]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3477] Making socket name/address exclusive (2)
authorFrancis Dupont <fdupont@isc.org>
Tue, 23 Jul 2024 14:32:08 +0000 (16:32 +0200)
committerFrancis Dupont <fdupont@isc.org>
Thu, 1 Aug 2024 07:23:54 +0000 (09:23 +0200)
src/bin/d2/tests/d2_http_command_unittest.cc
src/bin/d2/tests/parser_unittest.cc
src/bin/dhcp4/tests/parser_unittest.cc
src/bin/dhcp6/tests/parser_unittest.cc

index d822cdf5f4d8d72578e730e7e0f8ca7613a92071..f1ec524f5699e075271b81c112673ffcf939879c 100644 (file)
@@ -258,8 +258,8 @@ public:
     ///        placed.
     void sendHttpCommand(const string& command, string& response) {
         response = "";
-       IOServicePtr io_service = getIOService();
-       ASSERT_TRUE(io_service);
+        IOServicePtr io_service = getIOService();
+        ASSERT_TRUE(io_service);
         boost::scoped_ptr<TestHttpClient> client;
         client.reset(new TestHttpClient(io_service, SERVER_ADDRESS,
                                         SERVER_PORT));
index 2ab573119aa53f2a6cb41795de29576634a065dc..f1ee4a172a30738aa10e7ecda391da188d92e3cf 100644 (file)
@@ -899,6 +899,52 @@ TEST_F(TrailingCommasTest, tests) {
     testParser(txt, D2ParserContext::PARSER_DHCPDDNS, false);
 }
 
+/// @brief Tests control socket config conflicts.
+TEST(ParserTest, duplicateControlSocket) {
+    // Valid configuration.
+    string txt(R"({
+    "DhcpDdns": {
+        "control-socket": {
+            "socket-type": "http",
+            "socket-address": "127.0.0.1"
+        }
+     }
+})");
+    testParser(txt, D2ParserContext::PARSER_DHCPDDNS, false);
+
+    // Invalid configuration: both map and list.
+    string bad1(R"({
+    "DhcpDdns": {
+        "control-socket": {
+            "socket-type": "http",
+            "socket-address": "127.0.0.1"
+        },
+        "control-sockets": [ ]
+     }
+})");
+
+    ASSERT_NO_THROW(Element::fromJSON(bad1, true));
+    D2ParserContext ctx1;
+    EXPECT_THROW(ctx1.parseString(bad1, D2ParserContext::PARSER_DHCPDDNS),
+                 D2ParseError);
+
+    // Invalid configuration: both name and address.
+    string bad2(R"({
+    "DhcpDdns": {
+        "control-socket": {
+            "socket-type": "http",
+            "socket-address": "127.0.0.1",
+            "socket-name": "::1"
+        }
+     }
+})");
+
+    ASSERT_NO_THROW(Element::fromJSON(bad1, true));
+    D2ParserContext ctx2;
+    EXPECT_THROW(ctx2.parseString(bad2, D2ParserContext::PARSER_DHCPDDNS),
+                 D2ParseError);
+}
+
 }  // namespace test
 }  // namespace d2
 }  // namespace isc
index bc21c35095068c96cb935b99828159f7410f66bf..266ee8a6b5f7e6db060513734f685570997dd1c4 100644 (file)
@@ -1007,6 +1007,52 @@ TEST_F(TrailingCommasTest, tests) {
     testParser(txt, Parser4Context::PARSER_DHCP4, false);
 }
 
+/// @brief Tests control socket config conflicts.
+TEST(ParserTest, duplicateControlSocket) {
+    // Valid configuration.
+    string txt(R"({
+    "Dhcp4": {
+        "control-socket": {
+            "socket-type": "http",
+            "socket-address": "127.0.0.1"
+        }
+     }
+})");
+    testParser(txt, Parser4Context::PARSER_DHCP4, false);
+
+    // Invalid configuration: both map and list.
+    string bad1(R"({
+    "Dhcp4": {
+        "control-socket": {
+            "socket-type": "http",
+            "socket-address": "127.0.0.1"
+        },
+        "control-sockets": [ ]
+     }
+})");
+
+    ASSERT_NO_THROW(Element::fromJSON(bad1, true));
+    Parser4Context ctx1;
+    EXPECT_THROW(ctx1.parseString(bad1, Parser4Context::PARSER_DHCP4),
+                 Dhcp4ParseError);
+
+    // Invalid configuration: both name and address.
+    string bad2(R"({
+    "Dhcp4": {
+        "control-socket": {
+            "socket-type": "http",
+            "socket-address": "127.0.0.1",
+            "socket-name": "::1"
+        }
+     }
+})");
+
+    ASSERT_NO_THROW(Element::fromJSON(bad1, true));
+    Parser4Context ctx2;
+    EXPECT_THROW(ctx2.parseString(bad2, Parser4Context::PARSER_DHCP4),
+                 Dhcp4ParseError);
+}
+
 }  // namespace test
 }  // namespace dhcp
 }  // namespace isc
index 5ff99d3d793db065a74cdeda1876b0a8af24ec30..f84f65cdcbf72ea9da81af2a3babe636672a5e5e 100644 (file)
@@ -998,6 +998,52 @@ TEST_F(TrailingCommasTest, tests) {
     testParser(txt, Parser6Context::PARSER_DHCP6, false);
 }
 
+/// @brief Tests control socket config conflicts.
+TEST(ParserTest, duplicateControlSocket) {
+    // Valid configuration.
+    string txt(R"({
+    "Dhcp6": {
+        "control-socket": {
+            "socket-type": "http",
+            "socket-address": "::1"
+        }
+     }
+})");
+    testParser(txt, Parser6Context::PARSER_DHCP6, false);
+
+    // Invalid configuration: both map and list.
+    string bad1(R"({
+    "Dhcp6": {
+        "control-socket": {
+            "socket-type": "http",
+            "socket-address": "::1"
+        },
+        "control-sockets": [ ]
+     }
+})");
+
+    ASSERT_NO_THROW(Element::fromJSON(bad1, true));
+    Parser6Context ctx1;
+    EXPECT_THROW(ctx1.parseString(bad1, Parser6Context::PARSER_DHCP6),
+                 Dhcp6ParseError);
+
+    // Invalid configuration: both name and address.
+    string bad2(R"({
+    "Dhcp6": {
+        "control-socket": {
+            "socket-type": "http",
+            "socket-address": "::1",
+            "socket-name": "127.0.0.1"
+        }
+     }
+})");
+
+    ASSERT_NO_THROW(Element::fromJSON(bad1, true));
+    Parser6Context ctx2;
+    EXPECT_THROW(ctx2.parseString(bad2, Parser6Context::PARSER_DHCP6),
+                 Dhcp6ParseError);
+}
+
 }  // namespace test
 }  // namespace dhcp
 }  // namespace isc