]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5108] Addressed review comments.
authorMarcin Siodelski <marcin@isc.org>
Thu, 13 Jul 2017 13:48:39 +0000 (15:48 +0200)
committerMarcin Siodelski <marcin@isc.org>
Thu, 13 Jul 2017 13:48:39 +0000 (15:48 +0200)
Added unit tests that check that configuration of various servers can
coexist.

src/bin/agent/tests/parser_unittests.cc
src/bin/d2/tests/parser_unittest.cc
src/bin/dhcp4/tests/kea_controller_unittest.cc
src/bin/dhcp6/tests/kea_controller_unittest.cc

index 07d3a563300075510ee03df15c82c5f7a623d444..c651eaab6e640761911d18a8b6a6d77c16eeb28c 100644 (file)
@@ -117,6 +117,54 @@ TEST(ParserTest, keywordJSON) {
     testParser(txt, ParserContext::PARSER_JSON);
 }
 
+// This test checks that the DhcpDdns configuration is accepted
+// by the parser.
+TEST(ParserTest, keywordDhcpDdns) {
+    string txt =
+        "{ \"DhcpDdns\" : \n"
+           "{ \n"
+            " \"ip-address\": \"192.168.77.1\", \n"
+            " \"port\": 777 , \n "
+            " \"ncr-protocol\": \"UDP\", \n"
+            "\"tsig-keys\": [], \n"
+            "\"forward-ddns\" : {}, \n"
+            "\"reverse-ddns\" : {} \n"
+            "} \n"
+         "} \n";
+     testParser(txt, ParserContext::PARSER_AGENT);
+}
+
+// This test checks that the Dhcp6 configuration is accepted
+// by the parser.
+TEST(ParserTest, keywordDhcp6) {
+     string txt = "{ \"Dhcp6\": { \"interfaces-config\": {"
+                  " \"interfaces\": [ \"type\", \"htype\" ] },\n"
+                  "\"preferred-lifetime\": 3000,\n"
+                  "\"rebind-timer\": 2000, \n"
+                  "\"renew-timer\": 1000, \n"
+                  "\"subnet6\": [ { "
+                  "    \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
+                  "    \"subnet\": \"2001:db8:1::/48\", "
+                  "    \"interface\": \"test\" } ],\n"
+                   "\"valid-lifetime\": 4000 } }";
+     testParser(txt, ParserContext::PARSER_AGENT);
+}
+
+// This test checks that the Dhcp4 configuration is accepted
+// by the parser.
+TEST(ParserTest, keywordDhcp4) {
+    string txt = "{ \"Dhcp4\": { \"interfaces-config\": {"
+                  " \"interfaces\": [ \"type\", \"htype\" ] },\n"
+                  "\"rebind-timer\": 2000, \n"
+                  "\"renew-timer\": 1000, \n"
+                  "\"subnet4\": [ { "
+                  "  \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ],"
+                  "  \"subnet\": \"192.0.2.0/24\", "
+                  "  \"interface\": \"test\" } ],\n"
+                   "\"valid-lifetime\": 4000 } }";
+     testParser(txt, ParserContext::PARSER_AGENT);
+}
+
 // This test checks if full config (with top level and Control-agent objects) can
 // be parsed with syntactic checking (and as pure JSON).
 TEST(ParserTest, keywordAgent) {
index 285981d50977dbbacc363030d7e648c904de9f22..0a23f0db7be8d4b1ea45a6e065101ac8ce90a67e 100644 (file)
@@ -159,6 +159,11 @@ TEST(ParserTest, keywordDhcp4) {
      testParser(txt, D2ParserContext::PARSER_DHCPDDNS);
 }
 
+TEST(ParserTest, keywordControlAgent) {
+    string txt = "{ \"Control-agent\": { } }";
+    testParser(txt, D2ParserContext::PARSER_DHCPDDNS);
+}
+
 TEST(ParserTest, Logging) {
     string txt = "{ \"Logging\": { \n"
                  "    \"loggers\": [ \n"
index ccd444a91255cc666a4cb7945b307b53aedc92e0..88a24f7a567e857bf91b3e93ff3096c6cb62e84a 100644 (file)
@@ -183,6 +183,31 @@ TEST_F(JSONFileBackendTest, jsonFile) {
     EXPECT_EQ(Lease::TYPE_V4, pools3.at(0)->getType());
 }
 
+// This test verifies that the configurations for various servers
+// can coexist and that the DHCPv4 configuration parsers will simply
+// ignore them.
+TEST_F(JSONFileBackendTest, serverConfigurationsCoexistence) {
+    std::string config = "{ \"Dhcp4\": {"
+        "\"rebind-timer\": 2000, "
+        "\"renew-timer\": 1000, \n"
+        "\"valid-lifetime\": 4000 }, "
+        "\"Dhcp6\": { },"
+        "\"DhcpDdns\": { },"
+        "\"Control-agent\": { }"
+        "}";
+
+    writeFile(TEST_FILE, config);
+
+    // Now initialize the server
+    boost::scoped_ptr<ControlledDhcpv4Srv> srv;
+    ASSERT_NO_THROW(
+        srv.reset(new ControlledDhcpv4Srv(0))
+    );
+
+    // And configure it using the config file.
+    EXPECT_NO_THROW(srv->init(TEST_FILE));
+}
+
 // This test checks if configuration can be read from a JSON file
 // using hash (#) line comments
 TEST_F(JSONFileBackendTest, hashComments) {
index 5ed89fbee13c13202039d885561924ec927f11b0..9856f5da11ebdd8e0858ae33e695c24a8fd446d6 100644 (file)
@@ -169,6 +169,32 @@ TEST_F(JSONFileBackendTest, jsonFile) {
     EXPECT_EQ(Lease::TYPE_NA, pools3.at(0)->getType());
 }
 
+// This test verifies that the configurations for various servers
+// can coexist and that the DHCPv6 configuration parsers will simply
+// ignore them.
+TEST_F(JSONFileBackendTest, serverConfigurationsCoexistence) {
+    std::string config = "{ \"Dhcp6\": {"
+        "\"rebind-timer\": 2000, "
+        "\"renew-timer\": 1000, \n"
+        "\"preferred-lifetime\": 1000, \n"
+        "\"valid-lifetime\": 4000 }, "
+        "\"Dhcp4\": { },"
+        "\"DhcpDdns\": { },"
+        "\"Control-agent\": { }"
+        "}";
+
+    writeFile(TEST_FILE, config);
+
+    // Now initialize the server
+    boost::scoped_ptr<ControlledDhcpv6Srv> srv;
+    ASSERT_NO_THROW(
+        srv.reset(new ControlledDhcpv6Srv(0))
+    );
+
+    // And configure it using the config file.
+    EXPECT_NO_THROW(srv->init(TEST_FILE));
+}
+
 // This test checks if configuration can be read from a JSON file
 // using hash (#) line comments
 TEST_F(JSONFileBackendTest, hashComments) {