From: Tomek Mrugalski Date: Fri, 15 Feb 2019 12:44:42 +0000 (+0100) Subject: [#464,!238] Truncated vivso option moved to vendor_opts_unittest.cc X-Git-Tag: 397-cb-implement-mysqlconfigbackenddhcpv6_base~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e912f7d6911c5a62b8c275f4625ce27a843c85c;p=thirdparty%2Fkea.git [#464,!238] Truncated vivso option moved to vendor_opts_unittest.cc --- diff --git a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc index f5dd3afd87..201fe3df37 100644 --- a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -3282,63 +3281,6 @@ TEST_F(Dhcpv4SrvTest, userContext) { EXPECT_EQ("{ \"value\": 42 }", pools[0]->getContext()->str()); } -// Verifies that an a client query with a truncated length in -// vendor option (125) will still be processed by the server. -TEST_F(Dhcpv4SrvTest, truncatedVIVSOOption) { - IfaceMgrTestConfig test_config(true); - IfaceMgr::instance().openSockets4(); - - NakedDhcpv4Srv srv(0); - - string config = "{ \"interfaces-config\": {" - " \"interfaces\": [ \"*\" ]" - "}," - "\"rebind-timer\": 2000, " - "\"renew-timer\": 1000, " - "\"subnet4\": [ { " - " \"pools\": [ { \"pool\": \"10.206.80.0/25\" } ]," - " \"subnet\": \"10.206.80.0/24\", " - " \"rebind-timer\": 2000, " - " \"renew-timer\": 1000, " - " \"valid-lifetime\": 4000," - " \"interface\": \"eth0\" " - " } ]," - "\"valid-lifetime\": 4000 }"; - - ConstElementPtr json; - ASSERT_NO_THROW(json = parseDHCP4(config)); - ConstElementPtr status; - - // Configure the server and make sure the config is accepted - EXPECT_NO_THROW(status = configureDhcp4Server(srv, json)); - ASSERT_TRUE(status); - comment_ = config::parseAnswer(rcode_, status); - ASSERT_EQ(0, rcode_); - - CfgMgr::instance().commit(); - - // Create a DISCOVER with a VIVSO option whose length is - // too short. - Pkt4Ptr dis; - ASSERT_NO_THROW(dis = PktCaptures::discoverWithTruncatedVIVSO()); - - // 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 an response and it was an offer - Pkt4Ptr offer = srv.fake_sent_.front(); - ASSERT_TRUE(offer); -} - /// @todo: Implement proper tests for MySQL lease/host database, /// see ticket #4214. diff --git a/src/bin/dhcp4/tests/vendor_opts_unittest.cc b/src/bin/dhcp4/tests/vendor_opts_unittest.cc index d76e0564a8..cb702fbddc 100644 --- a/src/bin/dhcp4/tests/vendor_opts_unittest.cc +++ b/src/bin/dhcp4/tests/vendor_opts_unittest.cc @@ -1419,3 +1419,59 @@ TEST_F(VendorOptsTest, clientOption43RawClass) { EXPECT_TRUE(client.getContext().response_); } +// Verifies that an a client query with a truncated length in +// vendor option (125) will still be processed by the server. +TEST_F(Dhcpv4SrvTest, truncatedVIVSOOption) { + IfaceMgrTestConfig test_config(true); + IfaceMgr::instance().openSockets4(); + + NakedDhcpv4Srv srv(0); + + string config = "{ \"interfaces-config\": {" + " \"interfaces\": [ \"*\" ]" + "}," + "\"rebind-timer\": 2000, " + "\"renew-timer\": 1000, " + "\"subnet4\": [ { " + " \"pools\": [ { \"pool\": \"10.206.80.0/25\" } ]," + " \"subnet\": \"10.206.80.0/24\", " + " \"rebind-timer\": 2000, " + " \"renew-timer\": 1000, " + " \"valid-lifetime\": 4000," + " \"interface\": \"eth0\" " + " } ]," + "\"valid-lifetime\": 4000 }"; + + ConstElementPtr json; + ASSERT_NO_THROW(json = parseDHCP4(config)); + ConstElementPtr status; + + // Configure the server and make sure the config is accepted + EXPECT_NO_THROW(status = configureDhcp4Server(srv, json)); + ASSERT_TRUE(status); + comment_ = parseAnswer(rcode_, status); + ASSERT_EQ(0, rcode_); + + CfgMgr::instance().commit(); + + // Create a DISCOVER with a VIVSO option whose length is + // too short. + Pkt4Ptr dis; + ASSERT_NO_THROW(dis = PktCaptures::discoverWithTruncatedVIVSO()); + + // 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 an response and it was an offer + Pkt4Ptr offer = srv.fake_sent_.front(); + ASSERT_TRUE(offer); +}