createUnixChannelServer();
std::string response;
+ // This is normally set by the command line -c parameter.
+ server_->setConfigFile("test1.json");
+
sendUnixCommand("{ \"command\": \"config-write\", "
"\"arguments\": { \"filename\": \"test2.json\" } }", response);
::remove("test2.json");
}
+// Tests if config-write can be called with a valid full path as parameter.
+TEST_F(CtrlChannelDhcpv4SrvTest, configWriteFullPath) {
+ createUnixChannelServer();
+ std::string response;
+
+
+ // This is normally set by the command line -c parameter.
+ server_->setConfigFile("/tmp/test1.json");
+
+
+ sendUnixCommand("{ \"command\": \"config-write\", "
+ "\"arguments\": { \"filename\": \"/tmp/test2.json\" } }", response);
+
+ checkConfigWrite(response, CONTROL_RESULT_SUCCESS, "/tmp/test2.json");
+ ::remove("/tmp/test2.json");
+}
+
+// Tests if config-write raises an error with invalid path as parameter.
+TEST_F(CtrlChannelDhcpv4SrvTest, configWriteBadPath) {
+ createUnixChannelServer();
+ std::string response;
+
+ // This is normally set by the command line -c parameter.
+ server_->setConfigFile("test1.json");
+
+ sendUnixCommand("{ \"command\": \"config-write\", "
+ "\"arguments\": { \"filename\": \"/tmp/test2.json\" } }", response);
+
+ string expected = "not allowed to write config into /tmp/test2.json: ";
+ expected += "file /tmp/test2.json must be in the same directory ";
+ expected += "as the config file (test1.json)";
+ checkConfigWrite(response, CONTROL_RESULT_ERROR, expected);
+ ::remove("/tmp/test2.json");
+}
+
+// Tests if config-write raises an error with invalid full path as parameter.
+TEST_F(CtrlChannelDhcpv4SrvTest, configWriteBadFullPath) {
+ createUnixChannelServer();
+ std::string response;
+
+ // This is normally set by the command line -c parameter.
+ server_->setConfigFile("/tmp/kea1/test.json");
+
+ sendUnixCommand("{ \"command\": \"config-write\", "
+ "\"arguments\": { \"filename\": \"/tmp/kea2/test.json\" } }", response);
+
+ string expected = "not allowed to write config into /tmp/kea2/test.json: ";
+ expected += "file /tmp/kea2/test.json must be in the same directory ";
+ expected += "as the config file (/tmp/kea1/test.json)";
+ checkConfigWrite(response, CONTROL_RESULT_ERROR, expected);
+ ::remove("/tmp/kea2/test.json");
+}
+
// Tests if config-reload attempts to reload a file and reports that the
// file is missing.
TEST_F(CtrlChannelDhcpv4SrvTest, configReloadMissingFile) {
ASSERT_TRUE(from_file);
} else if (exp_status == CONTROL_RESULT_ERROR) {
+ // Errors can be in a list.
+ if (rsp->getType() == Element::list) {
+ ASSERT_EQ(1, rsp->size());
+ rsp = rsp->get(0);
+ }
+
// Let's check if the reason for failure was given.
ConstElementPtr text = rsp->get("text");
ASSERT_TRUE(text);
// Tests if config-write can be called with a valid filename as parameter.
void testConfigWriteFilename();
+ // Tests if config-write can be called with a valid full path as parameter.
+ void testConfigWriteFullPath();
+
+ // Tests if config-write raises an error with invalid path as parameter.
+ void testConfigWriteBadPath();
+
+ // Tests if config-write raises an error with invalid full path as parameter.
+ void testConfigWriteBadFullPath();
+
// Tests if config-reload attempts to reload a file and reports that the
// file is missing.
void testConfigReloadMissingFile();
createHttpChannelServer();
std::string response;
+ // This is normally set by the command line -c parameter.
+ server_->setConfigFile("test1.json");
+
sendHttpCommand("{ \"command\": \"config-write\", "
"\"arguments\": { \"filename\": \"test2.json\" } }",
response);
testConfigWriteFilename();
}
+// Tests if config-write can be called with a valid full path as parameter.
+void
+BaseCtrlChannelDhcpv4Test::testConfigWriteFullPath() {
+ createHttpChannelServer();
+ std::string response;
+
+ // This is normally set by the command line -c parameter.
+ server_->setConfigFile("/tmp/test1.json");
+
+ sendHttpCommand("{ \"command\": \"config-write\", "
+ "\"arguments\": { \"filename\": \"/tmp/test2.json\" } }",
+ response);
+
+ checkConfigWrite(response, CONTROL_RESULT_SUCCESS, "/tmp/test2.json");
+ ::remove("/tmp/test2.json");
+}
+
+TEST_F(HttpCtrlChannelDhcpv4Test, configWriteFullPath) {
+ testConfigWriteFullPath();
+}
+
+TEST_F(HttpsCtrlChannelDhcpv4Test, configWriteFullPath) {
+ testConfigWriteFullPath();
+}
+
+// Tests if config-write raises an error with invalid path as parameter.
+void
+BaseCtrlChannelDhcpv4Test::testConfigWriteBadPath() {
+ createHttpChannelServer();
+ std::string response;
+
+ // This is normally set by the command line -c parameter.
+ server_->setConfigFile("test1.json");
+
+ sendHttpCommand("{ \"command\": \"config-write\", "
+ "\"arguments\": { \"filename\": \"/tmp/test2.json\" } }",
+ response);
+
+ string expected = "not allowed to write config into /tmp/test2.json: ";
+ expected += "file /tmp/test2.json must be in the same directory ";
+ expected += "as the config file (test1.json)";
+ checkConfigWrite(response, CONTROL_RESULT_ERROR, expected);
+ ::remove("/tmp/test2.json");
+}
+
+TEST_F(HttpCtrlChannelDhcpv4Test, configWriteBadPath) {
+ testConfigWriteBadPath();
+}
+
+TEST_F(HttpsCtrlChannelDhcpv4Test, configWriteBadPath) {
+ testConfigWriteBadPath();
+}
+
+// Tests if config-write raises an error with invalid full path as parameter.
+void
+BaseCtrlChannelDhcpv4Test::testConfigWriteBadFullPath() {
+ createHttpChannelServer();
+ std::string response;
+
+ // This is normally set by the command line -c parameter.
+ server_->setConfigFile("/tmp/kea1/test.json");
+
+ sendHttpCommand("{ \"command\": \"config-write\", "
+ "\"arguments\": { \"filename\": \"/tmp/kea2/test.json\" } }",
+ response);
+
+ string expected = "not allowed to write config into /tmp/kea2/test.json: ";
+ expected += "file /tmp/kea2/test.json must be in the same directory ";
+ expected += "as the config file (/tmp/kea1/test.json)";
+ checkConfigWrite(response, CONTROL_RESULT_ERROR, expected);
+ ::remove("/tmp/kea2/test.json");
+}
+
+TEST_F(HttpCtrlChannelDhcpv4Test, configWriteBadFullPath) {
+ testConfigWriteBadFullPath();
+}
+
+TEST_F(HttpsCtrlChannelDhcpv4Test, configWriteBadFullPath) {
+ testConfigWriteBadFullPath();
+}
+
// Tests if config-reload attempts to reload a file and reports that the
// file is missing.
void