]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[4206_0.9.1] Unit-test for empty client-id added.
authorTomek Mrugalski <tomasz@isc.org>
Tue, 8 Dec 2015 17:22:12 +0000 (18:22 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Tue, 8 Dec 2015 17:22:12 +0000 (18:22 +0100)
src/bin/dhcp6/tests/dhcp6_client.cc
src/bin/dhcp6/tests/dhcp6_client.h
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc

index 5c49efe62981ae41ea539670316b4c8723e73022..e72bd42cfb8122bf7d56774098a2c473e2276f76 100644 (file)
@@ -265,6 +265,14 @@ Dhcp6Client::createMsg(const uint8_t msg_type) {
         msg->addOption(oro);
     };
 
+    // If there are any custom options specified, add them all to the message.
+    if (!extra_options_.empty()) {
+        for (OptionCollection::iterator opt = extra_options_.begin();
+             opt != extra_options_.end(); ++opt) {
+            msg->addOption(opt->second);
+        }
+    }
+
     return (msg);
 }
 
@@ -509,6 +517,10 @@ Dhcp6Client::useHint(const uint32_t pref_lft, const uint32_t valid_lft,
                                            len, pref_lft, valid_lft));
 }
 
+void
+Dhcp6Client::addExtraOption(const OptionPtr& opt) {
+    extra_options_.insert(std::make_pair(opt->getType(), opt));
+}
 
 } // end of namespace isc::dhcp::test
 } // end of namespace isc::dhcp
index e8e8526f587ea589ecf8425430a597b724fcc97c..2e64b23186662838cb1ee6bd8f7f043547705bd8 100644 (file)
@@ -467,6 +467,10 @@ public:
         return (duid_);
     }
 
+    /// @brief Adds extra option (an option the client will always send)
+    ///
+    /// @param opt additional option to be sent
+    void addExtraOption(const OptionPtr& opt);
 private:
 
     /// @brief Applies the new leases for the client.
@@ -577,6 +581,9 @@ private:
     /// Content of this vector will be sent as ORO if use_oro_ is set
     /// to true. See @ref sendORO for details.
     std::vector<uint16_t> oro_;
+
+    /// @brief Extra options the client will send.
+    OptionCollection extra_options_;
 };
 
 } // end of namespace isc::dhcp::test
index 8548d9947da655075a656a6904b46a8f68387e82..eb24fb7d20658ac3e967462f08dc614b9eb86dd1 100644 (file)
@@ -2350,6 +2350,42 @@ TEST_F(Dhcpv6SrvTest, rsooOverride) {
     ASSERT_EQ(1, opt->getData().size());
 }
 
+// This test verifies that the server is able to handle an empty DUID (client-id)
+// in incoming client message.
+TEST_F(Dhcpv6SrvTest, emptyClientId) {
+    Dhcp6Client client;
+
+    // The following configuration enables RSOO options: 110 and 120.
+    // It also configures the server with option 120 which should
+    // "override" the option 120 sent in the RSOO by the relay.
+    string config =
+        "{"
+        "    \"preferred-lifetime\": 3000,"
+        "    \"rebind-timer\": 2000, "
+        "    \"renew-timer\": 1000, "
+        "    \"subnet6\": [ { "
+        "        \"pools\": [ { \"pool\": \"2001:db8::/64\" } ],"
+        "        \"subnet\": \"2001:db8::/48\" "
+        "     } ],"
+        "    \"valid-lifetime\": 4000"
+        "}";
+
+    EXPECT_NO_THROW(configure(config, *client.getServer()));
+
+    // Tell the client to not send client-id on its own.
+    client.useClientId(false);
+
+    // Instead, tell him to send this extra option, which happens to be
+    // an empty client-id.
+    OptionPtr empty_client_id(new Option(Option::V6, D6O_CLIENTID));
+    client.addExtraOption(empty_client_id);
+
+    // Let's check whether the server is able to process this packet without
+    // throwing any exceptions. We don't care whether the server sent any
+    // responses or not. The goal is to check that the server didn't throw
+    // any exceptions.
+    EXPECT_NO_THROW(client.doSARR());
+}
 
 /// @todo: Add more negative tests for processX(), e.g. extend sanityCheck() test
 /// to call processX() methods.