]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2707] Checkpoint before v6
authorFrancis Dupont <fdupont@isc.org>
Mon, 5 Jun 2023 15:32:48 +0000 (17:32 +0200)
committerTomek Mrugalski <tomek@isc.org>
Thu, 22 Jun 2023 14:23:38 +0000 (16:23 +0200)
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
src/lib/process/d_controller.cc

index 02167097a1dce606d0fd2e37e704258ad1fe5db4..f923901e17466ca1695564d064c63682321cbcc7 100644 (file)
@@ -552,6 +552,7 @@ TEST_F(CtrlChannelDhcpv4SrvTest, commandsRegistration) {
     EXPECT_TRUE(command_list.find("\"build-report\"") != string::npos);
     EXPECT_TRUE(command_list.find("\"config-backend-pull\"") != string::npos);
     EXPECT_TRUE(command_list.find("\"config-get\"") != string::npos);
+    EXPECT_TRUE(command_list.find("\"config-hash-get\"") != string::npos);
     EXPECT_TRUE(command_list.find("\"config-set\"") != string::npos);
     EXPECT_TRUE(command_list.find("\"config-write\"") != string::npos);
     EXPECT_TRUE(command_list.find("\"leases-reclaim\"") != string::npos);
@@ -916,6 +917,33 @@ TEST_F(CtrlChannelDhcpv4SrvTest, configGet) {
     EXPECT_TRUE(cfg->get("Dhcp4")->get("loggers"));
 }
 
+// Tests if the server returns the hash of its configuration using
+// config-hash-get.
+TEST_F(CtrlChannelDhcpv4SrvTest, configHashGet) {
+    createUnixChannelServer();
+    std::string response;
+
+    sendUnixCommand("{ \"command\": \"config-hash-get\" }", response);
+    ConstElementPtr rsp;
+
+    // The response should be a valid JSON.
+    EXPECT_NO_THROW(rsp = Element::fromJSON(response));
+    ASSERT_TRUE(rsp);
+
+    int status;
+    ConstElementPtr args = parseAnswer(status, rsp);
+    EXPECT_EQ(CONTROL_RESULT_SUCCESS, status);
+
+    // Ok, now roughly check if the response seems legit.
+    ASSERT_TRUE(args);
+    ASSERT_EQ(Element::map, args->getType());
+    ConstElementPtr hash = args->get("hash");
+    ASSERT_TRUE(hash);
+    ASSERT_EQ(Element::string, hash->getType());
+    // SHA-256 -> 64 hex digits.
+    EXPECT_EQ(64, hash->stringValue().size());
+}
+
 // Verify that the "config-test" command will do what we expect.
 TEST_F(CtrlChannelDhcpv4SrvTest, configTest) {
     createUnixChannelServer();
@@ -1418,6 +1446,7 @@ TEST_F(CtrlChannelDhcpv4SrvTest, listCommands) {
     checkListCommands(rsp, "build-report");
     checkListCommands(rsp, "config-backend-pull");
     checkListCommands(rsp, "config-get");
+    checkListCommands(rsp, "config-hash-get");
     checkListCommands(rsp, "config-reload");
     checkListCommands(rsp, "config-set");
     checkListCommands(rsp, "config-test");
index 077e08c0d31f847ae0eef5e713498f19caf766ee..7b240b05aeecaf7eb2b160cc0247ffd917736f75 100644 (file)
@@ -451,6 +451,14 @@ ConstElementPtr
 DControllerBase::configGetHandler(const std::string&,
                                   ConstElementPtr /*args*/) {
     ConstElementPtr config = process_->getCfgMgr()->getContext()->toElement();
+
+    return (createAnswer(CONTROL_RESULT_SUCCESS, config));
+}
+
+ConstElementPtr
+DControllerBase::configHashGetHandler(const std::string&,
+                                      ConstElementPtr /*args*/) {
+    ConstElementPtr config = process_->getCfgMgr()->getContext()->toElement();
     // Assume that config is never null.
     std::string config_txt = config->str();
     OutputBuffer hash_data(0);