]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3477] Addressed auth parsing issue
authorFrancis Dupont <fdupont@isc.org>
Mon, 22 Jul 2024 21:32:22 +0000 (23:32 +0200)
committerFrancis Dupont <fdupont@isc.org>
Thu, 1 Aug 2024 07:23:54 +0000 (09:23 +0200)
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc

index f9a193aa05e5f3aa7618eb76a0f7d56f55f258b3..9161acf841361d3eeb146f49b43a00de53e02081 100644 (file)
@@ -2873,6 +2873,37 @@ void removeTlsParameters(ConstElementPtr elem) {
     }
 }
 
+/// @brief Remove authentication filess
+void removeAuthFiles(ConstElementPtr elem) {
+    if (!elem) {
+        return;
+    }
+    ConstElementPtr auth = elem->get("authentication");
+    if (!auth) {
+        return;
+    }
+    ConstElementPtr clients = auth->get("clients");
+    if (!clients || clients->empty()) {
+        return;
+    }
+    ElementPtr mutable_clients = boost::const_pointer_cast<Element>(clients);
+    for (;;) {
+        bool found = false;
+        for (int i = 0; i < clients->size(); ++i) {
+            ConstElementPtr client = clients->get(i);
+            if (client->contains("user-file") ||
+                client->contains("password-file")) {
+                mutable_clients->remove(i);
+                found = true;
+                break;
+            }
+        }
+        if (!found) {
+            return;
+        }
+    }
+}
+
 void
 Dhcpv4SrvTest::loadConfigFile(const string& path) {
     CfgMgr::instance().clear();
@@ -2914,6 +2945,21 @@ Dhcpv4SrvTest::loadConfigFile(const string& path) {
             removeTlsParameters(host);
         }
     }
+    // Remove TLS parameters and authentication.
+    ConstElementPtr control_sockets = dhcp4->get("control-socket");
+    if (control_sockets) {
+        removeTlsParameters(control_sockets);
+        removeAuthFiles(control_sockets);
+    }
+    control_sockets = dhcp4->get("control-sockets");
+    if (control_sockets) {
+        for (int i = 0; i < control_sockets->size(); ++i) {
+            ConstElementPtr control_socket = control_sockets->get(i);
+            removeTlsParameters(control_socket);
+            removeAuthFiles(control_socket);
+        }
+    }
+
     ASSERT_NO_THROW(Dhcpv4SrvTest::configure(dhcp4->str(), true, true, true, true));
 
     LeaseMgrFactory::destroy();
index ca73c0e4f03d079b02a538374ca8c9eb000c6ad7..503f23e613e5088bc4395ce5583805a17b66d1c6 100644 (file)
@@ -237,6 +237,37 @@ void removeTlsParameters(ConstElementPtr elem) {
     }
 }
 
+/// @brief Remove authentication filess
+void removeAuthFiles(ConstElementPtr elem) {
+    if (!elem) {
+        return;
+    }
+    ConstElementPtr auth = elem->get("authentication");
+    if (!auth) {
+        return;
+    }
+    ConstElementPtr clients = auth->get("clients");
+    if (!clients || clients->empty()) {
+        return;
+    }
+    ElementPtr mutable_clients = boost::const_pointer_cast<Element>(clients);
+    for (;;) {
+        bool found = false;
+        for (int i = 0; i < clients->size(); ++i) {
+            ConstElementPtr client = clients->get(i);
+            if (client->contains("user-file") ||
+                client->contains("password-file")) {
+                mutable_clients->remove(i);
+                found = true;
+                break;
+            }
+        }
+        if (!found) {
+            return;
+        }
+    }
+}
+
 void
 Dhcpv6SrvTest::loadConfigFile(const string& path) {
     CfgMgr::instance().clear();
@@ -278,6 +309,21 @@ Dhcpv6SrvTest::loadConfigFile(const string& path) {
             removeTlsParameters(host);
         }
     }
+    // Remove TLS parameters and authentication.
+    ConstElementPtr control_sockets = dhcp6->get("control-socket");
+    if (control_sockets) {
+        removeTlsParameters(control_sockets);
+        removeAuthFiles(control_sockets);
+    }
+    control_sockets = dhcp6->get("control-sockets");
+    if (control_sockets) {
+        for (int i = 0; i < control_sockets->size(); ++i) {
+            ConstElementPtr control_socket = control_sockets->get(i);
+            removeTlsParameters(control_socket);
+            removeAuthFiles(control_socket);
+        }
+    }
+
     ASSERT_NO_THROW(Dhcpv6SrvTest::configure(dhcp6->str(), true, true, true, true));
 
     LeaseMgrFactory::destroy();