From: Wlodek Wencel Date: Thu, 16 Apr 2020 13:21:25 +0000 (+0200) Subject: [#1132] added unittest for dhcpinform X-Git-Tag: Kea-1.7.7~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9cfdd8bbf156b81310702149e3041c333faff36b;p=thirdparty%2Fkea.git [#1132] added unittest for dhcpinform --- diff --git a/src/bin/dhcp4/tests/inform_unittest.cc b/src/bin/dhcp4/tests/inform_unittest.cc index 1be526b4c3..591d419246 100644 --- a/src/bin/dhcp4/tests/inform_unittest.cc +++ b/src/bin/dhcp4/tests/inform_unittest.cc @@ -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(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 diff --git a/src/bin/dhcp4/tests/shared_network_unittest.cc b/src/bin/dhcp4/tests/shared_network_unittest.cc index 427fa3b80a..47abaaf097 100644 --- a/src/bin/dhcp4/tests/shared_network_unittest.cc +++ b/src/bin/dhcp4/tests/shared_network_unittest.cc @@ -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");