mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 05:55:28 +00:00
[#3831] Checkpoint: did dhcp4 UTs
This commit is contained in:
@@ -1529,6 +1529,9 @@ TEST_F(CtrlChannelDhcpv4SrvTest, configWriteFilename) {
|
||||
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);
|
||||
|
||||
@@ -1536,6 +1539,59 @@ TEST_F(CtrlChannelDhcpv4SrvTest, configWriteFilename) {
|
||||
::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) {
|
||||
|
@@ -389,6 +389,12 @@ public:
|
||||
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);
|
||||
@@ -503,6 +509,15 @@ public:
|
||||
// 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();
|
||||
@@ -2323,6 +2338,9 @@ BaseCtrlChannelDhcpv4Test::testConfigWriteFilename() {
|
||||
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);
|
||||
@@ -2339,6 +2357,87 @@ TEST_F(HttpsCtrlChannelDhcpv4Test, configWriteFilename) {
|
||||
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
|
||||
|
Reference in New Issue
Block a user