From: Francis Dupont Date: Tue, 2 Jan 2018 15:52:25 +0000 (+0100) Subject: [5491] Added a positive and a few negative user context / embedded comment tests... X-Git-Tag: trac5458a_base~18^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=539645e6734718c3e04fe9ccfdb828a937610fe9;p=thirdparty%2Fkea.git [5491] Added a positive and a few negative user context / embedded comment tests per server --- diff --git a/src/bin/agent/tests/parser_unittests.cc b/src/bin/agent/tests/parser_unittests.cc index e777811463..c7d8fb7c3b 100644 --- a/src/bin/agent/tests/parser_unittests.cc +++ b/src/bin/agent/tests/parser_unittests.cc @@ -303,6 +303,22 @@ TEST(ParserTest, multilineComments) { 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 @@ -596,6 +612,45 @@ TEST(ParserTest, errors) { ParserContext::PARSER_AGENT, ":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, + ":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, + ":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, + ":3.3-11: duplicate user-context/comment entries " + "(previous at :2:3)"); + + testError("{ \"Control-agent\":{\n" + " \"user-context\": { \"version\": 1 },\n" + " \"user-context\": { \"one\": \"only\" },\n" + " \"http-port\": 9000 }}\n", + ParserContext::PARSER_AGENT, + ":3.3-16: duplicate user-context entries " + "(previous at :2:19)"); + + testError("{ \"Control-agent\":{\n" + " \"user-context\": { \"comment\": \"indirect\" },\n" + " \"comment\": \"a comment\",\n" + " \"http-port\": 9000 }}\n", + ParserContext::PARSER_AGENT, + ":3.3-11: duplicate user-context/comment entries " + "(previous at :2:19)"); } // Check unicode escapes diff --git a/src/bin/d2/tests/parser_unittest.cc b/src/bin/d2/tests/parser_unittest.cc index 44198359c5..9ecd663451 100644 --- a/src/bin/d2/tests/parser_unittest.cc +++ b/src/bin/d2/tests/parser_unittest.cc @@ -188,73 +188,89 @@ TEST(ParserTest, Logging) { // 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); } @@ -551,6 +567,45 @@ TEST(ParserTest, errors) { D2ParserContext::PARSER_DHCPDDNS, ":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, + ":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, + ":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, + ":3.3-11: duplicate user-context/comment entries " + "(previous at :2:3)"); + + testError("{ \"DhcpDdns\":{\n" + " \"user-context\": { \"version\": 1 },\n" + " \"user-context\": { \"one\": \"only\" },\n" + " \"dns-server-timeout\": 1000 }}\n", + D2ParserContext::PARSER_DHCPDDNS, + ":3.3-16: duplicate user-context entries " + "(previous at :2:19)"); + + testError("{ \"DhcpDdns\":{\n" + " \"user-context\": { \"comment\": \"indirect\" },\n" + " \"comment\": \"a comment\",\n" + " \"dns-server-timeout\": 1000 }}\n", + D2ParserContext::PARSER_DHCPDDNS, + ":3.3-11: duplicate user-context/comment entries " + "(previous at :2:19)"); } // Check unicode escapes diff --git a/src/bin/dhcp4/tests/parser_unittest.cc b/src/bin/dhcp4/tests/parser_unittest.cc index d909e533e8..b3c822e24a 100644 --- a/src/bin/dhcp4/tests/parser_unittest.cc +++ b/src/bin/dhcp4/tests/parser_unittest.cc @@ -1,4 +1,4 @@ -// 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 @@ -200,6 +200,24 @@ TEST(ParserTest, multilineComments) { 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 /// @@ -532,6 +550,45 @@ TEST(ParserTest, errors) { Parser4Context::PARSER_OPTION_DEF, "missing parameter 'type' (:1:1) " "[option-def map between :1:1 and :2:15]"); + + // user context and embedded comments + testError("{ \"Dhcp4\":{\n" + " \"comment\": true,\n" + " \"valid-lifetime\": 600 }}\n", + Parser4Context::PARSER_DHCP4, + ":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, + ":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, + ":3.3-11: duplicate user-context/comment entries " + "(previous at :2:3)"); + + testError("{ \"Dhcp4\":{\n" + " \"user-context\": { \"version\": 1 },\n" + " \"user-context\": { \"one\": \"only\" },\n" + " \"valid-lifetime\": 600 }}\n", + Parser4Context::PARSER_DHCP4, + ":3.3-16: duplicate user-context entries " + "(previous at :2:19)"); + + testError("{ \"Dhcp4\":{\n" + " \"user-context\": { \"comment\": \"indirect\" },\n" + " \"comment\": \"a comment\",\n" + " \"valid-lifetime\": 600 }}\n", + Parser4Context::PARSER_DHCP4, + ":3.3-11: duplicate user-context/comment entries " + "(previous at :2:19)"); } // Check unicode escapes diff --git a/src/bin/dhcp6/tests/parser_unittest.cc b/src/bin/dhcp6/tests/parser_unittest.cc index 64e3fdc419..9a88454206 100644 --- a/src/bin/dhcp6/tests/parser_unittest.cc +++ b/src/bin/dhcp6/tests/parser_unittest.cc @@ -1,4 +1,4 @@ -// 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 @@ -204,6 +204,26 @@ TEST(ParserTest, multilineComments) { 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 @@ -521,6 +541,45 @@ TEST(ParserTest, errors) { Parser6Context::PARSER_OPTION_DEF, "missing parameter 'type' (:1:1) " "[option-def map between :1:1 and :2:15]"); + + // user context and embedded comments + testError("{ \"Dhcp6\":{\n" + " \"comment\": true,\n" + " \"preferred-lifetime\": 600 }}\n", + Parser6Context::PARSER_DHCP6, + ":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, + ":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, + ":3.3-11: duplicate user-context/comment entries " + "(previous at :2:3)"); + + testError("{ \"Dhcp6\":{\n" + " \"user-context\": { \"version\": 1 },\n" + " \"user-context\": { \"one\": \"only\" },\n" + " \"preferred-lifetime\": 600 }}\n", + Parser6Context::PARSER_DHCP6, + ":3.3-16: duplicate user-context entries " + "(previous at :2:19)"); + + testError("{ \"Dhcp6\":{\n" + " \"user-context\": { \"comment\": \"indirect\" },\n" + " \"comment\": \"a comment\",\n" + " \"preferred-lifetime\": 600 }}\n", + Parser6Context::PARSER_DHCP6, + ":3.3-11: duplicate user-context/comment entries " + "(previous at :2:19)"); } // Check unicode escapes