From: Marcin Siodelski Date: Tue, 3 Oct 2017 10:26:11 +0000 (+0200) Subject: [5364] Verify that the subnet id is not messed up in the database. X-Git-Tag: trac5297_base~6^2~7 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=396c232ae66281da5d896de38e38cf1dcb982302;p=thirdparty%2Fkea.git [5364] Verify that the subnet id is not messed up in the database. --- diff --git a/src/bin/dhcp4/tests/shared_network_unittest.cc b/src/bin/dhcp4/tests/shared_network_unittest.cc index e657cbfaa4..00b3784cbf 100644 --- a/src/bin/dhcp4/tests/shared_network_unittest.cc +++ b/src/bin/dhcp4/tests/shared_network_unittest.cc @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include #include @@ -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_); } }