]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5364] Verify that the subnet id is not messed up in the database.
authorMarcin Siodelski <marcin@isc.org>
Tue, 3 Oct 2017 10:26:11 +0000 (12:26 +0200)
committerMarcin Siodelski <marcin@isc.org>
Tue, 3 Oct 2017 10:26:11 +0000 (12:26 +0200)
src/bin/dhcp4/tests/shared_network_unittest.cc

index e657cbfaa4fc3482ddbcdc160c46ac0111c6ff41..00b3784cbf7747cd403750f9df72d2ea503f7609 100644 (file)
@@ -12,6 +12,8 @@
 #include <dhcp/option.h>
 #include <dhcp/option_int.h>
 #include <dhcp/option_string.h>
+#include <dhcpsrv/cfgmgr.h>
+#include <dhcpsrv/cfg_subnets4.h>
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcp4/tests/dhcp4_client.h>
 #include <dhcp4/tests/dhcp4_test_utils.h>
@@ -850,6 +852,23 @@ public:
         StatsMgr::instance().removeAll();
     }
 
+    /// @brief Returns subnet having specified address in range.
+    ///
+    /// @param address Address for which subnet is being searched.
+    /// @return Pointer to the subnet having an address in range or null pointer
+    /// if no subnet found.
+    Subnet4Ptr getConfiguredSubnet(const IOAddress& address) {
+        CfgSubnets4Ptr cfg = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4();
+        const Subnet4Collection* subnets = cfg->getAll();
+        for (auto subnet_it = subnets->cbegin(); subnet_it != subnets->cend();
+             ++subnet_it) {
+            if ((*subnet_it)->inRange(address)) {
+                return (*subnet_it);
+            }
+        }
+        return (Subnet4Ptr());
+    }
+
     /// @brief Perform DORA exchange and checks the result
     ///
     /// This convenience method conducts DORA exchange with client
@@ -880,6 +899,10 @@ public:
             EXPECT_EQ(exp_addr, resp->getYiaddr().toText());
             Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(IOAddress(resp->getYiaddr()));
             ASSERT_TRUE(lease);
+            // Make sure that the subnet id in the lease database is not messed up.
+            Subnet4Ptr subnet = getConfiguredSubnet(resp->getYiaddr());
+            ASSERT_TRUE(subnet);
+            ASSERT_EQ(subnet->getID(), lease->subnet_id_);
 
         } else {
             EXPECT_EQ("0.0.0.0", resp->getYiaddr().toText());
@@ -941,6 +964,10 @@ public:
             EXPECT_EQ(exp_addr, resp->getYiaddr().toText());
             Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(IOAddress(resp->getYiaddr()));
             ASSERT_TRUE(lease);
+            // Make sure that the subnet id in the lease database is not messed up.
+            Subnet4Ptr subnet = getConfiguredSubnet(resp->getYiaddr());
+            ASSERT_TRUE(subnet);
+            ASSERT_EQ(subnet->getID(), lease->subnet_id_);
         }
     }