|
@@ -1278,6 +1278,20 @@ TEST_F(ParseConfigTest, validRelayInfo4) {
|
|
|
" }";
|
|
|
ElementPtr json = Element::fromJSON(config_str);
|
|
|
|
|
|
+ // Invalid config (wrong family type of the ip-address field)
|
|
|
+ std::string config_str_bogus1 =
|
|
|
+ " {"
|
|
|
+ " \"ip-address\" : \"2001:db8::1\""
|
|
|
+ " }";
|
|
|
+ ElementPtr json_bogus1 = Element::fromJSON(config_str_bogus1);
|
|
|
+
|
|
|
+ // Invalid config (that thing is not an IPv4 address)
|
|
|
+ std::string config_str_bogus2 =
|
|
|
+ " {"
|
|
|
+ " \"ip-address\" : \"256.345.123.456\""
|
|
|
+ " }";
|
|
|
+ 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")));
|
|
|
|
|
@@ -1285,11 +1299,17 @@ TEST_F(ParseConfigTest, validRelayInfo4) {
|
|
|
|
|
|
// Subnet4 parser will pass 0.0.0.0 to the RelayInfoParser
|
|
|
EXPECT_NO_THROW(parser.reset(new RelayInfoParser("ignored", result,
|
|
|
- asiolink::IOAddress("0.0.0.0"))));
|
|
|
+ Option::V4)));
|
|
|
EXPECT_NO_THROW(parser->build(json));
|
|
|
EXPECT_NO_THROW(parser->commit());
|
|
|
|
|
|
EXPECT_EQ("192.0.2.1", result->addr_.toText());
|
|
|
+
|
|
|
+ // Let's check negative scenario (wrong family type)
|
|
|
+ EXPECT_THROW(parser->build(json_bogus1), DhcpConfigError);
|
|
|
+
|
|
|
+ // Let's check negative scenario (too large byte values in pseudo-IPv4 addr)
|
|
|
+ EXPECT_THROW(parser->build(json_bogus2), DhcpConfigError);
|
|
|
}
|
|
|
|
|
|
/// @brief Checks that a valid relay info structure for IPv6 can be handled
|
|
@@ -1302,15 +1322,35 @@ TEST_F(ParseConfigTest, validRelayInfo6) {
|
|
|
" }";
|
|
|
ElementPtr json = Element::fromJSON(config_str);
|
|
|
|
|
|
+ // Invalid config (wrong family type of the ip-address field
|
|
|
+ std::string config_str_bogus1 =
|
|
|
+ " {"
|
|
|
+ " \"ip-address\" : \"192.0.2.1\""
|
|
|
+ " }";
|
|
|
+ ElementPtr json_bogus1 = Element::fromJSON(config_str_bogus1);
|
|
|
+
|
|
|
+ // That IPv6 address doesn't look right
|
|
|
+ std::string config_str_bogus2 =
|
|
|
+ " {"
|
|
|
+ " \"ip-address\" : \"2001:db8:::4\""
|
|
|
+ " }";
|
|
|
+ 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("::")));
|
|
|
|
|
|
boost::shared_ptr<RelayInfoParser> parser;
|
|
|
// Subnet4 parser will pass :: to the RelayInfoParser
|
|
|
EXPECT_NO_THROW(parser.reset(new RelayInfoParser("ignored", result,
|
|
|
- asiolink::IOAddress("::"))));
|
|
|
+ Option::V6)));
|
|
|
EXPECT_NO_THROW(parser->build(json));
|
|
|
EXPECT_NO_THROW(parser->commit());
|
|
|
|
|
|
EXPECT_EQ("2001:db8::1", result->addr_.toText());
|
|
|
+
|
|
|
+ // Let's check negative scenario (wrong family type)
|
|
|
+ EXPECT_THROW(parser->build(json_bogus1), DhcpConfigError);
|
|
|
+
|
|
|
+ // Unparseable text that looks like IPv6 address, but has too many colons
|
|
|
+ EXPECT_THROW(parser->build(json_bogus2), DhcpConfigError);
|
|
|
}
|