Parcourir la source

[3352] Augment DHPC6 FQDN tests to properly check handling of FQDN flags

Unit tests did not detect that Dhcpv6Srv::createNameChangeRequests attempts
to make NCRs when the response FQDN flags indicate that none should be created.
FqdnDhcpv6Srv::testFqdn has been expanded to invoke this method and check the
outcome.
Thomas Markwalder il y a 11 ans
Parent
commit
614d16ac5d
1 fichiers modifiés avec 47 ajouts et 12 suppressions
  1. 47 12
      src/bin/dhcp6/tests/fqdn_unittest.cc

+ 47 - 12
src/bin/dhcp6/tests/fqdn_unittest.cc

@@ -172,6 +172,7 @@ public:
             pkt->addOption(oro);
         }
 
+        OptionPtr tmp = pkt->getOption(D6O_CLIENTID);
         return (pkt);
     }
 
@@ -264,13 +265,16 @@ public:
     }
 
     /// @brief Verifies if the DHCPv6 server processes DHCPv6 Client FQDN option
-    /// as expected.
+    /// as expected and subsequent interpretation of this processing when
+    /// creating NCRs, if any should be created.
     ///
     /// This function simulates generation of the client's message holding FQDN.
     /// It then calls the server's @c Dhcpv6Srv::processClientFqdn option to
     /// generate server's response to the FQDN. This function returns the FQDN
     /// which should be appended to the server's response to the client.
-    /// This function verifies that the FQDN option returned is correct.
+    /// This function verifies that the FQDN option returned is correct
+    /// Optionally, this function then proceeds to call createNameChangeRequests
+    /// to verify if that method interprets the FQDN information properly.
     ///
     /// @param msg_type A type of the client's message.
     /// @param in_flags A value of flags field to be set for the FQDN carried
@@ -282,22 +286,34 @@ public:
     /// @param exp_flags A value of flags expected in the FQDN sent by a server.
     /// @param exp_domain_name A domain name expected in the FQDN sent by a
     /// server.
+    /// @param create_ncr_check if true, calls createNameChangeRequests method
+    /// and tests the outcome.
+    /// @param exp_fwd indicates whether or not a forward change is expected
+    /// @param exp_fwd indicates whether or not a reverse change is expected
     void testFqdn(const uint16_t msg_type,
                   const uint8_t in_flags,
                   const std::string& in_domain_name,
                   const Option6ClientFqdn::DomainNameType in_domain_type,
                   const uint8_t exp_flags,
-                  const std::string& exp_domain_name) {
+                  const std::string& exp_domain_name,
+                  const bool create_ncr_check,
+                  const bool exp_fwd = true, const bool exp_rev = true) {
 
         Pkt6Ptr question = generateMessage(msg_type,
                                            in_flags,
                                            in_domain_name,
                                            in_domain_type,
                                            true);
+
         ASSERT_TRUE(getClientFqdnOption(question));
 
-        Pkt6Ptr answer(new Pkt6(msg_type == DHCPV6_SOLICIT ? DHCPV6_ADVERTISE :
-                                DHCPV6_REPLY, question->getTransid()));
+        Pkt6Ptr answer = generateMessageWithIds(msg_type == DHCPV6_SOLICIT
+                                                ? DHCPV6_ADVERTISE :
+                                                DHCPV6_REPLY);
+
+        // Create three IAs, each having different address.
+        addIA(1234, IOAddress("2001:db8:1::1"), answer);
+
         ASSERT_NO_THROW(srv_->processClientFqdn(question, answer));
         Option6ClientFqdnPtr answ_fqdn = boost::dynamic_pointer_cast<
             Option6ClientFqdn>(answer->getOption(D6O_CLIENT_FQDN));
@@ -325,6 +341,25 @@ public:
             EXPECT_EQ(Option6ClientFqdn::FULL, answ_fqdn->getDomainNameType());
 
         }
