]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#82, !180] Missing unit-test added. 82-improve-kea-test-capabilities 421-create-config-backend-for-dhcpv6-base_base 421-create-config-backend-for-dhcpv6_base
authorTomek Mrugalski <tomasz@isc.org>
Fri, 18 Jan 2019 17:12:28 +0000 (18:12 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Fri, 18 Jan 2019 17:12:28 +0000 (18:12 +0100)
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc

index 412b48b9c4b0bf348cbcd3c93a279f8d063bbd5e..33078ec38c30d1d2a16e0a51d3649a2711edb72c 100644 (file)
@@ -1511,6 +1511,49 @@ TEST_F(Dhcpv4SrvTest, relayAgentInfoEcho) {
     EXPECT_TRUE(rai_response->equals(rai_query));
 }
 
+// Checks if client port can be overridden in packets being sent.
+TEST_F(Dhcpv4SrvTest, portsClientPort) {
+    IfaceMgrTestConfig test_config(true);
+    IfaceMgr::instance().openSockets4();
+
+    NakedDhcpv4Srv srv(0);
+
+    // By default te client port is supposed to be zero.
+    EXPECT_EQ(0, srv.client_port_);
+
+    // Use of the captured DHCPDISCOVER packet requires that
+    // subnet 10.254.226.0/24 is in use, because this packet
+    // contains the giaddr which belongs to this subnet and
+    // this giaddr is used to select the subnet
+    configure(CONFIGS[0]);
+    srv.client_port_ = 1234;
+
+    // Let's create a relayed DISCOVER. This particular relayed DISCOVER has
+    // added option 82 (relay agent info) with 3 suboptions. The server
+    // is supposed to echo it back in its response.
+    Pkt4Ptr dis;
+    ASSERT_NO_THROW(dis = PktCaptures::captureRelayedDiscover());
+
+    // Simulate that we have received that traffic
+    srv.fakeReceive(dis);
+
+    // Server will now process to run its normal loop, but instead of calling
+    // IfaceMgr::receive4(), it will read all packets from the list set by
+    // fakeReceive()
+    // In particular, it should call registered buffer4_receive callback.
+    srv.run();
+
+    // Check that the server did send a response
+    ASSERT_EQ(1, srv.fake_sent_.size());
+
+    // Make sure that we received a response
+    Pkt4Ptr offer = srv.fake_sent_.front();
+    ASSERT_TRUE(offer);
+
+    // Get Relay Agent Info from query...
+    EXPECT_EQ(srv.client_port_, offer->getRemotePort());
+}
+
 /// @todo move vendor options tests to a separate file.
 /// @todo Add more extensive vendor options tests, including multiple
 ///       vendor options