]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3831] More UT fixes
authorThomas Markwalder <tmark@isc.org>
Fri, 16 May 2025 13:09:48 +0000 (09:09 -0400)
committerThomas Markwalder <tmark@isc.org>
Mon, 19 May 2025 12:12:55 +0000 (12:12 +0000)
modified:   doc/examples/ddns/all-keys-netconf.json
modified:   doc/examples/ddns/all-keys.json
modified:   doc/examples/ddns/comments.json
modified:   doc/examples/ddns/sample1.json
modified:   doc/examples/ddns/template.json
modified:   src/bin/d2/tests/d2_cfg_mgr_unittests.cc
modified:   src/bin/d2/tests/d2_command_unittest.cc
modified:   src/bin/d2/tests/get_config_unittest.cc
modified:   src/bin/d2/tests/testdata/get_config.json

doc/examples/ddns/all-keys-netconf.json
doc/examples/ddns/all-keys.json
doc/examples/ddns/comments.json
doc/examples/ddns/sample1.json
doc/examples/ddns/template.json
src/bin/d2/tests/d2_cfg_mgr_unittests.cc
src/bin/d2/tests/d2_command_unittest.cc
src/bin/d2/tests/get_config_unittest.cc
src/bin/d2/tests/testdata/get_config.json

index 642258dc35d30ec46c5bbb739fcbb233027410b1..be481f6851e50f7b1a885485e34431c07b7f0e7a 100644 (file)
@@ -40,7 +40,7 @@
         // Location of the UNIX domain socket file the DHCP-DDNS server uses
         // to receive control commands from the Kea Control Agent or the
         // local server administrator.
-        "socket-name": "/tmp/kea-ddns-ctrl-socket",
+        "socket-name": "kea-ddns-ctrl-socket",
 
         // Control socket type used by the Kea DHCP-DDNS server.
         // The 'unix' socket is currently the only supported type.
index b9015d871366e9bcce0c8088bff658f97f6bc5b2..f1b8d48b9a1fd892c8dd4759a9cd8928ff965614 100644 (file)
@@ -44,7 +44,7 @@
             // Location of the UNIX domain socket file the DHCP-DDNS
             // server uses to receive control commands from the
             // local server administrator.
