From: Francis Dupont Date: Tue, 7 Dec 2021 14:42:29 +0000 (+0100) Subject: [#2006] Added sample cred files X-Git-Tag: Kea-2.1.2~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b398aa4842dd4e277dbf51691da72ea82df23730;p=thirdparty%2Fkea.git [#2006] Added sample cred files --- diff --git a/doc/examples/agent/simple.json b/doc/examples/agent/simple.json index 0bb6aa23cb..9264cac37c 100644 --- a/doc/examples/agent/simple.json +++ b/doc/examples/agent/simple.json @@ -29,7 +29,7 @@ // This optional parameter can be used to specify a common // prefix for files handling client credentials. - "directory": "/tmp/ca", + "directory": "/tmp/kea-creds", // This list specifies the user ids and passwords to use for // basic HTTP authentication. If empty or not present any client @@ -46,7 +46,7 @@ // If password is not specified an empty password is used. "password": "1234" - }/* temporary disabled because it requires files , + }, // This specifies a hiddent client. { @@ -62,7 +62,7 @@ // The secret is the content of the file /tmp/ca/hiddens // which must be in the : format. "password-file": "hiddens" - }*/ + } ] }, diff --git a/src/bin/agent/tests/get_config_unittest.cc b/src/bin/agent/tests/get_config_unittest.cc index 2d557294ed..09fc0fc7e2 100644 --- a/src/bin/agent/tests/get_config_unittest.cc +++ b/src/bin/agent/tests/get_config_unittest.cc @@ -109,6 +109,18 @@ pathReplacer(ConstElementPtr ca_cfg) { first_lib->set("library", Element::create(lib_path)); } +/// @brief Replace the credential directory +void +dirReplacer(ConstElementPtr ca_cfg) { + ConstElementPtr auth = ca_cfg->get("authentication"); + if (!auth || auth->empty()) { + return; + } + ElementPtr mutable_auth = boost::const_pointer_cast(auth); + std::string dir_path(CA_TEST_DATA_DIR); + mutable_auth->set("directory", Element::create(dir_path)); +} + /// @brief Almost regular agent CfgMgr with internal parse method exposed. class NakedAgentCfgMgr : public CtrlAgentCfgMgr { public: @@ -174,6 +186,9 @@ public: // update hooks-libraries pathReplacer(ca); + // update authentication directory + dirReplacer(ca); + // try AGENT configure ConstElementPtr status; try { @@ -265,11 +280,12 @@ TEST_F(CtrlAgentGetCfgTest, simple) { ASSERT_NO_THROW(jsonj = parseJSON(expected)); // the generic JSON parser does not handle comments EXPECT_TRUE(isEquivalent(jsond, moveComments(jsonj))); - // replace the path by its actual value + // replace the paths by their actual values ConstElementPtr ca; ASSERT_NO_THROW(ca = jsonj->get("Control-agent")); ASSERT_TRUE(ca); pathReplacer(ca); + dirReplacer(ca); // check that unparsed and updated expected values match EXPECT_TRUE(isEquivalent(unparsed, jsonj)); // check on pretty prints too diff --git a/src/bin/agent/tests/testdata/get_config.json b/src/bin/agent/tests/testdata/get_config.json index f1b5376667..ce3df5433e 100644 --- a/src/bin/agent/tests/testdata/get_config.json +++ b/src/bin/agent/tests/testdata/get_config.json @@ -8,9 +8,16 @@ "user-context": { "comment": "admin is authorized" } + }, + { + "password-file": "hiddenp", + "user-file": "hiddenu" + }, + { + "password-file": "hiddens" } ], - "directory": "/tmp/ca", + "directory": "/tmp/kea-creds", "realm": "kea-control-agent", "type": "basic" }, diff --git a/src/bin/agent/tests/testdata/hiddenp b/src/bin/agent/tests/testdata/hiddenp new file mode 100644 index 0000000000..beb2d2fb11 --- /dev/null +++ b/src/bin/agent/tests/testdata/hiddenp @@ -0,0 +1 @@ +KeaTest diff --git a/src/bin/agent/tests/testdata/hiddens b/src/bin/agent/tests/testdata/hiddens new file mode 100644 index 0000000000..2c2e06d8c0 --- /dev/null +++ b/src/bin/agent/tests/testdata/hiddens @@ -0,0 +1 @@ +kea:test diff --git a/src/bin/agent/tests/testdata/hiddenu b/src/bin/agent/tests/testdata/hiddenu new file mode 100644 index 0000000000..eadbb15e84 --- /dev/null +++ b/src/bin/agent/tests/testdata/hiddenu @@ -0,0 +1 @@ +keatest