|
@@ -1,4 +1,4 @@
|
|
|
-// Copyright (C) 2012-2016 Internet Systems Consortium, Inc. ("ISC")
|
|
|
+// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC")
|
|
|
//
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
@@ -226,48 +226,95 @@ TEST_F(DhcpParserTest, uint32ParserTest) {
|
|
|
EXPECT_EQ(test_value, actual_value);
|
|
|
}
|
|
|
|
|
|
-/// @brief Check MACSourcesListConfigParser basic functionality
|
|
|
+/// Verifies the code that parses mac sources and adds them to CfgMgr
|
|
|
+TEST_F(DhcpParserTest, MacSources) {
|
|
|
+
|
|
|
+ // That's an equivalent of the following snippet:
|
|
|
+ // "mac-sources: [ \"duid\", \"ipv6\" ]";
|
|
|
+ ElementPtr values = Element::createList();
|
|
|
+ values->add(Element::create("duid"));
|
|
|
+ values->add(Element::create("ipv6-link-local"));
|
|
|
+
|
|
|
+ // Let's grab server configuration from CfgMgr
|
|
|
+ SrvConfigPtr cfg = CfgMgr::instance().getStagingCfg();
|
|
|
+ ASSERT_TRUE(cfg);
|
|
|
+ CfgMACSource& sources = cfg->getMACSources();
|
|
|
+
|
|
|
+ // This should parse the configuration and check that it doesn't throw.
|
|
|
+ MACSourcesListConfigParser parser;
|
|
|
+ EXPECT_NO_THROW(parser.parse(sources, values));
|
|
|
+
|
|
|
+ // Finally, check the sources that were configured
|
|
|
+ CfgMACSources configured_sources = cfg->getMACSources().get();
|
|
|
+ ASSERT_EQ(2, configured_sources.size());
|
|
|
+ EXPECT_EQ(HWAddr::HWADDR_SOURCE_DUID, configured_sources[0]);
|
|
|
+ EXPECT_EQ(HWAddr::HWADDR_SOURCE_IPV6_LINK_LOCAL, configured_sources[1]);
|
|
|
+}
|
|
|
+
|
|
|
+/// @brief Check MACSourcesListConfigParser rejecting empty list
|
|
|
///
|
|
|
-/// Verifies that the parser:
|
|
|
-/// 1. Does not allow empty for storage.
|
|
|
-/// 2. Does not allow name other than "mac-sources"
|
|
|
-/// 3. Parses list of mac sources and adds them to CfgMgr
|
|
|
-TEST_F(DhcpParserTest, MacSourcesListConfigParserTest) {
|
|
|
+/// Verifies that the code rejects an empty mac-sources list.
|
|
|
+TEST_F(DhcpParserTest, MacSourcesEmpty) {
|
|
|
|
|
|
- const std::string valid_name = "mac-sources";
|
|
|
- const std::string bogus_name = "bogus-name";
|
|
|
+ // That's an equivalent of the following snippet:
|
|
|
+ // "mac-sources: [ \"duid\", \"ipv6\" ]";
|
|
|
+ ElementPtr values = Element::createList();
|
|
|
+
|
|
|
+ // Let's grab server configuration from CfgMgr
|
|
|
+ SrvConfigPtr cfg = CfgMgr::instance().getStagingCfg();
|
|
|
+ ASSERT_TRUE(cfg);
|
|
|
+ CfgMACSource& sources = cfg->getMACSources();
|
|
|
|
|
|
- ParserContextPtr parser_context(new ParserContext(Option::V6));
|
|
|
+ // This should throw, because if specified, at least one MAC source
|
|
|
+ // has to be specified.
|
|
|
+ MACSourcesListConfigParser parser;
|
|
|
+ EXPECT_THROW(parser.parse(sources, values), DhcpConfigError);
|
|
|
+}
|
|
|
|
|
|
- // Verify that parser constructor fails if parameter name isn't "mac-sources"
|
|
|
- EXPECT_THROW(MACSourcesListConfigParser(bogus_name, parser_context),
|
|
|
- isc::BadValue);
|
|
|
+/// @brief Check MACSourcesListConfigParser rejecting empty list
|
|
|
+///
|
|
|
+/// Verifies that the code rejects fake mac source.
|
|
|
+TEST_F(DhcpParserTest, MacSourcesBogus) {
|
|
|
|
|
|
// That's an equivalent of the following snippet:
|
|
|
// "mac-sources: [ \"duid\", \"ipv6\" ]";
|
|
|
- ElementPtr config = Element::createList();
|
|
|
- config->add(Element::create("duid"));
|
|
|
- config->add(Element::create("ipv6-link-local"));
|
|
|
+ ElementPtr values = Element::createList();
|
|
|
+ values->add(Element::create("from-ebay"));
|
|
|
+ values->add(Element::create("just-guess-it"));
|
|
|
+
|
|
|
+ // Let's grab server configuration from CfgMgr
|
|
|
+ SrvConfigPtr cfg = CfgMgr::instance().getStagingCfg();
|
|
|
+ ASSERT_TRUE(cfg);
|
|
|
+ CfgMACSource& sources = cfg->getMACSources();
|
|
|
+
|
|
|
+ // This should throw, because these are not valid sources.
|
|
|
+ MACSourcesListConfigParser parser;
|
|
|
+ EXPECT_THROW(parser.parse(sources, values), DhcpConfigError);
|
|
|
+}
|
|
|
|
|
|
- boost::scoped_ptr<MACSourcesListConfigParser>
|
|
|
- parser(new MACSourcesListConfigParser(valid_name, parser_context));
|
|
|
+/// Verifies the code that properly catches duplicate entries
|
|
|
+/// in mac-sources definition.
|
|
|
+TEST_F(DhcpParserTest, MacSourcesDuplicate) {
|
|
|
|
|
|
- // This should parse the configuration and add eth0 and eth1 to the list
|
|
|
- // of interfaces that server should listen on.
|
|
|
- EXPECT_NO_THROW(parser->build(config));
|
|
|
- EXPECT_NO_THROW(parser->commit());
|
|
|
+ // That's an equivalent of the following snippet:
|
|
|
+ // "mac-sources: [ \"duid\", \"ipv6\" ]";
|
|
|
+ ElementPtr values = Element::createList();
|
|
|
+ values->add(Element::create("ipv6-link-local"));
|
|
|
+ values->add(Element::create("duid"));
|
|
|
+ values->add(Element::create("duid"));
|
|
|
+ values->add(Element::create("duid"));
|
|
|
|
|
|
- // Use CfgMgr instance to check if eth0 and eth1 was added, and that
|
|
|
- // eth2 was not added.
|
|
|
+ // Let's grab server configuration from CfgMgr
|
|
|
SrvConfigPtr cfg = CfgMgr::instance().getStagingCfg();
|
|
|
ASSERT_TRUE(cfg);
|
|
|
- CfgMACSources configured_sources = cfg->getMACSources().get();
|
|
|
+ CfgMACSource& sources = cfg->getMACSources();
|
|
|
|
|
|
- ASSERT_EQ(2, configured_sources.size());
|
|
|
- EXPECT_EQ(HWAddr::HWADDR_SOURCE_DUID, configured_sources[0]);
|
|
|
- EXPECT_EQ(HWAddr::HWADDR_SOURCE_IPV6_LINK_LOCAL, configured_sources[1]);
|
|
|
+ // This should parse the configuration and check that it throws.
|
|
|
+ MACSourcesListConfigParser parser;
|
|
|
+ EXPECT_THROW(parser.parse(sources, values), DhcpConfigError);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/// @brief Test Fixture class which provides basic structure for testing
|
|
|
/// configuration parsing. This is essentially the same structure provided
|
|
|
/// by dhcp servers.
|
|
@@ -2416,6 +2463,19 @@ TEST_F(ParseConfigTest, validRelayInfo4) {
|
|
|
" }";
|
|
|
ElementPtr json = Element::fromJSON(config_str);
|
|
|
|
|
|
+ // We need to set the default ip-address to something.
|
|
|
+ Subnet::RelayInfoPtr result(new Subnet::RelayInfo(asiolink::IOAddress("0.0.0.0")));
|
|
|
+
|
|
|
+ RelayInfoParser parser(Option::V4);
|
|
|
+
|
|
|
+ // Subnet4 parser will pass 0.0.0.0 to the RelayInfoParser
|
|
|
+ EXPECT_NO_THROW(parser.parse(result, json));
|
|
|
+ EXPECT_EQ("192.0.2.1", result->addr_.toText());
|
|
|
+}
|
|
|
+
|
|
|
+/// @brief Checks that a bogus relay info structure for IPv4 is rejected.
|
|
|
+TEST_F(ParseConfigTest, bogusRelayInfo4) {
|
|
|
+
|
|
|
// Invalid config (wrong family type of the ip-address field)
|
|
|
std::string config_str_bogus1 =
|
|
|
" {"
|
|
@@ -2430,24 +2490,25 @@ TEST_F(ParseConfigTest, validRelayInfo4) {
|
|
|
" }";
|
|
|
ElementPtr json_bogus2 = Element::fromJSON(config_str_bogus2);
|
|
|
|
|
|
- // We need to set the default ip-address to something.
|
|
|
- Subnet::RelayInfoPtr result(new Subnet::RelayInfo(asiolink::IOAddress("0.0.0.0")));
|
|
|
+ // Invalid config (ip-address is mandatory)
|
|
|
+ std::string config_str_bogus3 =
|
|
|
+ " {"
|
|
|
+ " }";
|
|
|
+ ElementPtr json_bogus3 = Element::fromJSON(config_str_bogus3);
|
|
|
|
|
|
- boost::shared_ptr<RelayInfoParser> parser;
|
|
|
+ // We need to set the default ip-address to something.
|
|
|
+ Subnet::RelayInfoPtr result(new Subnet::RelayInfo(IOAddress::IPV4_ZERO_ADDRESS()));
|
|
|
|
|
|
- // Subnet4 parser will pass 0.0.0.0 to the RelayInfoParser
|
|
|
- EXPECT_NO_THROW(parser.reset(new RelayInfoParser("ignored", result,
|
|
|
- Option::V4)));
|
|
|
- EXPECT_NO_THROW(parser->build(json));
|
|
|
- EXPECT_NO_THROW(parser->commit());
|
|
|
+ RelayInfoParser parser(Option::V4);
|
|
|
|
|
|
- EXPECT_EQ("192.0.2.1", result->addr_.toText());
|
|
|
+ // wrong family type
|
|
|
+ EXPECT_THROW(parser.parse(result, json_bogus1), DhcpConfigError);
|
|
|
|
|
|
- // Let's check negative scenario (wrong family type)
|
|
|
- EXPECT_THROW(parser->build(json_bogus1), DhcpConfigError);
|
|
|
+ // Too large byte values in pseudo-IPv4 addr
|
|
|
+ EXPECT_THROW(parser.parse(result, json_bogus2), DhcpConfigError);
|
|
|
|
|
|
- // Let's check negative scenario (too large byte values in pseudo-IPv4 addr)
|
|
|
- EXPECT_THROW(parser->build(json_bogus2), DhcpConfigError);
|
|
|
+ // Mandatory ip-address is missing. What a pity.
|
|
|
+ EXPECT_THROW(parser.parse(result, json_bogus2), DhcpConfigError);
|
|
|
}
|
|
|
|
|
|
/// @brief Checks that a valid relay info structure for IPv6 can be handled
|
|
@@ -2460,6 +2521,18 @@ TEST_F(ParseConfigTest, validRelayInfo6) {
|
|
|
" }";
|
|
|
ElementPtr json = Element::fromJSON(config_str);
|
|
|
|
|
|
+ // We need to set the default ip-address to something.
|
|
|
+ Subnet::RelayInfoPtr result(new Subnet::RelayInfo(asiolink::IOAddress("::")));
|
|
|
+
|
|
|
+ RelayInfoParser parser(Option::V6);
|
|
|
+ // Subnet4 parser will pass :: to the RelayInfoParser
|
|
|
+ EXPECT_NO_THROW(parser.parse(result, json));
|
|
|
+ EXPECT_EQ("2001:db8::1", result->addr_.toText());
|
|
|
+}
|
|
|
+
|
|
|
+/// @brief Checks that a valid relay info structure for IPv6 can be handled
|
|
|
+TEST_F(ParseConfigTest, bogusRelayInfo6) {
|
|
|
+
|
|
|
// Invalid config (wrong family type of the ip-address field
|
|
|
std::string config_str_bogus1 =
|
|
|
" {"
|
|
@@ -2474,23 +2547,25 @@ TEST_F(ParseConfigTest, validRelayInfo6) {
|
|
|
" }";
|
|
|
ElementPtr json_bogus2 = Element::fromJSON(config_str_bogus2);
|
|
|
|
|
|
+ // Missing mandatory ip-address field.
|
|
|
+ std::string config_str_bogus3 =
|
|
|
+ " {"
|
|
|
+ " }";
|
|
|
+ ElementPtr json_bogus3 = Element::fromJSON(config_str_bogus3);
|
|
|
+
|
|
|
// We need to set the default ip-address to something.
|
|
|
Subnet::RelayInfoPtr result(new Subnet::RelayInfo(asiolink::IOAddress("::")));
|
|
|
|
|
|
- boost::shared_ptr<RelayInfoParser> parser;
|
|
|
- // Subnet4 parser will pass :: to the RelayInfoParser
|
|
|
- EXPECT_NO_THROW(parser.reset(new RelayInfoParser("ignored", result,
|
|
|
- Option::V6)));
|
|
|
- EXPECT_NO_THROW(parser->build(json));
|
|
|
- EXPECT_NO_THROW(parser->commit());
|
|
|
+ RelayInfoParser parser(Option::V6);
|
|
|
|
|
|
- EXPECT_EQ("2001:db8::1", result->addr_.toText());
|
|
|
+ // Negative scenario (wrong family type)
|
|
|
+ EXPECT_THROW(parser.parse(result, json_bogus1), DhcpConfigError);
|
|
|
|
|
|
- // Let's check negative scenario (wrong family type)
|
|
|
- EXPECT_THROW(parser->build(json_bogus1), DhcpConfigError);
|
|
|
+ // Looks like IPv6 address, but has too many colons
|
|
|
+ EXPECT_THROW(parser.parse(result, json_bogus2), DhcpConfigError);
|
|
|
|
|
|
- // Unparseable text that looks like IPv6 address, but has too many colons
|
|
|
- EXPECT_THROW(parser->build(json_bogus2), DhcpConfigError);
|
|
|
+ // Mandatory ip-address is missing. What a pity.
|
|
|
+ EXPECT_THROW(parser.parse(result, json_bogus3), DhcpConfigError);
|
|
|
}
|
|
|
|
|
|
// There's no test for ControlSocketParser, as it is tested in the DHCPv4 code
|