]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2006] Added sample cred files
authorFrancis Dupont <fdupont@isc.org>
Tue, 7 Dec 2021 14:42:29 +0000 (15:42 +0100)
committerRazvan Becheriu <razvan@isc.org>
Fri, 21 Jan 2022 17:15:38 +0000 (17:15 +0000)
doc/examples/agent/simple.json
src/bin/agent/tests/get_config_unittest.cc
src/bin/agent/tests/testdata/get_config.json
src/bin/agent/tests/testdata/hiddenp [new file with mode: 0644]
src/bin/agent/tests/testdata/hiddens [new file with mode: 0644]
src/bin/agent/tests/testdata/hiddenu [new file with mode: 0644]

index 0bb6aa23cbc902ff9e2eb719968d5f8bc2977257..9264cac37cf741b3292064a04737e23d1b99462e 100644 (file)
@@ -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 <user-id>:<password> format.
                     "password-file": "hiddens"
-                }*/
+                }
             ]
         },
 
index 2d557294edc44429e4fb80b3dac5758099751f18..09fc0fc7e2611237d0a642349347d67c5ac1f60c 100644 (file)
@@ -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<Element>(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
index f1b5376667cdc95d349c47056bd1faa63ab87017..ce3df5433ed1899cf0dda12458bfe44ec053ee7e 100644 (file)
@@ -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 (file)
index 0000000..beb2d2f
--- /dev/null
@@ -0,0 +1 @@
+KeaTest
diff --git a/src/bin/agent/tests/testdata/hiddens b/src/bin/agent/tests/testdata/hiddens
new file mode 100644 (file)
index 0000000..2c2e06d
--- /dev/null
@@ -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 (file)
index 0000000..eadbb15
--- /dev/null
@@ -0,0 +1 @@
+keatest