// 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.
// 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.
"control-sockets": [
{
"socket-type": "unix",
- "socket-name": "/tmp/kea-ddns-ctrl-socket",
+ "socket-name": "kea-ddns-ctrl-socket",
"user-context": { "comment": "Indirect comment" }
},
{
"control-socket":
{
"socket-type": "unix",
- "socket-name": "/tmp/kea-ddns-ctrl-socket"
+ "socket-name": "kea-ddns-ctrl-socket"
},
// ----------------- Hooks Libraries -----------------
// "control-socket":
// {
// "socket-type": "unix",
-// "socket-name": "/tmp/kea-ddns-ctrl-socket"
+// "socket-name": "kea-ddns-ctrl-socket"
// },
// ----------------- Forward DDNS ------------------
#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>
#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>
using namespace isc::d2;
using namespace isc::hooks;
using namespace isc::process;
+using namespace isc::config;
+using namespace isc::util;
namespace {
/// @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.
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_;
/// 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
"\"ncr-format\": \"JSON\", "
"\"control-socket\" : {"
" \"socket-type\" : \"unix\" ,"
- " \"socket-name\" : \"/tmp/d2-ctrl-channel\" "
+ " \"socket-name\" : \"d2-ctrl-channel\" "
"},"
"\"hooks-libraries\": ["
"{"
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();
/// @brief Tests comments.
TEST_F(D2CfgMgrTest, comments) {
+ setSocketTestPath();
std::string config = "{ "
"\"comment\": \"D2 config\" , "
"\"ip-address\" : \"192.168.1.33\" , "
"\"control-sockets\": ["
"{"
" \"socket-type\": \"unix\","
- " \"socket-name\": \"/tmp/d2-ctrl-socket\","
+ " \"socket-name\": \"d2-ctrl-socket\","
" \"user-context\": { \"comment\":"
" \"Indirect comment\" }"
"},"
#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>
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;
/// 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());
}
// Reset command manager.
CommandMgr::instance().deregisterAll();
UnixCommandMgr::instance().setConnectionTimeout(TIMEOUT_DHCP_SERVER_RECEIVE_COMMAND);
+ resetSocketPath();
}
/// @brief Returns pointer to the server's IO service.
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
#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>
using namespace isc::process;
using namespace isc::test;
using namespace isc::hooks;
+using namespace isc::util;
namespace {
D2GetConfigTest()
: rcode_(-1) {
resetHooksPath();
+ resetSocketPath();
srv_.reset(new D2CfgMgr());
// Enforce not verbose mode.
Daemon::setVerbose(false);
static_cast<void>(remove(test_file_name.c_str()));
resetConfiguration();
resetHooksPath();
+ resetSocketPath();
}
/// @brief Sets the Hooks path from which hooks can be loaded.
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.
/// Test a configuration
TEST_F(D2GetConfigTest, sample1) {
setHooksTestPath();
+ setSocketTestPath();
// get the sample1 configuration
std::string sample1_file = string(CFG_EXAMPLES) + "/" + "sample1.json";
"DhcpDdns": {
"control-sockets": [
{
- "socket-name": "/tmp/kea-ddns-ctrl-socket",
+ "socket-name": "kea-ddns-ctrl-socket",
"socket-type": "unix"
}
],