]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[4206_0.9.1] Unit-tests written.
authorTomek Mrugalski <tomasz@isc.org>
Tue, 8 Dec 2015 16:15:01 +0000 (17:15 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Tue, 8 Dec 2015 16:15:01 +0000 (17:15 +0100)
src/bin/dhcp4/tests/dhcp4_client.cc
src/bin/dhcp4/tests/dhcp4_client.h
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc

index a3c3436d743d48ccea321d091c283f7a82ca3aa6..e2007e0930904de3ef2b84248a788df6c890ffdf 100644 (file)
@@ -196,6 +196,17 @@ Dhcp4Client::createMsg(const uint8_t msg_type) {
     return (msg);
 }
 
+ void
+Dhcp4Client::appendExtraOptions() {
+    // 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) {
+            context_.query_->addOption(opt->second);
+        }
+    }
+}
+
 void
 Dhcp4Client::doDiscover(const boost::shared_ptr<IOAddress>& requested_addr) {
     context_.query_ = createMsg(DHCPDISCOVER);
@@ -212,6 +223,9 @@ Dhcp4Client::doDiscover(const boost::shared_ptr<IOAddress>& requested_addr) {
     if (ciaddr_.isSpecified()) {
         context_.query_->setCiaddr(ciaddr_.get());
     }
+
+    appendExtraOptions();
+
     // Send the message to the server.
     sendMsg(context_.query_);
     // Expect response.
@@ -422,6 +436,11 @@ Dhcp4Client::setHWAddress(const std::string& hwaddr_str) {
     }
 }
 
+void
+Dhcp4Client::addExtraOption(const OptionPtr& opt) {
+    extra_options_.insert(std::make_pair(opt->getType(), opt));
+}
+
 } // end of namespace isc::dhcp::test
 } // end of namespace isc::dhcp
 } // end of namespace isc
index 38b9025d802ed3a0f4105a0d840bdf1c4065ffa2..f2a2d038cdc04d3d985eb0f6f73f3c3197961916 100644 (file)
@@ -342,7 +342,15 @@ public:
     /// in the client's messages.
     isc::util::OptionalValue<asiolink::IOAddress> ciaddr_;
 
+    /// @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 Appends extra options, previously added with addExtraOption()
+    ///
+    /// Copies options from extra_options_ into outgoing message.
+    void appendExtraOptions();
 
     /// @brief Creates and adds Requested IP Address option to the client's
     /// query.
@@ -448,6 +456,8 @@ private:
     /// @brief Enable relaying messages to the server.
     bool use_relay_;
 
+    /// @brief Extra options the client will send.
+    OptionCollection extra_options_;
 };
 
 } // end of namespace isc::dhcp::test
index 97849fc7ea0876c14c73f9a45baaa7b464a2cc92..9cf0d3cba9e97af9f4b3e3c6f65e6b1a4926e7c5 100644 (file)
@@ -18,6 +18,7 @@
 #include <asiolink/io_address.h>
 #include <config/ccsession.h>
 #include <dhcp4/tests/dhcp4_test_utils.h>
+#include <dhcp4/tests/dhcp4_client.h>
 #include <dhcp/tests/pkt_captures.h>
 #include <dhcp/dhcp4.h>
 #include <dhcp/iface_mgr.h>
@@ -61,6 +62,26 @@ using namespace isc::test;
 
 namespace {
 
+const char* CONFIGS[] = {
+    // Configuration 0:
+    // - 1 subnet: 10.254.226.0/25
+    // - used for recorded traffic (see PktCaptures::captureRelayedDiscover)
+    "{ \"interfaces-config\": {"
+        "    \"interfaces\": [ \"*\" ]"
+        "},"
+        "\"rebind-timer\": 2000, "
+        "\"renew-timer\": 1000, "
+        "\"subnet4\": [ { "
+        "    \"pools\": [ { \"pool\": \"10.254.226.0/25\" } ],"
+        "    \"subnet\": \"10.254.226.0/24\", "
+        "    \"rebind-timer\": 2000, "
+        "    \"renew-timer\": 1000, "
+        "    \"valid-lifetime\": 4000,"
+        "    \"interface\": \"eth0\" "
+        " } ],"
+        "\"valid-lifetime\": 4000 }"
+};
+
 // This test verifies that the destination address of the response
 // message is set to giaddr, when giaddr is set to non-zero address
 // in the received message.
@@ -3536,4 +3557,26 @@ TEST_F(Dhcpv4SrvTest, acceptMessageType) {
     }
 }
 
+// This test verifies that the server is able to handle an empty client-id
+// in incoming client message.
+TEST_F(Dhcpv4SrvTest, emptyClientId) {
+    Dhcp4Client client;
+
+    EXPECT_NO_THROW(configure(CONFIGS[0], *client.getServer()));
+
+    // Tell the client to not send client-id on its own.
+    client.includeClientId("");
+
+    // Instead, tell him to send this extra option, which happens to be
+    // an empty client-id.
+    OptionPtr empty_client_id(new Option(Option::V4, DHO_DHCP_CLIENT_IDENTIFIER));
+    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.doDORA());
+}
+
 }; // end of anonymous namespace