+
+        if (create_ncr_check) {
+            // Call createNameChangeRequests
+            ASSERT_NO_THROW(srv_->createNameChangeRequests(answer));
+            if (exp_fwd || exp_rev) {
+                // Should have created 1 NCR.
+                NameChangeRequestPtr ncr;
+                ASSERT_EQ(1, d2_mgr_.getQueueSize());
+                ASSERT_NO_THROW(ncr = d2_mgr_.peekAt(0));
+                ASSERT_TRUE(ncr);
+                EXPECT_EQ(dhcp_ddns::CHG_ADD, ncr->getChangeType());
+                EXPECT_EQ(exp_fwd, ncr->isForwardChange());
+                EXPECT_EQ(exp_rev, ncr->isReverseChange());
+                ASSERT_NO_THROW(d2_mgr_.runReadyIO());
+            } else {
+                // Should not have created any NCRs.
+                EXPECT_EQ(0, d2_mgr_.getQueueSize());
+            }
+        }
     }
 
     /// @brief Tests that the client's message holding an FQDN is processed
@@ -468,7 +503,7 @@ TEST_F(FqdnDhcpv6SrvTest, serverAAAAUpdate) {
     testFqdn(DHCPV6_SOLICIT, Option6ClientFqdn::FLAG_S,
              "myhost.example.com",
              Option6ClientFqdn::FULL, Option6ClientFqdn::FLAG_S,
-             "myhost.example.com.");
+             "myhost.example.com.", true, true, true);
 }
 
 // Test server's response when client provides partial domain-name and requests
@@ -476,14 +511,14 @@ TEST_F(FqdnDhcpv6SrvTest, serverAAAAUpdate) {
 TEST_F(FqdnDhcpv6SrvTest, serverAAAAUpdatePartialName) {
     testFqdn(DHCPV6_SOLICIT, Option6ClientFqdn::FLAG_S, "myhost",
              Option6ClientFqdn::PARTIAL, Option6ClientFqdn::FLAG_S,
-             "myhost.example.com.");
+             "myhost.example.com.", true, true, true);
 }
 
 // Test server's response when client provides empty domain-name and requests
 // that server performs AAAA update.
 TEST_F(FqdnDhcpv6SrvTest, serverAAAAUpdateNoName) {
     testFqdn(DHCPV6_SOLICIT, Option6ClientFqdn::FLAG_S, "",
-             Option6ClientFqdn::PARTIAL, Option6ClientFqdn::FLAG_S, "");
+             Option6ClientFqdn::PARTIAL, Option6ClientFqdn::FLAG_S, "", false);
 }
 
 // Test server's response when client requests no DNS update.
@@ -491,7 +526,7 @@ TEST_F(FqdnDhcpv6SrvTest, noUpdate) {
     testFqdn(DHCPV6_SOLICIT, Option6ClientFqdn::FLAG_N,
              "myhost.example.com",
              Option6ClientFqdn::FULL, Option6ClientFqdn::FLAG_N,
-             "myhost.example.com.");
+             "myhost.example.com.", true, false, false);
 }
 
 // Test server's response when client requests no DNS update and
@@ -502,7 +537,7 @@ TEST_F(FqdnDhcpv6SrvTest, overrideNoUpdate) {
              "myhost.example.com",
              Option6ClientFqdn::FULL,
              (Option6ClientFqdn::FLAG_S | Option6ClientFqdn::FLAG_O),
-             "myhost.example.com.");
+             "myhost.example.com.", true, true, true);
 }
 
 // Test server's response when client requests that server delegates the AAAA
@@ -511,7 +546,7 @@ TEST_F(FqdnDhcpv6SrvTest, clientAAAAUpdate) {
     testFqdn(DHCPV6_SOLICIT, 0, "myhost.example.com.",
              Option6ClientFqdn::FULL,
              0,
-             "myhost.example.com.");
+             "myhost.example.com.", true, false, true);
 }
 
 // Test server's response when client requests that server delegates the AAAA
@@ -521,7 +556,7 @@ TEST_F(FqdnDhcpv6SrvTest, clientAAAAUpdateNotAllowed) {
     testFqdn(DHCPV6_SOLICIT, 0, "myhost.example.com.",
              Option6ClientFqdn::FULL,
              Option6ClientFqdn::FLAG_S | Option6ClientFqdn::FLAG_O,
-             "myhost.example.com.");
+             "myhost.example.com.", true, true, true);
 }
 
 // Test that exception is thrown if supplied NULL answer packet when