]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5351] Regen tests
authorFrancis Dupont <fdupont@isc.org>
Wed, 29 Nov 2017 15:14:22 +0000 (16:14 +0100)
committerFrancis Dupont <fdupont@isc.org>
Wed, 29 Nov 2017 15:14:22 +0000 (16:14 +0100)
src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp4/tests/get_config_unittest.cc
src/bin/dhcp4/tests/get_config_unittest.cc.skel
src/bin/dhcp6/tests/config_parser_unittest.cc
src/bin/dhcp6/tests/get_config_unittest.cc
src/bin/dhcp6/tests/get_config_unittest.cc.skel
src/lib/testutils/user_context_utils.cc
src/lib/testutils/user_context_utils.h

index 0afa9b0b7a695ff8482fcbf3c74cd15abe4152c5..22f37795c470590544fdbe620ab10ca0a5aeb67d 100644 (file)
@@ -5625,11 +5625,28 @@ TEST_F(Dhcp4ParserTest, comments) {
         "    \"data\": \"ABCDEF0105\",\n"
         "    \"csv-format\": false\n"
         " } ],\n"
-        "\"client-classes\": [ {\n"
-        "    \"name\": \"all\",\n"
-        "    \"comment\": \"match all\",\n"
-        "    \"test\": \"'' == ''\"\n"
-        " } ],\n"
+        "\"client-classes\": [\n"
+        "    {\n"
+        "       \"name\": \"all\",\n"
+        "       \"comment\": \"match all\",\n"
+        "       \"test\": \"'' == ''\"\n"
+        "    },\n"
+        "    {\n"
+        "       \"name\": \"none\"\n"
+        "    },\n"
+        "    {\n"
+        "       \"name\": \"two\",\n"
+        "       \"comment\": \"first comment\",\n"
+        "       \"comment\": \"second comment\"\n"
+        "    },\n"
+        "    {\n"
+        "       \"name\": \"both\",\n"
+        "       \"comment\": \"a comment\",\n"
+        "       \"user-context\": {\n"
+        "           \"version\": 1\n"
+        "       }\n"
+        "    }\n"
+        "    ],\n"
         "\"shared-networks\": [ {\n"
         "    \"name\": \"foo\"\n,"
         "    \"comment\": \"A shared network\"\n,"
@@ -5688,11 +5705,11 @@ TEST_F(Dhcp4ParserTest, comments) {
     ASSERT_TRUE(ctx_opt_desc->get("comment"));
     EXPECT_EQ("\"Set option value\"", ctx_opt_desc->get("comment")->str());
 
-    // And there is a client class.
+    // And there are some client classes.
     ClientClassDictionaryPtr dict =
         CfgMgr::instance().getStagingCfg()->getClientClassDictionary();
     ASSERT_TRUE(dict);
-    EXPECT_EQ(1, dict->getClasses()->size());
+    EXPECT_EQ(4, dict->getClasses()->size());
     ClientClassDefPtr cclass = dict->findClass("all");
     ASSERT_TRUE(cclass);
     EXPECT_EQ("all", cclass->getName());
@@ -5705,6 +5722,36 @@ TEST_F(Dhcp4ParserTest, comments) {
     ASSERT_TRUE(ctx_class->get("comment"));
     EXPECT_EQ("\"match all\"", ctx_class->get("comment")->str());
 
+    // The 'none' class has no user-context/comment.
+    cclass = dict->findClass("none");
+    ASSERT_TRUE(cclass);
+    EXPECT_EQ("none", cclass->getName());
+    EXPECT_EQ("", cclass->getTest());
+    EXPECT_FALSE(cclass->getContext());
+
+    // The 'two' class has two comments.
+    cclass = dict->findClass("two");
+    EXPECT_EQ("two", cclass->getName());
+    EXPECT_EQ("", cclass->getTest());
+    ctx_class = cclass->getContext();
+    ASSERT_TRUE(ctx_class);
+    ASSERT_EQ(1, ctx_class->size());
+    ASSERT_TRUE(ctx_class->get("comment"));
+    ASSERT_EQ(Element::list, cclass->getContext()->get("comment")->getType());
+    ASSERT_EQ(2, cclass->getContext()->get("comment")->size());
+
+    // The 'both' class has a user context and a comment.
+    cclass = dict->findClass("both");
+    EXPECT_EQ("both", cclass->getName());
+    EXPECT_EQ("", cclass->getTest());
+    ctx_class = cclass->getContext();
+    ASSERT_TRUE(ctx_class);
+    ASSERT_EQ(2, ctx_class->size());
+    ASSERT_TRUE(ctx_class->get("comment"));
+    EXPECT_EQ("\"a comment\"", ctx_class->get("comment")->str());
+    ASSERT_TRUE(ctx_class->get("version"));
+    EXPECT_EQ("1", ctx_class->get("version")->str());
+
     // Now verify that the shared network was indeed configured.
     CfgSharedNetworks4Ptr cfg_net = CfgMgr::instance().getStagingCfg()
         ->getCfgSharedNetworks4();
index c457e98b8d9359ffd8c2a049e4c3b0f91828e71b..790fbc261eef40306bacd85602b955bc503e3010 100644 (file)
@@ -10,6 +10,7 @@
 #include <cc/data.h>
 #include <cc/simple_parser.h>
 #include <cc/cfg_to_element.h>
+#include <testutils/user_context_utils.h>
 #include <dhcp/tests/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcp4/tests/dhcp4_test_utils.h>
@@ -30,6 +31,7 @@ using namespace isc::config;
 using namespace isc::data;
 using namespace isc::dhcp;
 using namespace isc::dhcp::test;
+using namespace isc::test;
 
 namespace {
 
@@ -68,7 +70,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 0
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -78,7 +81,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 1
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"subnet4\": [\n"
@@ -96,7 +100,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 2
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"renew-timer\": 1000,\n"
 "        \"subnet4\": [\n"
@@ -114,7 +119,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 3
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -133,7 +139,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 4
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -177,7 +184,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 5
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -225,7 +233,8 @@ const char* EXTRACTED_CONFIGS[] = {
 "{\n"
 "        \"boot-file-name\": \"bar\",\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"next-server\": \"1.2.3.4\",\n"
 "        \"rebind-timer\": 2000,\n"
@@ -246,7 +255,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 7
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -269,7 +279,8 @@ const char* EXTRACTED_CONFIGS[] = {
 "{\n"
 "        \"boot-file-name\": \"nofile\",\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"next-server\": \"192.0.0.1\",\n"
 "        \"rebind-timer\": 2000,\n"
@@ -294,7 +305,8 @@ const char* EXTRACTED_CONFIGS[] = {
 "{\n"
 "        \"echo-client-id\": false,\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -314,7 +326,8 @@ const char* EXTRACTED_CONFIGS[] = {
 "{\n"
 "        \"echo-client-id\": true,\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -333,7 +346,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 11
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -362,7 +376,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 12
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"match-client-id\": true,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -391,7 +406,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 13
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -413,7 +429,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 14
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -446,7 +463,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 15
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -551,7 +569,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 23
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"option-data\": [\n"
 "            {\n"
@@ -582,7 +601,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 24
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -613,7 +633,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 25
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"option-data\": [\n"
 "            {\n"
@@ -652,7 +673,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 26
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"option-data\": [\n"
 "            {\n"
@@ -687,7 +709,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 27
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"option-data\": [\n"
 "            {\n"
@@ -743,7 +766,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 28
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"option-data\": [\n"
 "            {\n"
@@ -781,7 +805,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 29
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -822,7 +847,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 30
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -853,7 +879,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 31
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -889,7 +916,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 32
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"option-data\": [\n"
 "            {\n"
@@ -918,7 +946,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 33
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"option-data\": [\n"
 "            {\n"
@@ -953,7 +982,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 34
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"option-data\": [\n"
 "            {\n"
@@ -1004,7 +1034,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 35
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"option-data\": [\n"
 "            {\n"
@@ -1039,7 +1070,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 36
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"option-data\": [\n"
 "            {\n"
@@ -1074,7 +1106,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 37
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"eth0\", \"eth1\" ]\n"
+"            \"interfaces\": [ \"eth0\", \"eth1\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -1083,7 +1116,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 38
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"eth0\", \"*\", \"eth1\" ]\n"
+"            \"interfaces\": [ \"eth0\", \"*\", \"eth1\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -1108,7 +1142,8 @@ const char* EXTRACTED_CONFIGS[] = {
 "            \"server-port\": 777\n"
 "        },\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -1127,7 +1162,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 40
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -1152,7 +1188,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 41
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -1250,7 +1287,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 42
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"option-def\": [\n"
 "            {\n"
@@ -1334,14 +1372,16 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 44
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"subnet4\": [ ]\n"
 "    }\n",
     // CONFIGURATION 45
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"subnet4\": [ ]\n"
 "    }\n",
@@ -1349,7 +1389,8 @@ const char* EXTRACTED_CONFIGS[] = {
 "{\n"
 "        \"decline-probation-period\": 12345,\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"subnet4\": [ ]\n"
 "    }\n",
@@ -1364,14 +1405,16 @@ const char* EXTRACTED_CONFIGS[] = {
 "            \"unwarned-reclaim-cycles\": 10\n"
 "        },\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"subnet4\": [ ]\n"
 "    }\n",
     // CONFIGURATION 48
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -1390,7 +1433,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 49
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -1410,7 +1454,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 50
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -1430,7 +1475,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 51
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -1451,7 +1497,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 52
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -1482,7 +1529,8 @@ const char* EXTRACTED_CONFIGS[] = {
 "            }\n"
 "        ],\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -1501,7 +1549,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 54
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -1520,7 +1569,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 55
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -1540,7 +1590,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 56
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -1564,7 +1615,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 57
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"rebind-timer\": 2000,\n"
 "        \"renew-timer\": 1000,\n"
@@ -1593,6 +1645,20 @@ const char* EXTRACTED_CONFIGS[] = {
 "                \"comment\": \"match all\",\n"
 "                \"name\": \"all\",\n"
 "                \"test\": \"'' == ''\"\n"
+"            },\n"
+"            {\n"
+"                \"name\": \"none\"\n"
+"            },\n"
+"            {\n"
+"                \"comment\": [ \"first comment\", \"second comment\" ],\n"
+"                \"name\": \"two\"\n"
+"            },\n"
+"            {\n"
+"                \"comment\": \"a comment\",\n"
+"                \"name\": \"both\",\n"
+"                \"user-context\": {\n"
+"                    \"version\": 1\n"
+"                }\n"
 "            }\n"
 "        ],\n"
 "        \"option-data\": [\n"
@@ -6287,6 +6353,35 @@ const char* UNPARSED_CONFIGS[] = {
 "                \"option-def\": [ ],\n"
 "                \"server-hostname\": \"\",\n"
 "                \"test\": \"'' == ''\"\n"
+"            },\n"
+"            {\n"
+"                \"comment\": \"a comment\",\n"
+"                \"boot-file-name\": \"\",\n"
+"                \"name\": \"both\",\n"
+"                \"next-server\": \"0.0.0.0\",\n"
+"                \"option-data\": [ ],\n"
+"                \"option-def\": [ ],\n"
+"                \"server-hostname\": \"\",\n"
+"                \"user-context\": {\n"
+"                    \"version\": 1\n"
+"                }\n"
+"            },\n"
+"            {\n"
+"                \"boot-file-name\": \"\",\n"
+"                \"name\": \"none\",\n"
+"                \"next-server\": \"0.0.0.0\",\n"
+"                \"option-data\": [ ],\n"
+"                \"option-def\": [ ],\n"
+"                \"server-hostname\": \"\"\n"
+"            },\n"
+"            {\n"
+"                \"comment\": [ \"first comment\", \"second comment\" ],\n"
+"                \"boot-file-name\": \"\",\n"
+"                \"name\": \"two\",\n"
+"                \"next-server\": \"0.0.0.0\",\n"
+"                \"option-data\": [ ],\n"
+"                \"option-def\": [ ],\n"
+"                \"server-hostname\": \"\"\n"
 "            }\n"
 "        ],\n"
 "        \"decline-probation-period\": 86400,\n"
@@ -6424,7 +6519,7 @@ static_assert(max_config_counter == sizeof(UNPARSED_CONFIGS) / sizeof(char*),
 void
 outputFormatted(const std::string& config) {
     // pretty print it
-    ConstElementPtr json = parseJSON(config);
+    ConstElementPtr json = extractComments(parseDHCP4(config));
     std::string prettier = prettyPrint(json, 4, 4);
     // get it as a line array
     std::list<std::string> lines;
@@ -6638,10 +6733,12 @@ TEST_P(Dhcp4GetConfigTest, run) {
         ASSERT_NO_THROW(outputFormatted(dhcp->str()));
     } else {
         expected = UNPARSED_CONFIGS[config_counter];
-        ConstElementPtr json;
-        ASSERT_NO_THROW(json = parseDHCP4(expected, true));
-        ASSERT_NO_THROW(json = parseJSON(expected));
-        EXPECT_TRUE(isEquivalent(dhcp, json));
+        ElementPtr jsond;
+        ASSERT_NO_THROW(jsond = parseDHCP4(expected, true));
+        ElementPtr jsonj;
+        ASSERT_NO_THROW(jsonj = parseJSON(expected));
+        EXPECT_TRUE(isEquivalent(dhcp, jsonj));
+        EXPECT_TRUE(isEquivalent(jsond, moveComments(jsonj)));
         std::string current = prettyPrint(dhcp, 4, 4) + "\n";
         EXPECT_EQ(expected, current);
         if (expected != current) {
index 68d8f165d70c2e1912a058a5e5dd680dad4b0955..f5bec0e103d64a503e37da7a465c6107376b17f2 100644 (file)
@@ -10,6 +10,7 @@
 #include <cc/data.h>
 #include <cc/simple_parser.h>
 #include <cc/cfg_to_element.h>
+#include <testutils/user_context_utils.h>
 #include <dhcp/tests/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcp4/tests/dhcp4_test_utils.h>
@@ -30,6 +31,7 @@ using namespace isc::config;
 using namespace isc::data;
 using namespace isc::dhcp;
 using namespace isc::dhcp::test;
+using namespace isc::test;
 
 namespace {
 
@@ -101,7 +103,7 @@ static_assert(max_config_counter == sizeof(UNPARSED_CONFIGS) / sizeof(char*),
 void
 outputFormatted(const std::string& config) {
     // pretty print it
-    ConstElementPtr json = parseJSON(config);
+    ConstElementPtr json = extractComments(parseDHCP4(config));
     std::string prettier = prettyPrint(json, 4, 4);
     // get it as a line array
     std::list<std::string> lines;
@@ -315,10 +317,12 @@ TEST_P(Dhcp4GetConfigTest, run) {
         ASSERT_NO_THROW(outputFormatted(dhcp->str()));
     } else {
         expected = UNPARSED_CONFIGS[config_counter];
-        ConstElementPtr json;
-        ASSERT_NO_THROW(json = parseDHCP4(expected, true));
-        ASSERT_NO_THROW(json = parseJSON(expected));
-        EXPECT_TRUE(isEquivalent(dhcp, json));
+        ElementPtr jsond;
+        ASSERT_NO_THROW(jsond = parseDHCP4(expected, true));
+        ElementPtr jsonj;
+        ASSERT_NO_THROW(jsonj = parseJSON(expected));
+        EXPECT_TRUE(isEquivalent(dhcp, jsonj));
+        EXPECT_TRUE(isEquivalent(jsond, moveComments(jsonj)));
         std::string current = prettyPrint(dhcp, 4, 4) + "\n";
         EXPECT_EQ(expected, current);
         if (expected != current) {
index 5962f0873ef7f94530c9f833788bf7c7cf889fad..ad0aab9de6f345b67b3fd80960152c440afef8eb 100644 (file)
@@ -6067,11 +6067,28 @@ TEST_F(Dhcp6ParserTest, comments) {
         "    \"data\": \"ABCDEF0105\",\n"
         "        \"csv-format\": false\n"
         " } ],\n"
-        "\"client-classes\": [ {\n"
-        "    \"name\": \"all\",\n"
-        "    \"comment\": \"match all\",\n"
-        "    \"test\": \"'' == ''\"\n"
-        " } ],\n"
+        "\"client-classes\": [\n"
+        "    {\n"
+        "       \"name\": \"all\",\n"
+        "       \"comment\": \"match all\",\n"
+        "       \"test\": \"'' == ''\"\n"
+        "    },\n"
+        "    {\n"
+        "       \"name\": \"none\"\n"
+        "    },\n"
+        "    {\n"
+        "       \"name\": \"two\",\n"
+        "       \"comment\": \"first comment\",\n"
+        "       \"comment\": \"second comment\"\n"
+        "    },\n"
+        "    {\n"
+        "       \"name\": \"both\",\n"
+        "       \"comment\": \"a comment\",\n"
+        "       \"user-context\": {\n"
+        "           \"version\": 1\n"
+        "       }\n"
+        "    }\n"
+        "    ],\n"
         "\"shared-networks\": [ {\n"
         "    \"name\": \"foo\"\n,"
         "    \"comment\": \"A shared network\"\n,"
@@ -6138,11 +6155,11 @@ TEST_F(Dhcp6ParserTest, comments) {
     ASSERT_TRUE(ctx_opt_desc->get("comment"));
     EXPECT_EQ("\"Set option value\"", ctx_opt_desc->get("comment")->str());
 
-    // And there is a client class.
+    // And there there are some client classes.
     ClientClassDictionaryPtr dict =
         CfgMgr::instance().getStagingCfg()->getClientClassDictionary();
     ASSERT_TRUE(dict);
-    EXPECT_EQ(1, dict->getClasses()->size());
+    EXPECT_EQ(4, dict->getClasses()->size());
     ClientClassDefPtr cclass = dict->findClass("all");
     ASSERT_TRUE(cclass);
     EXPECT_EQ("all", cclass->getName());
@@ -6155,6 +6172,36 @@ TEST_F(Dhcp6ParserTest, comments) {
     ASSERT_TRUE(ctx_class->get("comment"));
     EXPECT_EQ("\"match all\"", ctx_class->get("comment")->str());
 
+    // The 'none' class has no user-context/comment.
+    cclass = dict->findClass("none");
+    ASSERT_TRUE(cclass);
+    EXPECT_EQ("none", cclass->getName());
+    EXPECT_EQ("", cclass->getTest());
+    EXPECT_FALSE(cclass->getContext());
+
+    // The 'two' class has two comments.
+    cclass = dict->findClass("two");
+    EXPECT_EQ("two", cclass->getName());
+    EXPECT_EQ("", cclass->getTest());
+    ctx_class = cclass->getContext();
+    ASSERT_TRUE(ctx_class);
+    ASSERT_EQ(1, ctx_class->size());
+    ASSERT_TRUE(ctx_class->get("comment"));
+    ASSERT_EQ(Element::list, cclass->getContext()->get("comment")->getType());
+    ASSERT_EQ(2, cclass->getContext()->get("comment")->size());
+
+    // The 'both' class has a user context and a comment.
+    cclass = dict->findClass("both");
+    EXPECT_EQ("both", cclass->getName());
+    EXPECT_EQ("", cclass->getTest());
+    ctx_class = cclass->getContext();
+    ASSERT_TRUE(ctx_class);
+    ASSERT_EQ(2, ctx_class->size());
+    ASSERT_TRUE(ctx_class->get("comment"));
+    EXPECT_EQ("\"a comment\"", ctx_class->get("comment")->str());
+    ASSERT_TRUE(ctx_class->get("version"));
+    EXPECT_EQ("1", ctx_class->get("version")->str());
+
     // Now verify that the shared network was indeed configured.
     CfgSharedNetworks6Ptr cfg_net = CfgMgr::instance().getStagingCfg()
         ->getCfgSharedNetworks6();
index 4ac8ae512c1422eea8e45f4b088f7531a73a26cb..5087aaa73e713d469b364392ff6e0d6025fd6d67 100644 (file)
@@ -10,6 +10,8 @@
 #include <cc/data.h>
 #include <cc/simple_parser.h>
 #include <cc/cfg_to_element.h>
+#include <testutils/user_context_utils.h>
+#include <testutils/user_context_utils.h>
 #include <dhcp/tests/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcp6/tests/dhcp6_test_utils.h>
@@ -30,6 +32,7 @@ using namespace isc::config;
 using namespace isc::data;
 using namespace isc::dhcp;
 using namespace isc::dhcp::test;
+using namespace isc::test;
 
 namespace {
 
@@ -68,7 +71,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 0
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -79,7 +83,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 1
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -99,7 +104,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 2
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -144,7 +150,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 3
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -192,7 +199,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 4
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -240,7 +248,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 5
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -264,7 +273,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 6
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -303,7 +313,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 8
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -337,7 +348,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 9
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -357,7 +369,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 10
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -379,7 +392,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 11
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -403,7 +417,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 12
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -440,7 +455,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 13
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -526,7 +542,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 19
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"option-data\": [\n"
 "            {\n"
@@ -557,7 +574,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 20
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -588,7 +606,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 21
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"option-data\": [\n"
 "            {\n"
@@ -628,7 +647,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 22
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"option-data\": [\n"
 "            {\n"
@@ -664,7 +684,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 23
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"option-data\": [\n"
 "            {\n"
@@ -721,7 +742,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 24
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -763,7 +785,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 25
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -826,7 +849,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 26
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"option-data\": [\n"
 "            {\n"
@@ -862,7 +886,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 27
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"option-data\": [\n"
 "            {\n"
@@ -898,7 +923,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 28
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"eth0\" ]\n"
+"            \"interfaces\": [ \"eth0\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -908,7 +934,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 29
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"eth0\", \"eth1\", \"*\" ]\n"
+"            \"interfaces\": [ \"eth0\", \"eth1\", \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -918,7 +945,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 30
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -941,7 +969,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 31
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -1004,7 +1033,8 @@ const char* EXTRACTED_CONFIGS[] = {
 "            \"server-port\": 777\n"
 "        },\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -1024,7 +1054,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 33
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -1110,7 +1141,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 34
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"option-def\": [\n"
 "            {\n"
@@ -1149,7 +1181,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 35
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"mac-sources\": [ \"rfc6939\", \"rfc4649\", \"rfc4580\" ],\n"
 "        \"preferred-lifetime\": 3000,\n"
@@ -1161,7 +1194,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 36
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"mac-sources\": [ \"client-link-addr-option\", \"remote-id\", \"subscriber-id\" ],\n"
 "        \"preferred-lifetime\": 3000,\n"
@@ -1217,7 +1251,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 38
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -1229,14 +1264,16 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 39
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"subnet6\": [ ]\n"
 "    }\n",
     // CONFIGURATION 40
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"subnet6\": [ ]\n"
 "    }\n",
@@ -1244,7 +1281,8 @@ const char* EXTRACTED_CONFIGS[] = {
 "{\n"
 "        \"decline-probation-period\": 12345,\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"subnet6\": [ ]\n"
 "    }\n",
@@ -1259,7 +1297,8 @@ const char* EXTRACTED_CONFIGS[] = {
 "            \"unwarned-reclaim-cycles\": 10\n"
 "        },\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"subnet6\": [ ]\n"
 "    }\n",
@@ -1277,7 +1316,8 @@ const char* EXTRACTED_CONFIGS[] = {
 "            }\n"
 "        ],\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -1297,7 +1337,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 44
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -1317,7 +1358,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 45
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -1338,7 +1380,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 46
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -1364,7 +1407,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 47
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -1390,7 +1434,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 48
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -1412,7 +1457,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 49
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -1435,7 +1481,8 @@ const char* EXTRACTED_CONFIGS[] = {
     // CONFIGURATION 50
 "{\n"
 "        \"interfaces-config\": {\n"
-"            \"interfaces\": [ \"*\" ]\n"
+"            \"interfaces\": [ \"*\" ],\n"
+"            \"re-detect\": false\n"
 "        },\n"
 "        \"preferred-lifetime\": 3000,\n"
 "        \"rebind-timer\": 2000,\n"
@@ -1468,6 +1515,20 @@ const char* EXTRACTED_CONFIGS[] = {
 "                \"comment\": \"match all\",\n"
 "                \"name\": \"all\",\n"
 "                \"test\": \"'' == ''\"\n"
+"            },\n"
+"            {\n"
+"                \"name\": \"none\"\n"
+"            },\n"
+"            {\n"
+"                \"comment\": [ \"first comment\", \"second comment\" ],\n"
+"                \"name\": \"two\"\n"
+"            },\n"
+"            {\n"
+"                \"comment\": \"a comment\",\n"
+"                \"name\": \"both\",\n"
+"                \"user-context\": {\n"
+"                    \"version\": 1\n"
+"                }\n"
 "            }\n"
 "        ],\n"
 "        \"option-data\": [\n"
@@ -5894,6 +5955,23 @@ const char* UNPARSED_CONFIGS[] = {
 "                \"name\": \"all\",\n"
 "                \"option-data\": [ ],\n"
 "                \"test\": \"'' == ''\"\n"
+"            },\n"
+"            {\n"
+"                \"comment\": \"a comment\",\n"
+"                \"name\": \"both\",\n"
+"                \"option-data\": [ ],\n"
+"                \"user-context\": {\n"
+"                    \"version\": 1\n"
+"                }\n"
+"            },\n"
+"            {\n"
+"                \"name\": \"none\",\n"
+"                \"option-data\": [ ]\n"
+"            },\n"
+"            {\n"
+"                \"comment\": [ \"first comment\", \"second comment\" ],\n"
+"                \"name\": \"two\",\n"
+"                \"option-data\": [ ]\n"
 "            }\n"
 "        ],\n"
 "        \"decline-probation-period\": 86400,\n"
@@ -6045,7 +6123,7 @@ static_assert(max_config_counter == sizeof(UNPARSED_CONFIGS) / sizeof(char*),
 void
 outputFormatted(const std::string& config) {
     // pretty print it
-    ConstElementPtr json = parseJSON(config);
+    ConstElementPtr json = extractComments(parseDHCP6(config));
     std::string prettier = prettyPrint(json, 4, 4);
     // get it as a line array
     std::list<std::string> lines;
@@ -6262,10 +6340,12 @@ TEST_P(Dhcp6GetConfigTest, run) {
         ASSERT_NO_THROW(outputFormatted(dhcp->str()));
     } else {
         expected = UNPARSED_CONFIGS[config_counter];
-        ConstElementPtr json;
-        ASSERT_NO_THROW(json = parseDHCP6(expected, true));
-        ASSERT_NO_THROW(json = parseJSON(expected));
-        EXPECT_TRUE(isEquivalent(dhcp, json));
+        ElementPtr jsond;
+        ASSERT_NO_THROW(jsond = parseDHCP6(expected, true));
+        ElementPtr jsonj;
+        ASSERT_NO_THROW(jsonj = parseJSON(expected));
+        EXPECT_TRUE(isEquivalent(dhcp, jsonj));
+        EXPECT_TRUE(isEquivalent(jsond, moveComments(jsonj)));
         std::string current = prettyPrint(dhcp, 4, 4) + "\n";
         EXPECT_EQ(expected, current);
         if (expected != current) {
index 9a5566e4d9a0b68a5d4d9031102899dc43840e83..efb2accc4eef3f28da70fa0e074e4ad1f253cc3c 100644 (file)
@@ -10,6 +10,8 @@
 #include <cc/data.h>
 #include <cc/simple_parser.h>
 #include <cc/cfg_to_element.h>
+#include <testutils/user_context_utils.h>
+#include <testutils/user_context_utils.h>
 #include <dhcp/tests/iface_mgr_test_config.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcp6/tests/dhcp6_test_utils.h>
@@ -30,6 +32,7 @@ using namespace isc::config;
 using namespace isc::data;
 using namespace isc::dhcp;
 using namespace isc::dhcp::test;
+using namespace isc::test;
 
 namespace {
 
@@ -101,7 +104,7 @@ static_assert(max_config_counter == sizeof(UNPARSED_CONFIGS) / sizeof(char*),
 void
 outputFormatted(const std::string& config) {
     // pretty print it
-    ConstElementPtr json = parseJSON(config);
+    ConstElementPtr json = extractComments(parseDHCP6(config));
     std::string prettier = prettyPrint(json, 4, 4);
     // get it as a line array
     std::list<std::string> lines;
@@ -318,10 +321,12 @@ TEST_P(Dhcp6GetConfigTest, run) {
         ASSERT_NO_THROW(outputFormatted(dhcp->str()));
     } else {
         expected = UNPARSED_CONFIGS[config_counter];
-        ConstElementPtr json;
-        ASSERT_NO_THROW(json = parseDHCP6(expected, true));
-        ASSERT_NO_THROW(json = parseJSON(expected));
-        EXPECT_TRUE(isEquivalent(dhcp, json));
+        ElementPtr jsond;
+        ASSERT_NO_THROW(jsond = parseDHCP6(expected, true));
+        ElementPtr jsonj;
+        ASSERT_NO_THROW(jsonj = parseJSON(expected));
+        EXPECT_TRUE(isEquivalent(dhcp, jsonj));
+        EXPECT_TRUE(isEquivalent(jsond, moveComments(jsonj)));
         std::string current = prettyPrint(dhcp, 4, 4) + "\n";
         EXPECT_EQ(expected, current);
         if (expected != current) {
index 511ae731616910caa06df4ad2570af41940ac8c2..fc01075cd755b57f96a9f32a203f1c878dc80fa9 100644 (file)
@@ -123,3 +123,115 @@ ElementPtr moveComments(ElementPtr element) {
 
 }; // end of isc::test namespace
 }; // end of isc namespace
+
+namespace {
+
+/// @brief Recursive helper
+///
+/// Instead of returning a unmodified copy a @ref UnModified exception
+/// is raised with the unmodified value
+///
+/// @tparam EP ElementPtr or ConstElementPtr (compiler will infer which one)
+/// @param element the element to traverse
+/// @return a modified copy where comment entries were moved to user-context
+/// @throw UnModified with the unmodified value
+template<typename EP>
+EP extractComments1(EP element) {
+    bool modified = false;
+
+    // On lists recurse on items
+    if (element->getType() == Element::list) {
+        ElementPtr result = ElementPtr(new ListElement());
+        typedef std::vector<ElementPtr> ListType;
+        const ListType& list = element->listValue();
+        for (ListType::const_iterator it = list.cbegin();
+             it != list.cend(); ++it) {
+            try {
+                result->add(extractComments1(*it));
+                modified = true;
+            }
+            catch (const UnModified<ElementPtr>& ex) {
+                result->add(ex.get());
+            }
+        }
+        if (!modified) {
+            throw UnModified<EP>(element);
+        }
+        return (result);
+    } else if (element->getType() != Element::map) {
+        throw UnModified<EP>(element);
+    }
+
+    // Process maps: recurse on items
+    ElementPtr result = ElementPtr(new MapElement());
+    bool has_comment = false;
+    typedef std::map<std::string, ConstElementPtr> map_type;
+    const map_type& map = element->mapValue();
+    for (map_type::const_iterator it = map.cbegin(); it != map.cend(); ++it) {
+        if (it->first == "comment") {
+            // Do not traverse comment entries
+            result->set("comment", it->second);
+        } else if (it->first == "user-context") {
+            if (it->second->contains("comment")) {
+                // Note there is a  entry to move
+                has_comment = true;
+            } else {
+                // Do not traverse user-context entries
+                result->set("user-context", it->second);
+            }
+        } else {
+            // Not comment or user-context
+            try {
+                result->set(it->first, extractComments1(it->second));
+                modified = true;
+            }
+            catch (const UnModified<ConstElementPtr>& ex) {
+                result->set(it->first, ex.get());
+            }
+        }
+    }
+    // Check if the value should be not modified
+    if (!has_comment && !modified) {
+        throw UnModified<EP>(element);
+    }
+
+    if (has_comment) {
+        // Move the comment entry
+        const map_type& uc_map = element->get("user-context")->mapValue();
+        ElementPtr user_context = Element::createMap();
+        ConstElementPtr comment;
+        for (map_type::const_iterator it = uc_map.cbegin();
+             it != uc_map.cend(); ++it) {
+            if  (it->first == "comment") {
+                comment = it->second;
+            } else {
+                user_context->set(it->first, it->second);
+            }
+        }
+        if (user_context->size() > 0) {
+            result->set("user-context", user_context);
+        }
+        result->combine_set("comment", comment);
+    }
+
+    return (result);
+}
+
+} // anonymous namespace
+
+namespace isc {
+namespace test {
+
+ElementPtr extractComments(ElementPtr element) {
+    ElementPtr result;
+    try {
+        result = extractComments1(element);
+    }
+    catch (const UnModified<ElementPtr>& ex) {
+        result = ex.get();
+    }
+    return result;
+}
+
+}; // end of isc::test namespace
+}; // end of isc namespace
index 417fdc6290ec7b857f360437f72b55d3bbfb8386..c815ce578c8f70653f458463699340f965600393 100644 (file)
@@ -18,6 +18,12 @@ namespace test {
 /// @return a processed copy of element or unmodified element
 isc::data::ElementPtr moveComments(isc::data::ElementPtr element);
 
+/// @brief Extract comment entries from user-context
+///
+/// @param element
+/// @return a processed copy of element or unmodified element
+ isc::data::ElementPtr extractComments(isc::data::ElementPtr element);
+
 }; // end of isc::test namespace
 }; // end of isc namespace