From: Tomek Mrugalski Date: Thu, 5 Jan 2017 13:43:40 +0000 (+0100) Subject: [5032] MAC sources unit-tests in src/bin/dhcp6 improved X-Git-Tag: trac5044_base~1^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3305fecc23ea8c6f8ec97655fbeb7f88ee2cd8f6;p=thirdparty%2Fkea.git [5032] MAC sources unit-tests in src/bin/dhcp6 improved --- diff --git a/src/bin/dhcp6/tests/config_parser_unittest.cc b/src/bin/dhcp6/tests/config_parser_unittest.cc index 11a0651cf0..fc479fc12e 100644 --- a/src/bin/dhcp6/tests/config_parser_unittest.cc +++ b/src/bin/dhcp6/tests/config_parser_unittest.cc @@ -251,6 +251,9 @@ public: ASSERT_TRUE(status); comment_ = parseAnswer(rcode_, status); EXPECT_EQ(expected_code, rcode_); + if (expected_code != rcode_) { + cout << "The comment returned was: [" << comment_->stringValue() << "]" << endl; + } } /// @brief Returns an interface configuration used by the most of the @@ -4292,16 +4295,15 @@ TEST_F(Dhcp6ParserTest, reservationBogus) { } /// The goal of this test is to verify that configuration can include -/// MAC/Hardware sources. This test also checks if the aliases are -/// handled properly (rfc6939 = client-addr-relay, rfc4649 = remote-id, -/// rfc4580 = subscriber-id). -TEST_F(Dhcp6ParserTest, macSources) { +/// MAC/Hardware sources. This case uses RFC numbers to reference methods. +/// Also checks if the aliases are handled properly (rfc6939 = client-addr-relay, +/// rfc4649 = remote-id, rfc4580 = subscriber-id). +TEST_F(Dhcp6ParserTest, macSources1) { ConstElementPtr json; ASSERT_NO_THROW(json = parseDHCP6("{ " + genIfaceConfig() + "," - "\"mac-sources\": [ \"rfc6939\", \"rfc4649\", \"rfc4580\"," - "\"client-link-addr-option\", \"remote-id\", \"subscriber-id\"]," + "\"mac-sources\": [ \"rfc6939\", \"rfc4649\", \"rfc4580\" ]," "\"preferred-lifetime\": 3000," "\"rebind-timer\": 2000, " "\"renew-timer\": 1000, " @@ -4310,23 +4312,46 @@ TEST_F(Dhcp6ParserTest, macSources) { ConstElementPtr status; EXPECT_NO_THROW(status = configureDhcp6Server(srv_, json)); + checkResult(status, 0); - // returned value should be 0 (success) + CfgMACSources sources = CfgMgr::instance().getStagingCfg()->getMACSources().get(); + + ASSERT_EQ(3, sources.size()); + // Let's check the aliases. They should be recognized to their base methods. + EXPECT_EQ(HWAddr::HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION, sources[0]); + EXPECT_EQ(HWAddr::HWADDR_SOURCE_REMOTE_ID, sources[1]); + EXPECT_EQ(HWAddr::HWADDR_SOURCE_SUBSCRIBER_ID, sources[2]); +} + +/// The goal of this test is to verify that configuration can include +/// MAC/Hardware sources. This uses specific method names. +TEST_F(Dhcp6ParserTest, macSources2) { + + ConstElementPtr json; + ASSERT_NO_THROW(json = + parseDHCP6("{ " + genIfaceConfig() + "," + "\"mac-sources\": [ \"client-link-addr-option\", \"remote-id\", " + " \"subscriber-id\"]," + "\"preferred-lifetime\": 3000," + "\"rebind-timer\": 2000, " + "\"renew-timer\": 1000, " + "\"subnet6\": [ ], " + "\"valid-lifetime\": 4000 }")); + + ConstElementPtr status; + EXPECT_NO_THROW(status = configureDhcp6Server(srv_, json)); checkResult(status, 0); - CfgMACSources mac_sources = CfgMgr::instance().getStagingCfg()->getMACSources().get(); - ASSERT_EQ(6, mac_sources.size()); + CfgMACSources sources = CfgMgr::instance().getStagingCfg()->getMACSources().get(); + + ASSERT_EQ(3, sources.size()); // Let's check the aliases. They should be recognized to their base methods. - EXPECT_EQ(HWAddr::HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION, mac_sources[0]); - EXPECT_EQ(HWAddr::HWADDR_SOURCE_REMOTE_ID, mac_sources[1]); - EXPECT_EQ(HWAddr::HWADDR_SOURCE_SUBSCRIBER_ID, mac_sources[2]); - - // Let's check if the actual methods are recognized properly. - EXPECT_EQ(HWAddr::HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION, mac_sources[3]); - EXPECT_EQ(HWAddr::HWADDR_SOURCE_REMOTE_ID, mac_sources[4]); - EXPECT_EQ(HWAddr::HWADDR_SOURCE_SUBSCRIBER_ID, mac_sources[5]); + EXPECT_EQ(HWAddr::HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION, sources[0]); + EXPECT_EQ(HWAddr::HWADDR_SOURCE_REMOTE_ID, sources[1]); + EXPECT_EQ(HWAddr::HWADDR_SOURCE_SUBSCRIBER_ID, sources[2]); } + /// The goal of this test is to verify that empty MAC sources configuration /// is rejected. If specified, this has to have at least one value. TEST_F(Dhcp6ParserTest, macSourcesEmpty) {