From: Andrei Pavel Date: Mon, 3 Nov 2025 11:20:11 +0000 (+0200) Subject: [#3969] Add negative tests for bad socket path in netconf X-Git-Tag: Kea-3.1.4~93 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1625d21196120065142c330c35ea32db7638e3f7;p=thirdparty%2Fkea.git [#3969] Add negative tests for bad socket path in netconf --- diff --git a/src/bin/netconf/tests/netconf_controller_unittests.cc b/src/bin/netconf/tests/netconf_controller_unittests.cc index f12f4de5f1..9fc505e66b 100644 --- a/src/bin/netconf/tests/netconf_controller_unittests.cc +++ b/src/bin/netconf/tests/netconf_controller_unittests.cc @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -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 diff --git a/src/bin/netconf/tests/netconf_unittests.cc b/src/bin/netconf/tests/netconf_unittests.cc index 55ac3fa2c2..e3848fe426 100644 --- a/src/bin/netconf/tests/netconf_unittests.cc +++ b/src/bin/netconf/tests/netconf_unittests.cc @@ -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