-            "socket-name": "/tmp/kea-ddns-ctrl-socket"
+            "socket-name": "kea-ddns-ctrl-socket"
         },
         {
             // Control socket type used by the Kea DHCP-DDNS server.
index ecd68c47653881f9db85a0bc0628149555c6e83c..08b24e609a251ac136a22410e3337add2f20c4d8 100644 (file)
@@ -16,7 +16,7 @@
     "control-sockets": [
         {
             "socket-type": "unix",
-            "socket-name": "/tmp/kea-ddns-ctrl-socket",
+            "socket-name": "kea-ddns-ctrl-socket",
             "user-context": { "comment": "Indirect comment" }
         },
         {
index 4d8148bc29f41c30bfe0a78d78eb8c2895da8a1e..2c43ba920ae2bc9f2533cbd072b37ff85840e10b 100644 (file)
@@ -32,7 +32,7 @@
     "control-socket":
     {
         "socket-type": "unix",
-        "socket-name": "/tmp/kea-ddns-ctrl-socket"
+        "socket-name": "kea-ddns-ctrl-socket"
     },
 
 // ----------------- Hooks Libraries -----------------
index cec9e3234b625268fb1b97cbef228f525618a937..67b371b7bcb205c225fdf75f36e933f29b0f7d1a 100644 (file)
@@ -19,7 +19,7 @@
 //    "control-socket":
 //    {
 //        "socket-type": "unix",
-//        "socket-name": "/tmp/kea-ddns-ctrl-socket"
+//        "socket-name": "kea-ddns-ctrl-socket"
 //    },
 
 // ----------------- Forward DDNS  ------------------
index 42983a607dc6fe4d442e7a132b0b95d134284f1c..f71e6a29bae17b59cd78bbb8e8343d02310e5125 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 
 #include <config/http_command_config.h>
+#include <config/unix_command_config.h>
 #include <d2/parser_context.h>
 #include <d2/tests/parser_unittest.h>
 #include <d2/tests/test_callout_libraries.h>
@@ -18,6 +19,7 @@
 #include <process/testutils/d_test_stubs.h>
 #include <test_data_files_config.h>
 #include <util/encode/encode.h>
+#include <util/filesystem.h>
 
 #include <boost/scoped_ptr.hpp>
 #include <gtest/gtest.h>
@@ -27,6 +29,8 @@ using namespace isc;
 using namespace isc::d2;
 using namespace isc::hooks;
 using namespace isc::process;
+using namespace isc::config;
+using namespace isc::util;
 
 namespace {
 
@@ -50,11 +54,13 @@ public:
     /// @brief Constructor
     D2CfgMgrTest():cfg_mgr_(new D2CfgMgr()), d2_params_() {
        resetHooksPath();
+       resetSocketPath();
     }
 
     /// @brief Destructor
     ~D2CfgMgrTest() {
        resetHooksPath();
+       resetSocketPath();
     }
 
     /// @brief Sets the Hooks path from which hooks can be loaded.
@@ -70,6 +76,22 @@ public:
         HooksLibrariesParser::getHooksPath(true);
     }
 
+    /// @brief Sets the path in which the socket can be created.
+    /// @param explicit_path path to use as the socket path.
+    void setSocketTestPath(const std::string explicit_path = "") {
+        UnixCommandConfig::getSocketPath(true, (!explicit_path.empty() ?
+                                         explicit_path : TEST_DATA_BUILDDIR));
+
+        auto path = UnixCommandConfig::getSocketPath();
+        UnixCommandConfig::setSocketPathPerms(file::getPermissions(path));
+    }
+
+    /// @brief Resets the socket path to the default.
+    void resetSocketPath() {
+        UnixCommandConfig::getSocketPath(true);
+        UnixCommandConfig::setSocketPathPerms();
+    }
+
     /// @brief Configuration manager instance.
     D2CfgMgrPtr cfg_mgr_;
 
@@ -478,6 +500,7 @@ TEST(D2CfgMgr, construction) {
 /// event.
 TEST_F(D2CfgMgrTest, fullConfig) {
     setHooksTestPath();
+    setSocketTestPath();
 
     // Create a configuration with all of application level parameters, plus
     // both the forward and reverse ddns managers.  Both managers have two
@@ -490,7 +513,7 @@ TEST_F(D2CfgMgrTest, fullConfig) {
                         "\"ncr-format\": \"JSON\", "
                         "\"control-socket\" : {"
                         " \"socket-type\" : \"unix\" ,"
-                        " \"socket-name\" : \"/tmp/d2-ctrl-channel\" "
+                        " \"socket-name\" : \"d2-ctrl-channel\" "
                         "},"
                         "\"hooks-libraries\": ["
                         "{"
@@ -580,7 +603,7 @@ TEST_F(D2CfgMgrTest, fullConfig) {
     ASSERT_TRUE(ctrl_sock->get("socket-type"));
     EXPECT_EQ("\"unix\"", ctrl_sock->get("socket-type")->str());
     ASSERT_TRUE(ctrl_sock->get("socket-name"));
-    EXPECT_EQ("\"/tmp/d2-ctrl-channel\"", ctrl_sock->get("socket-name")->str());
+    EXPECT_EQ("\"d2-ctrl-channel\"", ctrl_sock->get("socket-name")->str());
 
     // Verify that the hooks libraries can be retrieved.
     const HookLibsCollection libs = context->getHooksConfig().get();
@@ -989,6 +1012,7 @@ TEST_F(D2CfgMgrTest, configPermutations) {
 
 /// @brief Tests comments.
 TEST_F(D2CfgMgrTest, comments) {
+    setSocketTestPath();
     std::string config = "{ "
                         "\"comment\": \"D2 config\" , "
                         "\"ip-address\" : \"192.168.1.33\" , "
@@ -996,7 +1020,7 @@ TEST_F(D2CfgMgrTest, comments) {
                         "\"control-sockets\": ["
                         "{"
                         " \"socket-type\": \"unix\","
-                        " \"socket-name\": \"/tmp/d2-ctrl-socket\","
+                        " \"socket-name\": \"d2-ctrl-socket\","
                         " \"user-context\": { \"comment\":"
                         "  \"Indirect comment\" }"
                         "},"
index f83f5cd88b26ea5bcb1ba0bf236f191daf65d4fb..52360a22cbd27ec2c991b76d69e76650594d60d0 100644 (file)
@@ -17,6 +17,7 @@
 #include <d2/d2_controller.h>
 #include <d2/d2_process.h>
 #include <d2/parser_context.h>
+#include <util/filesystem.h>
 #include <gtest/gtest.h>
 #include <testutils/sandbox.h>
 #include <boost/pointer_cast.hpp>
@@ -34,6 +35,7 @@ using namespace isc::d2;
 using namespace isc::data;
 using namespace isc::dhcp::test;
 using namespace isc::process;
+using namespace isc::util;
 using namespace boost::asio;
 namespace ph = std::placeholders;
 
@@ -125,12 +127,7 @@ public:
     /// Sets socket path to its default value.
     CtrlChannelD2Test()
         : server_(NakedD2Controller::instance()) {
-        const char* env = getenv("KEA_SOCKET_TEST_DIR");
-        if (env) {
-            socket_path_ = string(env) + "/d2.sock";
-        } else {
-            socket_path_ = sandbox.join("d2.sock");
-        }
+        setSocketTestPath();
         ::remove(socket_path_.c_str());
     }
 
@@ -146,6 +143,7 @@ public:
         // Reset command manager.
         CommandMgr::instance().deregisterAll();
         UnixCommandMgr::instance().setConnectionTimeout(TIMEOUT_DHCP_SERVER_RECEIVE_COMMAND);
+        resetSocketPath();
     }
 
     /// @brief Returns pointer to the server's IO service.
@@ -156,6 +154,23 @@ public:
         return (server_ ? d2Controller()->getIOService() : IOServicePtr());
     }
 
+    /// @brief Sets the path in which the socket can be created.
+    /// @param explicit_path path to use as the socket path.
+    void setSocketTestPath(const std::string explicit_path = "") {
+        UnixCommandConfig::getSocketPath(true, (!explicit_path.empty() ?
+                                         explicit_path : TEST_DATA_BUILDDIR));
+
+        auto path = UnixCommandConfig::getSocketPath();
+        UnixCommandConfig::setSocketPathPerms(file::getPermissions(path));
+        socket_path_ = path + "/d2.sock";
+    }
+
+    /// @brief Resets the socket path to the default.
+    void resetSocketPath() {
+        UnixCommandConfig::getSocketPath(true);
+        UnixCommandConfig::setSocketPathPerms();
+    }
+
     /// @brief Runs parser in DHCPDDNS mode
     ///
     /// @param config input configuration
index 6eee45d0666d3b215b88e9e08187a51f0c17ae65..84a38ab4c90170dbd63104286b06f89c0d9d6369 100644 (file)
@@ -8,12 +8,14 @@
 
 #include <cc/command_interpreter.h>
 #include <cc/data.h>
+#include <config/unix_command_config.h>
 #include <d2/parser_context.h>
 #include <d2srv/d2_cfg_mgr.h>
 #include <d2srv/d2_config.h>
 #include <hooks/hooks_parser.h>
 #include <process/testutils/d_test_stubs.h>
 #include <testutils/user_context_utils.h>
+#include <util/filesystem.h>
 #include <gtest/gtest.h>
 
 #include <iostream>
@@ -30,6 +32,7 @@ using namespace isc::data;
 using namespace isc::process;
 using namespace isc::test;
 using namespace isc::hooks;
+using namespace isc::util;
 
 namespace {
 
@@ -142,6 +145,7 @@ public:
     D2GetConfigTest()
     : rcode_(-1) {
         resetHooksPath();
+        resetSocketPath();
         srv_.reset(new D2CfgMgr());
         // Enforce not verbose mode.
         Daemon::setVerbose(false);
@@ -155,6 +159,7 @@ public:
         static_cast<void>(remove(test_file_name.c_str()));
         resetConfiguration();
         resetHooksPath();
+        resetSocketPath();
     }
 
     /// @brief Sets the Hooks path from which hooks can be loaded.
@@ -170,6 +175,23 @@ public:
         HooksLibrariesParser::getHooksPath(true);
     }
 
+
+    /// @brief Sets the path in which the socket can be created.
+    /// @param explicit_path path to use as the socket path.
+    void setSocketTestPath(const std::string explicit_path = "") {
+        UnixCommandConfig::getSocketPath(true, (!explicit_path.empty() ?
+                                         explicit_path : TEST_DATA_BUILDDIR));
+
+        auto path = UnixCommandConfig::getSocketPath();
+        UnixCommandConfig::setSocketPathPerms(file::getPermissions(path));
+    }
+
+    /// @brief Resets the socket path to the default.
+    void resetSocketPath() {
+        UnixCommandConfig::getSocketPath(true);
+        UnixCommandConfig::setSocketPathPerms();
+    }
+
     /// @brief Parse and Execute configuration
     ///
     /// Parses a configuration and executes a configuration of the server.
@@ -279,6 +301,7 @@ public:
 /// Test a configuration
 TEST_F(D2GetConfigTest, sample1) {
     setHooksTestPath();
+    setSocketTestPath();
 
     // get the sample1 configuration
     std::string sample1_file = string(CFG_EXAMPLES) + "/" + "sample1.json";
index d3059dde7fef7832e1fa80c4bd9e75d048dd740c..1a6d9ed0988383096c42cc7afbdff602c1bd93a1 100644 (file)
@@ -2,7 +2,7 @@
     "DhcpDdns": {
         "control-sockets": [
             {
-                "socket-name": "/tmp/kea-ddns-ctrl-socket",
+                "socket-name": "kea-ddns-ctrl-socket",
                 "socket-type": "unix"
             }
         ],