]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3038] update lease4_offer UTs
authorPiotrek Zadroga <piotrek@isc.org>
Thu, 14 Sep 2023 14:54:39 +0000 (16:54 +0200)
committerPiotrek Zadroga <piotrek@isc.org>
Mon, 18 Sep 2023 17:19:45 +0000 (19:19 +0200)
src/bin/dhcp4/tests/hooks_unittest.cc

index c0556ed1c60bb40f33545d6ca6311a9d1e0fe273..dd8bc25404ed6ee5b6f65446164e40933cc2a5ac 100644 (file)
@@ -787,12 +787,6 @@ public:
             callback_lease4_ = leases4->at(0);
         }
 
-        Lease4CollectionPtr deleted_leases4;
-        callout_handle.getArgument("deleted_leases4", deleted_leases4);
-        if (deleted_leases4->size() > 0) {
-            callback_deleted_lease4_ = deleted_leases4->at(0);
-        }
-
         callout_handle.getArgument("offer_lifetime", callback_offer_lft_);
         callout_handle.getArgument("old_lease", callback_old_lease_);
 
@@ -956,6 +950,8 @@ public:
         callback_argument_names_.clear();
         callback_qry_options_copy_ = false;
         callback_resp_options_copy_ = false;
+        callback_offer_lft_ = 0;
+        callback_old_lease_.reset();
     }
 
     /// @brief Fetches the current value of the given statistic.
@@ -3488,8 +3484,8 @@ TEST_F(HooksDhcpv4SrvTest, leases4ParkedPacketLimit) {
 }
 
 // This test verifies that the lease4_offer hook point is triggered
-// for the DHCPDISCOVER and is NOT triggered for the DHCPREQUEST.
-TEST_F(HooksDhcpv4SrvTest, lease4OfferDiscoverRequest) {
+// for the DHCPDISCOVER.
+TEST_F(HooksDhcpv4SrvTest, lease4OfferDiscover) {
     IfaceMgrTestConfig test_config(true);
     IfaceMgr::instance().openSockets4();
 
@@ -3500,7 +3496,7 @@ TEST_F(HooksDhcpv4SrvTest, lease4OfferDiscoverRequest) {
     Dhcp4Client client(Dhcp4Client::SELECTING);
     client.setIfaceName("eth1");
     client.setIfaceIndex(ETH1_INDEX);
-    ASSERT_NO_THROW(client.doDORA(boost::shared_ptr<IOAddress>(new IOAddress("192.0.2.100"))));
+    ASSERT_NO_THROW(client.doDiscover());
 
     // Make sure that we received a response
     ASSERT_TRUE(client.getContext().response_);
@@ -3511,7 +3507,6 @@ TEST_F(HooksDhcpv4SrvTest, lease4OfferDiscoverRequest) {
     // Check if all expected parameters were really received
     vector<string> expected_argument_names;
     expected_argument_names.push_back("query4");
-    expected_argument_names.push_back("deleted_leases4");
     expected_argument_names.push_back("leases4");
     expected_argument_names.push_back("offer_lifetime");
     expected_argument_names.push_back("old_lease");
@@ -3519,23 +3514,29 @@ TEST_F(HooksDhcpv4SrvTest, lease4OfferDiscoverRequest) {
     sort(expected_argument_names.begin(), expected_argument_names.end());
     EXPECT_TRUE(callback_argument_names_ == expected_argument_names);
 
-    // No allocated lease expected yet.
-    EXPECT_FALSE(callback_lease4_);
-
-    // Deleted lease must not be present.
-    EXPECT_FALSE(callback_deleted_lease4_);
+    // Newly allocated lease should be returned.
+    ASSERT_TRUE(callback_lease4_);
+    EXPECT_EQ("192.0.2.100", callback_lease4_->addr_.toText());
 
     // Pkt passed to a callout must be configured to copy retrieved options.
     EXPECT_TRUE(callback_qry_options_copy_);
 
     // Check if the callout handle state was reset after the callout.
     checkCalloutHandleReset(client.getContext().query_);
+}
 
-    resetCalloutBuffers();
+// This test verifies that the lease4_offer hook point is not triggered
+// for the DHCPINFORM.
+TEST_F(HooksDhcpv4SrvTest, lease4OfferInform) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
 
-    // Renew the lease and make sure that the callout has NOT been executed.
-    client.setState(Dhcp4Client::RENEWING);
-    ASSERT_NO_THROW(client.doRequest());
+    ASSERT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
+        "lease4_offer", lease4_offer_callout));
+
+    Dhcp4Client client(Dhcp4Client::SELECTING);
+    client.useRelay();
+    ASSERT_NO_THROW(client.doInform());
 
     // Make sure that we received a response
     ASSERT_TRUE(client.getContext().response_);
@@ -3548,8 +3549,8 @@ TEST_F(HooksDhcpv4SrvTest, lease4OfferDiscoverRequest) {
 }
 
 // This test verifies that the lease4_offer hook point is not triggered
-// for the DHCPINFORM.
-TEST_F(HooksDhcpv4SrvTest, lease4OfferInform) {
+// for the DHCPDECLINE.
+TEST_F(HooksDhcpv4SrvTest, lease4OfferDecline) {
     IfaceMgrTestConfig test_config(true);
     IfaceMgr::instance().openSockets4();
 
@@ -3558,11 +3559,15 @@ TEST_F(HooksDhcpv4SrvTest, lease4OfferInform) {
 
     Dhcp4Client client(Dhcp4Client::SELECTING);
     client.useRelay();
-    ASSERT_NO_THROW(client.doInform());
+    ASSERT_NO_THROW(client.doDORA(boost::shared_ptr<IOAddress>(new IOAddress("192.0.2.100"))));
 
     // Make sure that we received a response
     ASSERT_TRUE(client.getContext().response_);
 
+    resetCalloutBuffers();
+
+    ASSERT_NO_THROW(client.doDecline());
+
     // Make sure that the callout wasn't called.
     EXPECT_TRUE(callback_name_.empty());
 
@@ -3571,8 +3576,8 @@ TEST_F(HooksDhcpv4SrvTest, lease4OfferInform) {
 }
 
 // This test verifies that the lease4_offer hook point is not triggered
-// for the DHCPDECLINE.
-TEST_F(HooksDhcpv4SrvTest, lease4OfferDecline) {
+// for the DHCPREQUEST.
+TEST_F(HooksDhcpv4SrvTest, lease4OfferRequest) {
     IfaceMgrTestConfig test_config(true);
     IfaceMgr::instance().openSockets4();
 
@@ -3580,7 +3585,8 @@ TEST_F(HooksDhcpv4SrvTest, lease4OfferDecline) {
         "lease4_offer", lease4_offer_callout));
 
     Dhcp4Client client(Dhcp4Client::SELECTING);
-    client.useRelay();
+    client.setIfaceName("eth1");
+    client.setIfaceIndex(ETH1_INDEX);
     ASSERT_NO_THROW(client.doDORA(boost::shared_ptr<IOAddress>(new IOAddress("192.0.2.100"))));
 
     // Make sure that we received a response
@@ -3588,9 +3594,10 @@ TEST_F(HooksDhcpv4SrvTest, lease4OfferDecline) {
 
     resetCalloutBuffers();
 
-    ASSERT_NO_THROW(client.doDecline());
+    client.setState(Dhcp4Client::RENEWING);
+    ASSERT_NO_THROW(client.doRequest());
 
-    // Make sure that the callout wasn't called.
+    // Make sure that the callout wasn't called on DHCPREQUEST.
     EXPECT_TRUE(callback_name_.empty());
 
     // Check if the callout handle state was reset after the callout.