]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1132] added unittest for dhcpinform
authorWlodek Wencel <wlodek@isc.org>
Thu, 16 Apr 2020 13:21:25 +0000 (15:21 +0200)
committerFrancis Dupont <fdupont@isc.org>
Thu, 23 Apr 2020 13:36:12 +0000 (15:36 +0200)
src/bin/dhcp4/tests/inform_unittest.cc
src/bin/dhcp4/tests/shared_network_unittest.cc

index 1be526b4c3e18fed6c4e324390695f7e51ac729b..591d41924614e3539a1869b0792b9bda4a9dc162 100644 (file)
@@ -485,4 +485,60 @@ TEST_F(InformTest, statisticsInform) {
     EXPECT_EQ(5, pkt4_sent->getInteger().first);
 }
 
+// This test checks that the server receiving DHCPINFORM via relay, should
+// unicasts the DHCPACK to the client (ciaddr) but sending to source address
+// because of testing mode enabled with unaltred content.
+TEST_F(InformTest, relayedClientSendToSourceTestingMode) {
+    setenv("KEA_TEST_SEND_RESPONSES_TO_SOURCE", "ENABLED", 1);
+    Dhcp4Client client;
+    // Configure DHCP server.
+    configure(INFORM_CONFIGS[1], *client.getServer());
+    // Message is relayed.
+    EXPECT_TRUE(isc::dhcp::test::NakedDhcpv4Srv::getSendResponsesToSource());
+    client.useRelay();
+    // Request some configuration when DHCPINFORM is sent.
+    client.requestOptions(DHO_LOG_SERVERS, DHO_COOKIE_SERVERS);
+    // Preconfigure the client with the IP address.
+    client.createLease(IOAddress("192.0.2.56"), 600);
+    // Send DHCPINFORM message to the server.
+    ASSERT_NO_THROW(client.doInform());
+    // Make sure that the server responded.
+    ASSERT_TRUE(client.getContext().response_);
+    Pkt4Ptr resp = client.getContext().response_;
+    Pkt4Ptr query = client.getContext().query_;
+    // Make sure that the server has responded with DHCPACK.
+    ASSERT_EQ(DHCPACK, static_cast<int>(resp->getType()));
+    // Response should NOT have been unicast to the ciaddr.
+    EXPECT_NE(IOAddress("192.0.2.56"), resp->getLocalAddr());
+    // Destiantion address of response should be equal to source
+    // address of query.
+    EXPECT_EQ(query->getLocalAddr(), resp->getLocalAddr());
+    // The ciaddr should have been copied.
+    EXPECT_EQ(IOAddress("192.0.2.56"), resp->getCiaddr());
+    // Response is unicast to the client, so it must not be relayed.
+    EXPECT_FALSE(resp->isRelayed());
+    EXPECT_EQ(DHCP4_CLIENT_PORT, resp->getLocalPort());
+    EXPECT_EQ(DHCP4_SERVER_PORT, resp->getRemotePort());
+    // Make sure that the server id is present.
+    EXPECT_EQ("10.0.0.1", client.config_.serverid_.toText());
+    // Make sure that the Routers option has been received.
+    ASSERT_EQ(2, client.config_.routers_.size());
+    EXPECT_EQ("192.0.2.200", client.config_.routers_[0].toText());
+    EXPECT_EQ("192.0.2.201", client.config_.routers_[1].toText());
+    // Make sure that the DNS Servers option has been received.
+    ASSERT_EQ(2, client.config_.dns_servers_.size());
+    EXPECT_EQ("192.0.2.202", client.config_.dns_servers_[0].toText());
+    EXPECT_EQ("192.0.2.203", client.config_.dns_servers_[1].toText());
+    // Make sure that the Quotes Servers option has been received.
+    ASSERT_EQ(2, client.config_.quotes_servers_.size());
+    EXPECT_EQ("10.0.0.202", client.config_.quotes_servers_[0].toText());
+    EXPECT_EQ("10.0.0.203", client.config_.quotes_servers_[1].toText());
+    // Make sure that the Log Servers option has been received.
+    ASSERT_EQ(2, client.config_.log_servers_.size());
+    EXPECT_EQ("10.0.0.200", client.config_.log_servers_[0].toText());
+    EXPECT_EQ("10.0.0.201", client.config_.log_servers_[1].toText());
+
+    unsetenv("KEA_TEST_SEND_RESPONSES_TO_SOURCE");
+}
+
 } // end of anonymous namespace
index 427fa3b80affb5507aa34fad795fc36bf8218de9..47abaaf09719a9247b62a054e5da77d69689a04c 100644 (file)
@@ -2219,13 +2219,13 @@ TEST_F(Dhcpv4SharedNetworkTest, sharedNetworkSendToSourceTestingModeEnabled) {
     // Source address is set to unrelated to configuration.
 
     // Set env variable that put kea into testing mode
-    //setenv("KEA_TEST_SEND_RESPONSES_TO_SOURCE", "ENABLED", 1);
+    setenv("KEA_TEST_SEND_RESPONSES_TO_SOURCE", "ENABLED", 1);
     Dhcp4Client client1(Dhcp4Client::SELECTING);
     client1.useRelay(true, IOAddress("192.3.5.6"), IOAddress("1.1.1.2"));
     // Configure the server with one shared network and one subnet outside of the
     // shared network.
     configure(NETWORKS_CONFIG[1], *client1.getServer());
-    //EXPECT_TRUE(isc::dhcp::test::NakedDhcpv4Srv::getSendResponsesToSource());
+    EXPECT_TRUE(isc::dhcp::test::NakedDhcpv4Srv::getSendResponsesToSource());
     // Client #1 should be assigned an address from shared network.
     testAssigned([this, &client1] {
         doDORA(client1, "192.0.2.63", "192.0.2.63");