testParser(txt, ParserContext::PARSER_AGENT, false);
}
+// Tests if embedded comments are handled correctly.
+TEST(ParserTest, embbededComments) {
+ string txt= "{ \"Control-agent\": {"
+ " \"comment\": \"a comment\","
+ " \"http-host\": \"localhost\","
+ " \"http-port\": 9000,\n"
+ " \"control-sockets\": {\n"
+ " \"dhcp4\": {\n"
+ " \"user-context\": { \"comment\": \"indirect\" },\n"
+ " \"socket-type\": \"unix\"\n"
+ " } },\n"
+ " \"user-context\": { \"compatible\": true }\n"
+ "} }";
+ testParser(txt, ParserContext::PARSER_AGENT, false);
+}
+
/// @brief Loads specified example config file
///
/// This test loads specified example file twice: first, using the legacy
ParserContext::PARSER_AGENT,
"<string>:2.2-10: got unexpected keyword "
"\"topping\" in Control-agent map.");
+
+ // user context and embedded comments
+ testError("{ \"Control-agent\":{\n"
+ " \"comment\": true,\n"
+ " \"http-port\": 9000 }}\n",
+ ParserContext::PARSER_AGENT,
+ "<string>:2.14-17: syntax error, unexpected boolean, "
+ "expecting constant string");
+
+ testError("{ \"Control-agent\":{\n"
+ " \"user-context\": \"a comment\",\n"
+ " \"http-port\": 9000 }}\n",
+ ParserContext::PARSER_AGENT,
+ "<string>:2.19-29: syntax error, unexpected constant string, "
+ "expecting {");
+
+ testError("{ \"Control-agent\":{\n"
+ " \"comment\": \"a comment\",\n"
+ " \"comment\": \"another one\",\n"
+ " \"http-port\": 9000 }}\n",
+ ParserContext::PARSER_AGENT,
+ "<string>:3.3-11: duplicate user-context/comment entries "
+ "(previous at <string>:2:3)");
+
+ testError("{ \"Control-agent\":{\n"
+ " \"user-context\": { \"version\": 1 },\n"
+ " \"user-context\": { \"one\": \"only\" },\n"
+ " \"http-port\": 9000 }}\n",
+ ParserContext::PARSER_AGENT,
+ "<string>:3.3-16: duplicate user-context entries "
+ "(previous at <string>:2:19)");
+
+ testError("{ \"Control-agent\":{\n"
+ " \"user-context\": { \"comment\": \"indirect\" },\n"
+ " \"comment\": \"a comment\",\n"
+ " \"http-port\": 9000 }}\n",
+ ParserContext::PARSER_AGENT,
+ "<string>:3.3-11: duplicate user-context/comment entries "
+ "(previous at <string>:2:19)");
}
// Check unicode escapes
// Tests if bash (#) comments are supported. That's the only comment type that
// was supported by the old parser.
TEST(ParserTest, bashComments) {
- string txt= "{ \"Dhcp6\": { \"interfaces-config\": {"
- " \"interfaces\": [ \"*\" ]"
- "},\n"
- "\"preferred-lifetime\": 3000,\n"
- "# this is a comment\n"
- "\"rebind-timer\": 2000, \n"
- "# lots of comments here\n"
- "# and here\n"
- "\"renew-timer\": 1000, \n"
- "\"subnet6\": [ { "
- " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
- " \"subnet\": \"2001:db8:1::/48\", "
- " \"interface\": \"eth0\""
- " } ],"
- "\"valid-lifetime\": 4000 } }";
+ string txt =
+ "{ \"DhcpDdns\" : \n"
+ "{ \n"
+ " \"ip-address\": \"192.168.77.1\", \n"
+ "# this is a comment\n"
+ " \"port\": 777, \n "
+ " \"ncr-protocol\": \"UDP\", \n"
+ "# lots of comments here\n"
+ "# and here\n"
+ "\"tsig-keys\": [], \n"
+ "\"forward-ddns\" : {}, \n"
+ "\"reverse-ddns\" : {} \n"
+ "} \n"
+ "} \n";
testParser(txt, D2ParserContext::PARSER_DHCPDDNS);
}
// Tests if C++ (//) comments can start anywhere, not just in the first line.
TEST(ParserTest, cppComments) {
- string txt= "{ \"Dhcp6\": { \"interfaces-config\": {"
- " \"interfaces\": [ \"*\" ]"
- "},\n"
- "\"preferred-lifetime\": 3000, // this is a comment \n"
- "\"rebind-timer\": 2000, // everything after // is ignored\n"
- "\"renew-timer\": 1000, // this will be ignored, too\n"
- "\"subnet6\": [ { "
- " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
- " \"subnet\": \"2001:db8:1::/48\", "
- " \"interface\": \"eth0\""
- " } ],"
- "\"valid-lifetime\": 4000 } }";
+ string txt =
+ "{ \"DhcpDdns\" : \n"
+ "{ \n"
+ " \"ip-address\": \"192.168.77.1\", \n"
+ " \"port\": 777, // this is a comment \n"
+ " \"ncr-protocol\": \"UDP\", // everything after // is ignored\n"
+ "\"tsig-keys\": [], // this will be ignored, too\n"
+ "\"forward-ddns\" : {}, \n"
+ "\"reverse-ddns\" : {} \n"
+ "} \n"
+ "} \n";
testParser(txt, D2ParserContext::PARSER_DHCPDDNS, false);
}
// Tests if bash (#) comments can start anywhere, not just in the first line.
TEST(ParserTest, bashCommentsInline) {
- string txt= "{ \"Dhcp6\": { \"interfaces-config\": {"
- " \"interfaces\": [ \"*\" ]"
- "},\n"
- "\"preferred-lifetime\": 3000, # this is a comment \n"
- "\"rebind-timer\": 2000, # everything after # is ignored\n"
- "\"renew-timer\": 1000, # this will be ignored, too\n"
- "\"subnet6\": [ { "
- " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
- " \"subnet\": \"2001:db8:1::/48\", "
- " \"interface\": \"eth0\""
- " } ],"
- "\"valid-lifetime\": 4000 } }";
+ string txt =
+ "{ \"DhcpDdns\" : \n"
+ "{ \n"
+ " \"ip-address\": \"192.168.77.1\", \n"
+ " \"port\": 777, # this is a comment \n"
+ " \"ncr-protocol\": \"UDP\", # everything after # is ignored\n"
+ "\"tsig-keys\": [], # this will be ignored, too\n"
+ "\"forward-ddns\" : {}, \n"
+ "\"reverse-ddns\" : {} \n"
+ "} \n"
+ "} \n";
testParser(txt, D2ParserContext::PARSER_DHCPDDNS, false);
}
// Tests if multi-line C style comments are handled correctly.
TEST(ParserTest, multilineComments) {
- string txt= "{ \"Dhcp6\": { \"interfaces-config\": {"
- " \"interfaces\": [ \"*\" ]"
- "},\n"
- "\"preferred-lifetime\": 3000, /* this is a C style comment\n"
- "that\n can \n span \n multiple \n lines */ \n"
- "\"rebind-timer\": 2000,\n"
- "\"renew-timer\": 1000, \n"
- "\"subnet6\": [ { "
- " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
- " \"subnet\": \"2001:db8:1::/48\", "
- " \"interface\": \"eth0\""
- " } ],"
- "\"valid-lifetime\": 4000 } }";
+ string txt =
+ "{ \"DhcpDdns\" : \n"
+ "{ \n"
+ " \"ip-address\": \"192.168.77.1\", \n"
+ " \"port\": 777, /* this is a C style comment\n"
+ "that\n can \n span \n multiple \n lines */ \n"
+ " \"ncr-protocol\": \"UDP\", \n"
+ "\"tsig-keys\": [], \n"
+ "\"forward-ddns\" : {}, \n"
+ "\"reverse-ddns\" : {} \n"
+ "} \n"
+ "} \n";
+ testParser(txt, D2ParserContext::PARSER_DHCPDDNS, false);
+}
+
+// Tests if embedded comments are handled correctly.
+TEST(ParserTest, embbededComments) {
+ string txt =
+ "{ \"DhcpDdns\" : \n"
+ "{ \n"
+ "\"comment\": \"a comment\",\n"
+ " \"ip-address\": \"192.168.77.1\", \n"
+ " \"port\": 777, \n "
+ " \"ncr-protocol\": \"UDP\", \n"
+ "\"tsig-keys\" : [ { \n"
+ " \"name\" : \"d2.md5.key\", \n"
+ " \"user-context\" : { \"comment\" : \"indirect\" } } ], \n"
+ "\"forward-ddns\" : {}, \n"
+ "\"reverse-ddns\" : {}, \n"
+ "\"user-context\": { \"compatible\": true }"
+ "} \n"
+ "} \n";
testParser(txt, D2ParserContext::PARSER_DHCPDDNS, false);
}
D2ParserContext::PARSER_DHCPDDNS,
"<string>:2.2-16: got unexpected keyword "
"\"totally-bogus\" in DhcpDdns map.");
+
+ // user context and embedded comments
+ testError("{ \"DhcpDdns\":{\n"
+ " \"comment\": true,\n"
+ " \"dns-server-timeout\": 1000 }}\n",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:2.14-17: syntax error, unexpected boolean, "
+ "expecting constant string");
+
+ testError("{ \"DhcpDdns\":{\n"
+ " \"user-context\": \"a comment\",\n"
+ " \"dns-server-timeout\": 1000 }}\n",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:2.19-29: syntax error, unexpected constant string, "
+ "expecting {");
+
+ testError("{ \"DhcpDdns\":{\n"
+ " \"comment\": \"a comment\",\n"
+ " \"comment\": \"another one\",\n"
+ " \"dns-server-timeout\": 1000 }}\n",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:3.3-11: duplicate user-context/comment entries "
+ "(previous at <string>:2:3)");
+
+ testError("{ \"DhcpDdns\":{\n"
+ " \"user-context\": { \"version\": 1 },\n"
+ " \"user-context\": { \"one\": \"only\" },\n"
+ " \"dns-server-timeout\": 1000 }}\n",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:3.3-16: duplicate user-context entries "
+ "(previous at <string>:2:19)");
+
+ testError("{ \"DhcpDdns\":{\n"
+ " \"user-context\": { \"comment\": \"indirect\" },\n"
+ " \"comment\": \"a comment\",\n"
+ " \"dns-server-timeout\": 1000 }}\n",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:3.3-11: duplicate user-context/comment entries "
+ "(previous at <string>:2:19)");
}
// Check unicode escapes
-// Copyright (C) 2016-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2016-2018 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
testParser(txt, Parser4Context::PARSER_DHCP4, false);
}
+// Tests if embedded comments are handled correctly.
+TEST(ParserTest, embbededComments) {
+ string txt= "{ \"Dhcp4\": { \"interfaces-config\": {"
+ " \"interfaces\": [ \"*\" ]"
+ "},\n"
+ "\"comment\": \"a comment\",\n"
+ "\"rebind-timer\": 2000,\n"
+ "\"renew-timer\": 1000, \n"
+ "\"subnet4\": [ { "
+ " \"user-context\": { \"comment\": \"indirect\" },"
+ " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ],"
+ " \"subnet\": \"192.0.2.0/24\", "
+ " \"interface\": \"eth0\""
+ " } ],"
+ "\"user-context\": { \"compatible\": true },"
+ "\"valid-lifetime\": 4000 } }";
+ testParser(txt, Parser4Context::PARSER_DHCP4, false);
+}
/// @brief Loads specified example config file
///
Parser4Context::PARSER_OPTION_DEF,
"missing parameter 'type' (<string>:1:1) "
"[option-def map between <string>:1:1 and <string>:2:15]");
+
+ // user context and embedded comments
+ testError("{ \"Dhcp4\":{\n"
+ " \"comment\": true,\n"
+ " \"valid-lifetime\": 600 }}\n",
+ Parser4Context::PARSER_DHCP4,
+ "<string>:2.14-17: syntax error, unexpected boolean, "
+ "expecting constant string");
+
+ testError("{ \"Dhcp4\":{\n"
+ " \"user-context\": \"a comment\",\n"
+ " \"valid-lifetime\": 600 }}\n",
+ Parser4Context::PARSER_DHCP4,
+ "<string>:2.19-29: syntax error, unexpected constant string, "
+ "expecting {");
+
+ testError("{ \"Dhcp4\":{\n"
+ " \"comment\": \"a comment\",\n"
+ " \"comment\": \"another one\",\n"
+ " \"valid-lifetime\": 600 }}\n",
+ Parser4Context::PARSER_DHCP4,
+ "<string>:3.3-11: duplicate user-context/comment entries "
+ "(previous at <string>:2:3)");
+
+ testError("{ \"Dhcp4\":{\n"
+ " \"user-context\": { \"version\": 1 },\n"
+ " \"user-context\": { \"one\": \"only\" },\n"
+ " \"valid-lifetime\": 600 }}\n",
+ Parser4Context::PARSER_DHCP4,
+ "<string>:3.3-16: duplicate user-context entries "
+ "(previous at <string>:2:19)");
+
+ testError("{ \"Dhcp4\":{\n"
+ " \"user-context\": { \"comment\": \"indirect\" },\n"
+ " \"comment\": \"a comment\",\n"
+ " \"valid-lifetime\": 600 }}\n",
+ Parser4Context::PARSER_DHCP4,
+ "<string>:3.3-11: duplicate user-context/comment entries "
+ "(previous at <string>:2:19)");
}
// Check unicode escapes
-// Copyright (C) 2016-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2016-2018 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
testParser(txt, Parser6Context::PARSER_DHCP6, false);
}
+// Tests if embedded comments are handled correctly.
+TEST(ParserTest, embbededComments) {
+ string txt= "{ \"Dhcp6\": { \"interfaces-config\": {"
+ " \"interfaces\": [ \"*\" ]"
+ "},\n"
+ "\"comment\": \"a comment\",\n"
+ "\"preferred-lifetime\": 3000,\n"
+ "\"rebind-timer\": 2000,\n"
+ "\"renew-timer\": 1000, \n"
+ "\"subnet6\": [ { "
+ " \"user-context\": { \"comment\": \"indirect\" },"
+ " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
+ " \"subnet\": \"2001:db8:1::/48\", "
+ " \"interface\": \"eth0\""
+ " } ],"
+ "\"user-context\": { \"compatible\": true },"
+ "\"valid-lifetime\": 4000 } }";
+ testParser(txt, Parser6Context::PARSER_DHCP6, false);
+}
+
/// @brief Loads specified example config file
///
/// This test loads specified example file twice: first, using the legacy
Parser6Context::PARSER_OPTION_DEF,
"missing parameter 'type' (<string>:1:1) "
"[option-def map between <string>:1:1 and <string>:2:15]");
+
+ // user context and embedded comments
+ testError("{ \"Dhcp6\":{\n"
+ " \"comment\": true,\n"
+ " \"preferred-lifetime\": 600 }}\n",
+ Parser6Context::PARSER_DHCP6,
+ "<string>:2.14-17: syntax error, unexpected boolean, "
+ "expecting constant string");
+
+ testError("{ \"Dhcp6\":{\n"
+ " \"user-context\": \"a comment\",\n"
+ " \"preferred-lifetime\": 600 }}\n",
+ Parser6Context::PARSER_DHCP6,
+ "<string>:2.19-29: syntax error, unexpected constant string, "
+ "expecting {");
+
+ testError("{ \"Dhcp6\":{\n"
+ " \"comment\": \"a comment\",\n"
+ " \"comment\": \"another one\",\n"
+ " \"preferred-lifetime\": 600 }}\n",
+ Parser6Context::PARSER_DHCP6,
+ "<string>:3.3-11: duplicate user-context/comment entries "
+ "(previous at <string>:2:3)");
+
+ testError("{ \"Dhcp6\":{\n"
+ " \"user-context\": { \"version\": 1 },\n"
+ " \"user-context\": { \"one\": \"only\" },\n"
+ " \"preferred-lifetime\": 600 }}\n",
+ Parser6Context::PARSER_DHCP6,
+ "<string>:3.3-16: duplicate user-context entries "
+ "(previous at <string>:2:19)");
+
+ testError("{ \"Dhcp6\":{\n"
+ " \"user-context\": { \"comment\": \"indirect\" },\n"
+ " \"comment\": \"a comment\",\n"
+ " \"preferred-lifetime\": 600 }}\n",
+ Parser6Context::PARSER_DHCP6,
+ "<string>:3.3-11: duplicate user-context/comment entries "
+ "(previous at <string>:2:19)");
}
// Check unicode escapes