]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1428] Improve non-unique reservations tests
authorMarcin Siodelski <marcin@isc.org>
Fri, 2 Oct 2020 16:57:00 +0000 (18:57 +0200)
committerMarcin Siodelski <marcin@isc.org>
Mon, 5 Oct 2020 13:14:58 +0000 (13:14 +0000)
The tests now verify that returned hosts are different. Also added a test
for prefixes. As a result of review.

src/lib/dhcpsrv/tests/cfg_hosts_unittest.cc
src/lib/dhcpsrv/tests/host_mgr_unittest.cc

index 5baf7dad2656b3f41e1641af4cf89bf40e3b6031..c1141d95191f21d70a24c68ebc9662e5911f0cf1 100644 (file)
@@ -953,9 +953,15 @@ TEST_F(CfgHostsTest, allow4AlreadyReserved) {
     // Adding this should work because the HW address is different.
     ASSERT_NO_THROW(cfg.add(host2));
 
+    // Get both hosts.
     ConstHostCollection returned;
     ASSERT_NO_THROW(returned = cfg.getAll4(host1->getIPv4SubnetID(), IOAddress("192.0.2.1")));
     EXPECT_EQ(2, returned.size());
+
+    // Make sure the address is the same but the identifiers are different.
+    EXPECT_NE(returned[0]->getIdentifierAsText(), returned[1]->getIdentifierAsText());
+    EXPECT_EQ(returned[0]->getIPv4Reservation().toText(),
+              returned[1]->getIPv4Reservation().toText());
 }
 
 // Checks that it's not possible for two hosts to have the same address
@@ -986,7 +992,7 @@ TEST_F(CfgHostsTest, add6Invalid2Hosts) {
 
 // Test that it is possible to allow inserting multiple reservations for
 // the same IPv6 address.
-TEST_F(CfgHostsTest, allow6AlreadyReserved) {
+TEST_F(CfgHostsTest, allowAddress6AlreadyReserved) {
     CfgHosts cfg;
     // Allow creating multiple reservations for the same IP address.
     ASSERT_TRUE(cfg.setIPReservationUnique(false));
@@ -1013,6 +1019,57 @@ TEST_F(CfgHostsTest, allow6AlreadyReserved) {
     ConstHostCollection returned;
     ASSERT_NO_THROW(returned = cfg.getAll6(host1->getIPv6SubnetID(), IOAddress("2001:db8::1")));
     EXPECT_EQ(2, returned.size());
+
+    // Make sure the address is the same but the identifiers are different.
+    EXPECT_NE(returned[0]->getIdentifierAsText(), returned[1]->getIdentifierAsText());
+
+    auto range0 = returned[0]->getIPv6Reservations(IPv6Resrv::TYPE_NA);
+    EXPECT_EQ(1, std::distance(range0.first, range0.second));
+    auto range1 = returned[1]->getIPv6Reservations(IPv6Resrv::TYPE_NA);
+    EXPECT_EQ(1, std::distance(range1.first, range1.second));
+    EXPECT_EQ(range0.first->second.getPrefix().toText(),
+              range1.first->second.getPrefix().toText());
+}
+
+// Test that it is possible to allow inserting multiple reservations for
+// the same IPv6 delegated prefix.
+TEST_F(CfgHostsTest, allowPrefix6AlreadyReserved) {
+    CfgHosts cfg;
+    // Allow creating multiple reservations for the same IP address.
+    ASSERT_TRUE(cfg.setIPReservationUnique(false));
+
+    // First host has a reservation for address 3000::/64.
+    HostPtr host1 = HostPtr(new Host(duids_[0]->toText(), "duid",
+                                     SUBNET_ID_UNUSED, SubnetID(1),
+                                     IOAddress("0.0.0.0")));
+    host1->addReservation(IPv6Resrv(IPv6Resrv::TYPE_PD,
+                                    IOAddress("3000::"), 64));
+    // Adding this should work.
+    EXPECT_NO_THROW(cfg.add(host1));
+
+    // The second host has a reservation for the same address.
+    HostPtr host2 = HostPtr(new Host(duids_[1]->toText(), "duid",
+                                     SUBNET_ID_UNUSED, SubnetID(1),
+                                     IOAddress("0.0.0.0")));
+    host2->addReservation(IPv6Resrv(IPv6Resrv::TYPE_PD,
+                                    IOAddress("3000::"), 64));
+
+    // Adding this should work because the DUID is different.
+    ASSERT_NO_THROW(cfg.add(host2));
+
+    ConstHostCollection returned;
+    ASSERT_NO_THROW(returned = cfg.getAll6(host1->getIPv6SubnetID(), IOAddress("3000::")));
+    EXPECT_EQ(2, returned.size());
+
+    // Make sure the address is the same but the identifiers are different.
+    EXPECT_NE(returned[0]->getIdentifierAsText(), returned[1]->getIdentifierAsText());
+
+    auto range0 = returned[0]->getIPv6Reservations(IPv6Resrv::TYPE_PD);
+    EXPECT_EQ(1, std::distance(range0.first, range0.second));
+    auto range1 = returned[1]->getIPv6Reservations(IPv6Resrv::TYPE_PD);
+    EXPECT_EQ(1, std::distance(range1.first, range1.second));
+    EXPECT_EQ(range0.first->second.getPrefix().toText(),
+              range1.first->second.getPrefix().toText());
 }
 
 // Check that no error is reported when adding a host with subnet
index 5facee2ace1f6ba22294d35b35139ab17d34f4c3..214f446881f9afd3a76596003e38a85ad2897c68 100644 (file)
@@ -1189,7 +1189,9 @@ HostMgrTest::testGetAll4BySubnetIP(BaseHostDataSource& data_source1,
     EXPECT_EQ(1, hosts[0]->getIPv4SubnetID());
     EXPECT_EQ(1, hosts[1]->getIPv4SubnetID());
 
-    // Make sure that two hosts were returned.
+    // Make sure that two hosts were returned with different identifiers
+    // but the same address.
+    EXPECT_NE(hosts[0]->getIdentifierAsText(), hosts[1]->getIdentifierAsText());
     EXPECT_EQ("192.0.2.5", hosts[0]->getIPv4Reservation().toText());
     EXPECT_EQ("192.0.2.5", hosts[1]->getIPv4Reservation().toText());
 }
@@ -1225,7 +1227,9 @@ HostMgrTest::testGetAll6BySubnetIP(BaseHostDataSource& data_source1,
     EXPECT_EQ(1, hosts[0]->getIPv6SubnetID());
     EXPECT_EQ(1, hosts[1]->getIPv6SubnetID());
 
-    // Make sure that two different hosts were returned.
+    // Make sure that two hosts were returned with different identifiers
+    // but the same address.
+    EXPECT_NE(hosts[0]->getIdentifierAsText(), hosts[1]->getIdentifierAsText());
     EXPECT_TRUE(hosts[0]->hasReservation(
                 IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::5"))));
     EXPECT_TRUE(hosts[1]->hasReservation(