mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-01 14:35:29 +00:00
[#3831] Checkpoint: did dhcp4 UTs
This commit is contained in:
@@ -1529,6 +1529,9 @@ TEST_F(CtrlChannelDhcpv4SrvTest, configWriteFilename) {
|
|||||||
createUnixChannelServer();
|
createUnixChannelServer();
|
||||||
std::string response;
|
std::string response;
|
||||||
|
|
||||||
|
// This is normally set by the command line -c parameter.
|
||||||
|
server_->setConfigFile("test1.json");
|
||||||
|
|
||||||
sendUnixCommand("{ \"command\": \"config-write\", "
|
sendUnixCommand("{ \"command\": \"config-write\", "
|
||||||
"\"arguments\": { \"filename\": \"test2.json\" } }", response);
|
"\"arguments\": { \"filename\": \"test2.json\" } }", response);
|
||||||
|
|
||||||
@@ -1536,6 +1539,59 @@ TEST_F(CtrlChannelDhcpv4SrvTest, configWriteFilename) {
|
|||||||
::remove("test2.json");
|
::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
|
// Tests if config-reload attempts to reload a file and reports that the
|
||||||
// file is missing.
|
// file is missing.
|
||||||
TEST_F(CtrlChannelDhcpv4SrvTest, configReloadMissingFile) {
|
TEST_F(CtrlChannelDhcpv4SrvTest, configReloadMissingFile) {
|
||||||
|
@@ -389,6 +389,12 @@ public:
|
|||||||
ASSERT_TRUE(from_file);
|
ASSERT_TRUE(from_file);
|
||||||
} else if (exp_status == CONTROL_RESULT_ERROR) {
|
} 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.
|
// Let's check if the reason for failure was given.
|
||||||
ConstElementPtr text = rsp->get("text");
|
ConstElementPtr text = rsp->get("text");
|
||||||
ASSERT_TRUE(text);
|
ASSERT_TRUE(text);
|
||||||
@@ -503,6 +509,15 @@ public:
|
|||||||
// Tests if config-write can be called with a valid filename as parameter.
|
// Tests if config-write can be called with a valid filename as parameter.
|
||||||
void testConfigWriteFilename();
|
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
|
// Tests if config-reload attempts to reload a file and reports that the
|
||||||
// file is missing.
|
// file is missing.
|
||||||
void testConfigReloadMissingFile();
|
void testConfigReloadMissingFile();
|
||||||
@@ -2323,6 +2338,9 @@ BaseCtrlChannelDhcpv4Test::testConfigWriteFilename() {
|
|||||||
createHttpChannelServer();
|
createHttpChannelServer();
|
||||||
std::string response;
|
std::string response;
|
||||||
|
|
||||||
|
// This is normally set by the command line -c parameter.
|
||||||
|
server_->setConfigFile("test1.json");
|
||||||
|
|
||||||
sendHttpCommand("{ \"command\": \"config-write\", "
|
sendHttpCommand("{ \"command\": \"config-write\", "
|
||||||
"\"arguments\": { \"filename\": \"test2.json\" } }",
|
"\"arguments\": { \"filename\": \"test2.json\" } }",
|
||||||
response);
|
response);
|
||||||
@@ -2339,6 +2357,87 @@ TEST_F(HttpsCtrlChannelDhcpv4Test, configWriteFilename) {
|
|||||||
testConfigWriteFilename();
|
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
|
// Tests if config-reload attempts to reload a file and reports that the
|
||||||
// file is missing.
|
// file is missing.
|
||||||
void
|
void
|
||||||
|
Reference in New Issue
Block a user