std::string response;
sendUnixCommand(os.str(), response);
- // Verify the configuration was successful.
- EXPECT_EQ("{ \"result\": 0, \"text\": \"Configuration successful.\" }",
- response);
+ // Verify the configuration was successful. The config contains random
+ // socket name (/tmp/kea-<value-changing-each-time>/kea6.sock), so the
+ // hash will be different each time. As such, we can do simplified checks:
+ // - verify the "result": 0 is there
+ // - verify the "text": "Configuration successful." is there
+ EXPECT_NE(response.find("\"result\": 0"), std::string::npos);
+ EXPECT_NE(response.find("\"text\": \"Configuration successful.\""), std::string::npos);
// Check that the config was indeed applied.
const Subnet6Collection* subnets =
// Verify the control channel socket no longer exists.
EXPECT_FALSE(fileExists(socket_path_));
- // With no command channel, should still receive the response.
- EXPECT_EQ("{ \"result\": 0, \"text\": \"Configuration successful.\" }",
- response);
+ // Verify the configuration was successful. The config contains random
+ // socket name (/tmp/kea-<value-changing-each-time>/kea6.sock), so the
+ // hash will be different each time. As such, we can do simplified checks:
+ // - verify the "result": 0 is there
+ // - verify the "text": "Configuration successful." is there
+ EXPECT_NE(response.find("\"result\": 0"), std::string::npos);
+ EXPECT_NE(response.find("\"text\": \"Configuration successful.\""), std::string::npos);
// Check that the config was not lost
subnets = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6()->getAll();
int status;
ConstElementPtr args = parseAnswer(status, rsp);
EXPECT_EQ(CONTROL_RESULT_SUCCESS, status);
+ // the parseAnswer is trying to be smart with ignoring hash.
+ // But this time we really want to see the hash, so we'll retrieve
+ // the arguments manually.
+ args = rsp->get(CONTROL_ARGUMENTS);
// Ok, now roughly check if the response seems legit.
ASSERT_TRUE(args);
std::string response;
sendUnixCommand(os.str(), response);
- // Verify the configuration was successful.
- EXPECT_EQ("{ \"result\": 0, \"text\": \"Configuration successful.\" }",
- response);
+ // Verify the configuration was successful. The config contains random
+ // socket name (/tmp/kea-<value-changing-each-time>/kea6.sock), so the
+ // hash will be different each time. As such, we can do simplified checks:
+ // - verify the "result": 0 is there
+ // - verify the "text": "Configuration successful." is there
+ EXPECT_NE(response.find("\"result\": 0"), std::string::npos);
+ EXPECT_NE(response.find("\"text\": \"Configuration successful.\""), std::string::npos);
// Check that the config was indeed applied.
const Subnet6Collection* subnets =
// This command should reload test8.json config.
sendUnixCommand("{ \"command\": \"config-reload\" }", response);
- // Verify the configuration was successful.
- EXPECT_EQ("{ \"result\": 0, \"text\": \"Configuration successful.\" }",
- response);
+
+ // Verify the configuration was successful. The config contains random
+ // socket name (/tmp/kea-<value-changing-each-time>/kea6.sock), so the
+ // hash will be different each time. As such, we can do simplified checks:
+ // - verify the "result": 0 is there
+ // - verify the "text": "Configuration successful." is there
+ EXPECT_NE(response.find("\"result\": 0"), std::string::npos);
+ EXPECT_NE(response.find("\"text\": \"Configuration successful.\""), std::string::npos);
// Check that the config was indeed applied.
const Subnet6Collection* subnets =
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);
- isc::cryptolink::digest(config_txt.c_str(),
- config_txt.size(),
- isc::cryptolink::HashAlgorithm::SHA256,
- hash_data);
- std::vector<uint8_t> hash;
- hash.resize(hash_data.getLength());
- if (hash.size() > 0) {
- memmove(&hash[0], hash_data.getData(), hash.size());
- }
+ ElementPtr config = process_->getCfgMgr()->getContext()->toElement();
+ std::string hash = BaseCommandMgr::getHash(config);
ElementPtr params = Element::createMap();
- params->set("hash", Element::create(encode::encodeHex(hash)));
+ params->set("hash", Element::create(hash));
return (createAnswer(CONTROL_RESULT_SUCCESS, params));
}