From: Tomek Mrugalski Date: Fri, 11 Dec 2015 14:00:43 +0000 (+0100) Subject: [4206b] Added unit-tests for too long client-id/DUID. X-Git-Tag: trac4240_base~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dc498ad0d7335992b2e4ae76d45d3396b6e77557;p=thirdparty%2Fkea.git [4206b] Added unit-tests for too long client-id/DUID. --- diff --git a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc index d155135786..cae001c0bb 100644 --- a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc @@ -2684,6 +2684,32 @@ TEST_F(Dhcpv4SrvTest, emptyClientId) { EXPECT_NO_THROW(client.doDORA()); } +// This test verifies that the server is able to handle too long client-id +// in incoming client message. +TEST_F(Dhcpv4SrvTest, tooLongClientId) { + IfaceMgrTestConfig test_config(true); + IfaceMgr::instance().openSockets4(); + 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. + std::vector data(250, 250); + OptionPtr long_client_id(new Option(Option::V4, DHO_DHCP_CLIENT_IDENTIFIER, + data)); + client.addExtraOption(long_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()); +} + /// @todo: Implement proper tests for MySQL lease/host database, /// see ticket #4214. diff --git a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc index efedf14ce2..6b68a0a2ce 100644 --- a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc @@ -2804,6 +2804,40 @@ TEST_F(Dhcpv6SrvTest, emptyServerId) { EXPECT_NO_THROW(client.doSARR()); } +// This test verifies that the server is able to handle a too large DUID (server-id) +// in incoming client message. +TEST_F(Dhcpv6SrvTest, tooLongServerId) { + Dhcp6Client client; + + // The following configuration enables RSOO options: 110 and 120. + // It also configures the server with option 120 which should + // "override" the option 120 sent in the RSOO by the relay. + string config = + "{" + " \"preferred-lifetime\": 3000," + " \"rebind-timer\": 2000, " + " \"renew-timer\": 1000, " + " \"subnet6\": [ { " + " \"pools\": [ { \"pool\": \"2001:db8::/64\" } ]," + " \"subnet\": \"2001:db8::/48\" " + " } ]," + " \"valid-lifetime\": 4000" + "}"; + + EXPECT_NO_THROW(configure(config, *client.getServer())); + + // Tell the client to use this specific server-id. + std::vector data(250, 250); + OptionPtr long_server_id(new Option(Option::V6, D6O_SERVERID, data)); + client.useServerId(long_server_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.doSARR()); +} + /// @todo: Add more negative tests for processX(), e.g. extend sanityCheck() test /// to call processX() methods.