Browse Source

[3773] Added unit tests for confirm and rebind

Francis Dupont 9 years ago
parent
commit
eff4751912

+ 19 - 0
src/bin/dhcp6/tests/confirm_unittest.cc

@@ -18,6 +18,7 @@
 #include <dhcp/tests/iface_mgr_test_config.h>
 #include <dhcp6/json_config_parser.h>
 #include <dhcp6/tests/dhcp6_message_test.h>
+#include <dhcpsrv/utils.h>
 
 using namespace isc;
 using namespace isc::asiolink;
@@ -98,6 +99,24 @@ public:
 };
 
 
+// Test that clientID is mandatory and serverID forbidden for Confirm messages
+TEST_F(ConfirmTest, sanityCheck) {
+    NakedDhcpv6Srv srv(0);
+
+    // No clientID should fail
+    Pkt6Ptr confirm = Pkt6Ptr(new Pkt6(DHCPV6_CONFIRM, 1234));
+    EXPECT_THROW(srv.processConfirm(confirm), RFCViolation);
+
+    // A clientID should succeed
+    OptionPtr clientid = generateClientId();
+    confirm->addOption(clientid);
+    EXPECT_NO_THROW(srv.processConfirm(confirm));
+
+    // A serverID should fail
+    confirm->addOption(srv.getServerID());
+    EXPECT_THROW(srv.processConfirm(confirm), RFCViolation);
+}
+
 // Test that directly connected client's Confirm message is processed and Reply
 // message is sent back. In this test case, the client sends Confirm for two
 // addresses that belong to the same IAID and are sent within the same IA_NA

+ 4 - 0
src/bin/dhcp6/tests/dhcp6_test_utils.h

@@ -98,7 +98,11 @@ public:
     using Dhcpv6Srv::processSolicit;
     using Dhcpv6Srv::processRequest;
     using Dhcpv6Srv::processRenew;
+    using Dhcpv6Srv::processRebind;
+    using Dhcpv6Srv::processConfirm;
     using Dhcpv6Srv::processRelease;
+    using Dhcpv6Srv::processDecline;
+    using Dhcpv6Srv::processInfRequest;
     using Dhcpv6Srv::processClientFqdn;
     using Dhcpv6Srv::createNameChangeRequests;
     using Dhcpv6Srv::createRemovalNameChangeRequest;

+ 19 - 0
src/bin/dhcp6/tests/rebind_unittest.cc

@@ -18,6 +18,7 @@
 #include <dhcp/tests/iface_mgr_test_config.h>
 #include <dhcp6/json_config_parser.h>
 #include <dhcp6/tests/dhcp6_message_test.h>
+#include <dhcpsrv/utils.h>
 
 using namespace isc;
 using namespace isc::asiolink;
@@ -244,6 +245,24 @@ public:
     }
 };
 
+// Test that clientID is mandatory and serverID forbidden for Rebind messages
+TEST_F(RebindTest, sanityCheck) {
+    NakedDhcpv6Srv srv(0);
+
+    // No clientID should fail
+    Pkt6Ptr rebind = Pkt6Ptr(new Pkt6(DHCPV6_REBIND, 1234));
+    EXPECT_THROW(srv.processRebind(rebind), RFCViolation);
+
+    // A clientID should succeed
+    OptionPtr clientid = generateClientId();
+    rebind->addOption(clientid);
+    EXPECT_NO_THROW(srv.processRebind(rebind));
+
+    // A serverID should fail
+    rebind->addOption(srv.getServerID());
+    EXPECT_THROW(srv.processRebind(rebind), RFCViolation);
+}
+
 // Test that directly connected client's Rebind message is processed and Reply
 // message is sent back.
 TEST_F(RebindTest, directClient) {