]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3969] Add negative tests for bad socket path in netconf
authorAndrei Pavel <andrei@isc.org>
Mon, 3 Nov 2025 11:20:11 +0000 (13:20 +0200)
committerAndrei Pavel <andrei@isc.org>
Wed, 5 Nov 2025 13:01:01 +0000 (15:01 +0200)
src/bin/netconf/tests/netconf_controller_unittests.cc
src/bin/netconf/tests/netconf_unittests.cc

index f12f4de5f1a4c0010fdd944c01efc2d1ff8e0ff2..9fc505e66be0eed2fcdf36fc064c3068af361eec 100644 (file)
@@ -12,6 +12,7 @@
 #include <netconf/netconf_process.h>
 #include <process/testutils/d_test_stubs.h>
 #include <testutils/gtest_utils.h>
+#include <util/filesystem.h>
 
 #include <gtest/gtest.h>
 
@@ -20,6 +21,7 @@ using namespace isc::netconf;
 using namespace isc::data;
 using namespace isc::http;
 using namespace isc::process;
+using namespace isc::util::file;
 using namespace std;
 
 namespace {
@@ -45,6 +47,20 @@ const char* valid_netconf_config =
     "  }"
     "}";
 
+string const bad_socket_name_config(R"(
+{
+  "managed-servers": {
+    "dhcp6": {
+      "control-socket": {
+        "socket-name": "/tmp/kea-dhcp6-ctrl.sock",
+        "socket-type": "unix"
+      },
+      "model": "kea-dhcp6-server"
+    }
+  }
+}
+)");
+
 /// @brief test fixture class for testing NetconfController class.
 ///
 /// This class derives from DControllerTest and wraps NetconfController. Much
@@ -186,4 +202,12 @@ TEST_F(NetconfControllerTest, sigtermShutdown) {
     EXPECT_TRUE(elapsed_time.total_milliseconds() < 300);
 }
 
+// Check that a bad socket path is refused.
+TEST_F(NetconfControllerTest, badSocketPath) {
+    time_duration elapsed_time;
+    EXPECT_THROW_MSG(runWithConfig(bad_socket_name_config, 200, elapsed_time), ProcessInitError,
+                     "Could Not load configuration file: invalid path specified: '/tmp', supported "
+                     "path is '/opt/kea/var/run/kea'");
+}
+
 }  // namespace
index 55ac3fa2c2de83b6db8587cb2153f17738d1018c..e3848fe426ee9396f912a8d9a14d4b6d7ae5402f 100644 (file)
@@ -42,6 +42,7 @@ using namespace isc::config;
 using namespace isc::data;
 using namespace isc::http;
 using namespace isc::test;
+using namespace isc::util::file;
 using namespace isc::yang;
 using namespace isc::yang::test;
 using namespace libyang;
@@ -1165,4 +1166,39 @@ TEST_F(NetconfAgentTest, noValidate) {
                      "Session::applyChanges: Couldn't apply changes: SR_ERR_VALIDATION_FAILED\n Validation failed (SR_ERR_VALIDATION_FAILED)");
 }
 
+// Check that a bad socket path is refused.
+TEST_F(NetconfAgentTest, badSocketPath) {
+    string config(R"(
+{
+  "Netconf": {
+    "managed-servers": {
+      "dhcp6": {
+        "control-socket": {
+          "socket-name": "/tmp/kea-dhcp6-ctrl.sock",
+          "socket-type": "unix"
+        },
+        "model": "kea-dhcp6-server"
+      }
+    }
+  }
+}
+)");
+
+    ElementPtr json;
+    ParserContext parser_context;
+    EXPECT_NO_THROW_LOG(json = parser_context.parseString(config, ParserContext::PARSER_NETCONF));
+    ASSERT_TRUE(json);
+    ASSERT_EQ(Element::map, json->getType());
+    ConstElementPtr netconf_json = json->get("Netconf");
+    ASSERT_TRUE(netconf_json);
+    json = copy(netconf_json, 0);
+    ASSERT_TRUE(json);
+    NetconfSimpleParser::setAllDefaults(json);
+    NetconfSimpleParser::deriveParameters(json);
+    NetconfSimpleParser parser;
+    NetconfConfigPtr ctx(new NetconfConfig());
+    EXPECT_THROW_MSG(parser.parse(ctx, json, false), SecurityError,
+                     "invalid path specified: '/tmp', supported path is '/opt/kea/var/run/kea'");
+}
+
 }  // namespace