From: Thomas Markwalder Date: Fri, 29 Sep 2017 15:15:27 +0000 (-0400) Subject: [5369] Update kea-dhcp4 unit tests to catch the problem X-Git-Tag: trac5361_base~4^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2f7a8c947c7800a79ebf904e6d99e29ec59616e;p=thirdparty%2Fkea.git [5369] Update kea-dhcp4 unit tests to catch the problem src/bin/dhcp4/tests/fqdn_unittest.cc TEST_F(NameDhcpv4SrvTest, processRequestFqdnEmptyDomainName) - Added renew cycle to verify DNS is not altered TEST_F(NameDhcpv4SrvTest, processRequestRenewFqdn) TEST_F(NameDhcpv4SrvTest, processRequestRenewHostname) New tests to verify clients which renew with a different FQDN/hostnames generte a CHG_REMOVE and a CHG_ADD --- diff --git a/src/bin/dhcp4/tests/fqdn_unittest.cc b/src/bin/dhcp4/tests/fqdn_unittest.cc index 6e4a24635c..9698963714 100644 --- a/src/bin/dhcp4/tests/fqdn_unittest.cc +++ b/src/bin/dhcp4/tests/fqdn_unittest.cc @@ -900,6 +900,17 @@ TEST_F(NameDhcpv4SrvTest, processRequestFqdnEmptyDomainName) { "", // empty DHCID forces that it is not checked time(NULL) + subnet_->getValid(), subnet_->getValid(), true); + + req = generatePktWithFqdn(DHCPREQUEST, Option4ClientFqdn::FLAG_S | + Option4ClientFqdn::FLAG_E, + "", Option4ClientFqdn::PARTIAL, true); + + ASSERT_NO_THROW(reply = srv_->processRequest(req)); + + checkResponse(reply, DHCPACK, 1234); + + // Verify that there are no NameChangeRequests generated. + ASSERT_EQ(0, d2_mgr_.getQueueSize()); } // Test that server generates client's hostname from the IP address assigned @@ -1071,6 +1082,90 @@ TEST_F(NameDhcpv4SrvTest, processTwoRequestsHostname) { time(NULL), subnet_->getValid(), true); } +// Test that client may send two requests, each carrying the same FQDN option. +// Server should renew existing lease for the second request without generating +// any NCRs. +TEST_F(NameDhcpv4SrvTest, processRequestRenewFqdn) { + IfaceMgrTestConfig test_config(true); + IfaceMgr::instance().openSockets4(); + + Pkt4Ptr req1 = generatePktWithFqdn(DHCPREQUEST, Option4ClientFqdn::FLAG_S | + Option4ClientFqdn::FLAG_E, + "myhost.example.com.", + Option4ClientFqdn::FULL, true); + + Pkt4Ptr reply; + ASSERT_NO_THROW(reply = srv_->processRequest(req1)); + + checkResponse(reply, DHCPACK, 1234); + + // Verify that there is one NameChangeRequest generated. + ASSERT_EQ(1, d2_mgr_.getQueueSize()); + verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true, + reply->getYiaddr().toText(), "myhost.example.com.", + "00010132E91AA355CFBB753C0F0497A5A940436" + "965B68B6D438D98E680BF10B09F3BCF", + time(NULL), subnet_->getValid(), true); + + // Create another Request message but with a different FQDN. Server + // should generate two NameChangeRequests: one to remove existing entry, + // another one to add new entry with updated domain-name. + Pkt4Ptr req2 = generatePktWithFqdn(DHCPREQUEST, Option4ClientFqdn::FLAG_S | + Option4ClientFqdn::FLAG_E, + "myhost.example.com.", + Option4ClientFqdn::FULL, true); + + ASSERT_NO_THROW(reply = srv_->processRequest(req2)); + + checkResponse(reply, DHCPACK, 1234); + + // There should be no NameChangeRequests. + ASSERT_EQ(0, d2_mgr_.getQueueSize()); +} + +// Test that client may send two requests, each carrying the same hostname +// option. Server should renew existing lease for the second request without +// generating any NCRs. +TEST_F(NameDhcpv4SrvTest, processRequestRenewHostname) { + IfaceMgrTestConfig test_config(true); + IfaceMgr::instance().openSockets4(); + + Pkt4Ptr req1 = generatePktWithHostname(DHCPREQUEST, "myhost.example.com."); + + // Set interface for the incoming packet. The server requires it to + // generate client id. + req1->setIface("eth1"); + + Pkt4Ptr reply; + ASSERT_NO_THROW(reply = srv_->processRequest(req1)); + + checkResponse(reply, DHCPACK, 1234); + + // Verify that there is one NameChangeRequest generated. + ASSERT_EQ(1, d2_mgr_.getQueueSize()); + verifyNameChangeRequest(isc::dhcp_ddns::CHG_ADD, true, true, + reply->getYiaddr().toText(), "myhost.example.com.", + "00010132E91AA355CFBB753C0F0497A5A940436" + "965B68B6D438D98E680BF10B09F3BCF", + time(NULL), subnet_->getValid(), true); + + // Create another Request message but with a different Hostname. Server + // should generate two NameChangeRequests: one to remove existing entry, + // another one to add new entry with updated domain-name. + Pkt4Ptr req2 = generatePktWithHostname(DHCPREQUEST, "myhost.example.com."); + + // Set interface for the incoming packet. The server requires it to + // generate client id. + req2->setIface("eth1"); + + ASSERT_NO_THROW(reply = srv_->processRequest(req2)); + + checkResponse(reply, DHCPACK, 1234); + + // There should be no NameChangeRequests. + ASSERT_EQ(0, d2_mgr_.getQueueSize()); +} + // Test that when a release message is sent for a previously acquired lease, // DDNS updates are enabled that the server generates a NameChangeRequest // to remove entries corresponding to the released lease.