]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2795] adding UTs for new command
authorPiotrek Zadroga <piotrek@isc.org>
Tue, 20 Jun 2023 12:25:24 +0000 (14:25 +0200)
committerPiotrek Zadroga <piotrek@isc.org>
Mon, 26 Jun 2023 15:30:59 +0000 (15:30 +0000)
src/lib/dhcpsrv/tests/host_mgr_unittest.cc
src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc
src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc
src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h

index a57e357f0e806cdce32ad1f6d78b7c1961c966cd..2ade444c06591f4cc13a74061d844bc45d9ba604 100644 (file)
@@ -56,6 +56,13 @@ TEST_F(HostMgrTest, getAll6BySubnetIP) {
     testGetAll6BySubnetIP(*getCfgHosts(), *getCfgHosts());
 }
 
+// This test verifies that HostMgr returns all reservations for the
+// IPv6 reserved address. The reservations are specified in the
+// server's configuration.
+TEST_F(HostMgrTest, getAll6ByIP) {
+    testGetAll6ByIP(*getCfgHosts(), *getCfgHosts());
+}
+
 // This test verifies that HostMgr returns all reservations for the
 // specified DHCPv6 subnet. The reservations are defined in the server's
 // configuration.
index eb3b9d975c257b299fe4416b060a026e1be13c5b..7ab3bc3791ecc4676f5b47653d3d25f25c797869 100644 (file)
@@ -1577,6 +1577,12 @@ TEST_F(MySQLHostMgrTest, getAll6BySubnetIP) {
     testGetAll6BySubnetIP(*getCfgHosts(), *getCfgHosts());
 }
 
