From: Marcin Siodelski Date: Fri, 20 May 2016 07:45:26 +0000 (+0200) Subject: [4317] Extended unit tests for DHCPv4 config parser to use client-id. X-Git-Tag: trac4106_update_base~1^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1bd8b4a26c29a3d4e1c1fd1695d8c09bbed3ff78;p=thirdparty%2Fkea.git [4317] Extended unit tests for DHCPv4 config parser to use client-id. --- diff --git a/src/bin/dhcp4/tests/config_parser_unittest.cc b/src/bin/dhcp4/tests/config_parser_unittest.cc index d166a6570f..4f69f25aa4 100644 --- a/src/bin/dhcp4/tests/config_parser_unittest.cc +++ b/src/bin/dhcp4/tests/config_parser_unittest.cc @@ -3457,6 +3457,11 @@ TEST_F(Dhcp4ParserTest, reservations) { " \"circuit-id\": \"060504030201\"," " \"ip-address\": \"192.0.4.102\"," " \"hostname\": \"\"" + " }," + " {" + " \"client-id\": \"05:01:02:03:04:05:06\"," + " \"ip-address\": \"192.0.4.103\"," + " \"hostname\": \"\"" " }" " ]" " } ]," @@ -3542,6 +3547,7 @@ TEST_F(Dhcp4ParserTest, reservations) { EXPECT_FALSE(hosts_cfg->get4(234, Host::IDENT_CIRCUIT_ID, &circuit_id[0], circuit_id.size())); + // Repeat the test for the DUID based reservation in this subnet. duid.reset(new DUID(std::vector(duid_vec.rbegin(), duid_vec.rend()))); @@ -3559,6 +3565,18 @@ TEST_F(Dhcp4ParserTest, reservations) { opt_ttl = retrieveOption(*host, DHO_DEFAULT_IP_TTL); ASSERT_TRUE(opt_ttl); EXPECT_EQ(95, static_cast(opt_ttl->getValue())); + + // Check that we can find reservation using client identifier. + ClientIdPtr client_id = ClientId::fromText("05:01:02:03:04:05:06"); + host = hosts_cfg->get4(542, Host::IDENT_CLIENT_ID, &client_id->getDuid()[0], + client_id->getDuid().size()); + ASSERT_TRUE(host); + EXPECT_EQ("192.0.4.103", host->getIPv4Reservation().toText()); + + // But this reservation should not be returned for other subnet. + host = hosts_cfg->get4(234, Host::IDENT_CLIENT_ID, &client_id->getDuid()[0], + client_id->getDuid().size()); + EXPECT_FALSE(host); } // This test checks that it is possible to configure option data for a