]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#683,!390] Implemnted unit tests for lease6-bulk-apply.
authorMarcin Siodelski <marcin@isc.org>
Fri, 21 Jun 2019 15:36:57 +0000 (17:36 +0200)
committerMarcin Siodelski <marcin@isc.org>
Fri, 21 Jun 2019 20:45:34 +0000 (16:45 -0400)
src/hooks/dhcp/lease_cmds/tests/lease_cmds_unittest.cc

index 75e4fe4f7b3dcfc5b37f2df125eea41a41bb3fd1..4aabae3aca9eb76b84ed944ecb33d622b78d05b3 100644 (file)
@@ -3944,5 +3944,204 @@ TEST_F(LeaseCmdsTest, brokenUpdate) {
     testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
 }
 
+// This test verifies that it is possible to add two leases and delete
+// two leases as a result of the single lease6-bulk-apply command.
+TEST_F(LeaseCmdsTest, Lease6BulkApply) {
+
+    initLeaseMgr(true, true); // (true = v6, true = create leases)
+
+    // Now send the command.
+    string cmd =
+        "{\n"
+        "    \"command\": \"lease6-bulk-apply\",\n"
+        "    \"arguments\": {"
+        "        \"deleted-leases\": ["
+        "            {"
+        "                \"ip-address\": \"2001:db8:1::1\","
+        "                \"type\": \"IA_NA\""
+        "            },"
+        "            {"
+        "                \"ip-address\": \"2001:db8:1::2\","
+        "                \"type\": \"IA_NA\""
+        "            }"
+        "        ],"
+        "        \"leases\": ["
+        "            {"
+        "                \"subnet-id\": 66,\n"
+        "                \"ip-address\": \"2001:db8:1::123\",\n"
+        "                \"duid\": \"11:11:11:11:11:11\",\n"
+        "                \"iaid\": 1234\n"
+        "            },"
+        "            {"
+        "                \"subnet-id\": 99,\n"
+        "                \"ip-address\": \"2001:db8:2::123\",\n"
+        "                \"duid\": \"22:22:22:22:22:22\",\n"
+        "                \"iaid\": 1234\n"
+        "            }"
+        "        ]"
+        "    }"
+        "}";
+    string exp_rsp = "Bulk apply of 4 IPv6 leases completed.";
+
+    // The status expected is success.
+    testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
+
+    //  Check that the leases we inserted are stored.
+    EXPECT_TRUE(lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::123")));
+    EXPECT_TRUE(lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:2::123")));
+
+    // Check that the leases we deleted are gone,
+    EXPECT_FALSE(lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1")));
+    EXPECT_FALSE(lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::2")));
+}
+
+// This test verifies that it is possible to send new leases only
+// with the lease6-bulk-apply.
+TEST_F(LeaseCmdsTest, Lease6BulkApplyAddsOnly) {
+
+    initLeaseMgr(true, true); // (true = v6, true = create leases)
+
+    // Now send the command.
+    string cmd =
+        "{\n"
+        "    \"command\": \"lease6-bulk-apply\",\n"
+        "    \"arguments\": {"
+        "        \"leases\": ["
+        "            {"
+        "                \"subnet-id\": 66,\n"
+        "                \"ip-address\": \"2001:db8:1::123\",\n"
+        "                \"duid\": \"11:11:11:11:11:11\",\n"
+        "                \"iaid\": 1234\n"
+        "            },"
+        "            {"
+        "                \"subnet-id\": 99,\n"
+        "                \"ip-address\": \"2001:db8:2::123\",\n"
+        "                \"duid\": \"22:22:22:22:22:22\",\n"
+        "                \"iaid\": 1234\n"
+        "            }"
+        "        ]"
+        "    }"
+        "}";
+    string exp_rsp = "Bulk apply of 2 IPv6 leases completed.";
+
+    // The status expected is success.
+    testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
+
+    //  Check that the leases we inserted are stored.
+    EXPECT_TRUE(lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::123")));
+    EXPECT_TRUE(lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:2::123")));
+}
+
+// This test verifies that it is possible to only delete leases
+// with the lease6-bulk-apply.
+TEST_F(LeaseCmdsTest, Lease6BulkApplyDeletesOnly) {
+
+    initLeaseMgr(true, true); // (true = v6, true = create leases)
+
+    // Now send the command.
+    string cmd =
+        "{\n"
+        "    \"command\": \"lease6-bulk-apply\",\n"
+        "    \"arguments\": {"
+        "        \"deleted-leases\": ["
+        "            {"
+        "                \"ip-address\": \"2001:db8:1::1\","
+        "                \"type\": \"IA_NA\""
+        "            },"
+        "            {"
+        "                \"ip-address\": \"2001:db8:1::2\","
+        "                \"type\": \"IA_NA\""
+        "            }"
+        "        ]"
+        "    }"
+        "}";
+    string exp_rsp = "Bulk apply of 2 IPv6 leases completed.";
+
+    // The status expected is success.
+    testCommand(cmd, CONTROL_RESULT_SUCCESS, exp_rsp);
+
+    // Check that the leases we deleted are gone,
+    EXPECT_FALSE(lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1")));
+    EXPECT_FALSE(lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::2")));
+}
+
+// This test verifies that deleting non existing leases returns an
+// 'empty' result.
+TEST_F(LeaseCmdsTest, Lease6BulkApplyDeleteNonExiting) {
+
+    initLeaseMgr(true, true); // (true = v6, true = create leases)
+
+    // Now send the command.
+    string cmd =
+        "{\n"
+        "    \"command\": \"lease6-bulk-apply\",\n"
+        "    \"arguments\": {"
+        "        \"deleted-leases\": ["
+        "            {"
+        "                \"ip-address\": \"2001:db8:1::123\","
+        "                \"type\": \"IA_NA\""
+        "            },"
+        "            {"
+        "                \"ip-address\": \"2001:db8:1::234\","
+        "                \"type\": \"IA_NA\""
+        "            }"
+        "        ]"
+        "    }"
+        "}";
+    string exp_rsp = "Bulk apply of 0 IPv6 leases completed.";
+
+    // The status expected is success.
+    testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
+}
+
+// Check that changes for other leases are not applied if one of
+// the leases is malformed.
+TEST_F(LeaseCmdsTest, Lease6BulkApplyRollback) {
+
+    initLeaseMgr(true, true); // (true = v6, true = create leases)
+
+    // Now send the command.
+    string cmd =
+        "{\n"
+        "    \"command\": \"lease6-bulk-apply\",\n"
+        "    \"arguments\": {"
+        "        \"deleted-leases\": ["
+        "            {"
+        "                \"ip-address\": \"2001:db8:1::1\","
+        "                \"type\": \"IA_NA\""
+        "            },"
+        "            {"
+        "                \"ip-address\": \"2001:db8:1::2\","
+        "                \"type\": \"IA_NA\""
+        "            }"
+        "        ],"
+        "        \"leases\": ["
+        "            {"
+        "                \"subnet-id\": 66,\n"
+        "                \"ip-address\": \"2001:db8:1::123\","
+        "                \"duid\": \"11:11:11:11:11:11\","
+        "                \"iaid\": 1234\n"
+        "            },"
+        "            {"
+        "                \"subnet-id\": -1,"
+        "                \"ip-address\": \"2001:db8:2::123\","
+        "                \"duid\": \"22:22:22:22:22:22\","
+        "                \"iaid\": 1234"
+        "            }"
+        "        ]"
+        "    }"
+        "}";
+    string exp_rsp = "out of range value (-1) specified for parameter 'subnet-id' (<string>:5:57)";
+
+    // The status expected is success.
+    testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
+
+    EXPECT_FALSE(lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::123")));
+    EXPECT_FALSE(lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:2::123")));
+
+    EXPECT_TRUE(lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::1")));
+    EXPECT_TRUE(lmptr_->getLease6(Lease::TYPE_NA, IOAddress("2001:db8:1::2")));
+}
+
 
 } // end of anonymous namespace