+// This test verifies that HostMgr returns all reservations for the
+// IPv6 reserved address.
+TEST_F(MySQLHostMgrTest, getAll6ByIP) {
+    testGetAll6ByIP(*getCfgHosts(), *getCfgHosts());
+}
+
 // This test verifies that reservations for a particular hostname can be
 // retrieved from the configuration file and a database simultaneously.
 TEST_F(MySQLHostMgrTest, getAllbyHostname) {
index 681a9c648f6488d0cecb2b36417adc8c37777971..2d30b239ad7b58c4d2c60c3934cd48147b770fd0 100644 (file)
@@ -1545,6 +1545,12 @@ TEST_F(PgSQLHostMgrTest, getAll6BySubnetIP) {
     testGetAll6BySubnetIP(*getCfgHosts(), *getCfgHosts());
 }
 
+// This test verifies that HostMgr returns all reservations for the specified
+// IPv6 reserved address.
+TEST_F(PgSQLHostMgrTest, getAll6ByIP) {
+    testGetAll6ByIP(*getCfgHosts(), *getCfgHosts());
+}
+
 // This test verifies that reservations for a particular hostname can be
 // retrieved from the configuration file and a database simultaneously.
 TEST_F(PgSQLHostMgrTest, getAllbyHostname) {
index 0be8217d5c0c61cc88ae312b656d5a007ebade6a..032118f9ec78db83c484ef943f35185d1f754b02 100644 (file)
@@ -4393,6 +4393,79 @@ HostMgrTest::testGetAll6BySubnetIP(BaseHostDataSource& data_source1,
     EXPECT_EQ(0, hosts.size());
 }
 
+void
+HostMgrTest::testGetAll6ByIP(BaseHostDataSource& data_source1,
+                             BaseHostDataSource& data_source2) {
+    // Set the mode of operation with multiple reservations for the same
+    // IP address.
+    ASSERT_TRUE(HostMgr::instance().setIPReservationsUnique(false));
+    CfgMgr::instance().getStagingCfg()->getCfgHosts()->setIPReservationsUnique(false);
+
+    // Initially, no reservations should be present.
+    ConstHostCollection hosts = HostMgr::instance().getAll6(SubnetID(1),
+                                                            IOAddress("2001:db8:1::5"));
+    ASSERT_TRUE(hosts.empty());
+
+    // Add two reservations for the same subnet.
+    addHost6(data_source1, duids_[0], SubnetID(1), IOAddress("2001:db8:1::5"));
+    addHost6(data_source2, duids_[1], SubnetID(1), IOAddress("2001:db8:1::5"));
+
+    CfgMgr::instance().commit();
+
+    // If there non-matching subnet is specified, nothing should be returned.
+    hosts = HostMgr::instance().getAll6(SubnetID(100), IOAddress("2001:db8:1::5"));
+    ASSERT_TRUE(hosts.empty());
+
+    // For given IP there should be two reservations.
+    hosts = HostMgr::instance().getAll6(IOAddress("2001:db8:1::5"));
+    ASSERT_EQ(2, hosts.size());
+
+    // Make sure that subnet is correct.
+    EXPECT_EQ(1, hosts[0]->getIPv6SubnetID());
+    EXPECT_EQ(1, hosts[1]->getIPv6SubnetID());
+
+    // 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(
+        IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::5"))));
+
+    // Make sure that the operation target is supported.
+    bool is_first_source_primary = isPrimaryDataSource(data_source1);
+    bool is_second_source_primary = isPrimaryDataSource(data_source2);
+    size_t hosts_in_primary_source = is_first_source_primary + is_second_source_primary;
+
+    // Select hosts only from the primary source.
+    hosts = HostMgr::instance().getAll6(IOAddress("2001:db8:1::5"), HostMgrOperationTarget::PRIMARY_SOURCE);
+    EXPECT_EQ(hosts_in_primary_source, hosts.size());
+    if (is_first_source_primary) {
+        EXPECT_TRUE(hosts[0]->hasReservation(
+            IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::5"))));
+    }
+    if (is_second_source_primary) {
+        EXPECT_TRUE(hosts[hosts_in_primary_source - 1]->hasReservation(
+            IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::5"))));
+    }
+
+    // Select hosts only from the alternate sources.
+    hosts = HostMgr::instance().getAll6(IOAddress("2001:db8:1::5"), HostMgrOperationTarget::ALTERNATE_SOURCES);
+    EXPECT_EQ(2 - hosts_in_primary_source, hosts.size());
+    if (!is_first_source_primary) {
+        EXPECT_TRUE(hosts[0]->hasReservation(
+            IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::5"))));
+    }
+    if (!is_second_source_primary) {
+        EXPECT_TRUE(hosts[2 - hosts_in_primary_source - 1]->hasReservation(
+            IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::5"))));
+    }
+
+    // Select hosts for an unspecified source.
+    hosts = HostMgr::instance().getAll4(IOAddress("2001:db8:1::5"), HostMgrOperationTarget::UNSPECIFIED_SOURCE);
+    EXPECT_EQ(0, hosts.size());
+}
+
 void
 HostMgrTest::testAdd(BaseHostDataSource& data_source1,
                      BaseHostDataSource& data_source2) {
index d5f1cf5352b999c62fa3ddcd369e339767394da3..786b88e4a8283a09ec79390d3af15e30e4e86073 100644 (file)
@@ -935,6 +935,19 @@ protected:
     void testGetAll6BySubnetIP(BaseHostDataSource& data_source1,
                                BaseHostDataSource& data_source2);
 
+    /// @brief This test verifies that HostMgr returns all reservations for the
+    /// specified IPv6 address.
+    ///
+    /// If reservations are added to different host data sources, it is expected
+    /// that the @c HostMgr will retrieve reservations from both of them.
+    ///
+    /// @param data_source1 Host data source to which first reservation is
+    /// inserted.
+    /// @param data_source2 Host data source to which second reservation is
+    /// inserted.
+    void testGetAll6ByIP(BaseHostDataSource& data_source1,
+                         BaseHostDataSource& data_source2);
+
     /// @brief This test verifies that HostMgr adds the reservations to any
     /// data source.
     ///