]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
test for namedconf zone plugin support
authorColin Vidal <colin@isc.org>
Mon, 26 May 2025 14:55:26 +0000 (16:55 +0200)
committerColin Vidal <colin@isc.org>
Tue, 9 Sep 2025 07:42:34 +0000 (09:42 +0200)
add a system test, using a dummy plugin, to test named.conf
validation of a plugin inside a zone definition.

bin/tests/system/hooks/conf/bad-topviewlevel.conf [new file with mode: 0644]
bin/tests/system/hooks/conf/good-toplevel.conf [new file with mode: 0644]
bin/tests/system/hooks/conf/good-viewlevel.conf [new file with mode: 0644]
bin/tests/system/hooks/conf/good-viewzonelevel.conf [new file with mode: 0644]
bin/tests/system/hooks/conf/good-zonelevel.conf [new file with mode: 0644]
bin/tests/system/hooks/driver/test-syncplugin.c [new file with mode: 0644]
bin/tests/system/hooks/tests.sh [new file with mode: 0644]
bin/tests/system/hooks/tests_hooks.py
bin/tests/system/meson.build
meson.build

diff --git a/bin/tests/system/hooks/conf/bad-topviewlevel.conf b/bin/tests/system/hooks/conf/bad-topviewlevel.conf
new file mode 100644 (file)
index 0000000..b5b267a
--- /dev/null
@@ -0,0 +1,4 @@
+view foo {
+       plugin query "driver/.libs/test-syncplugin.so";
+};
+plugin query "driver/.libs/test-syncplugin.so";
diff --git a/bin/tests/system/hooks/conf/good-toplevel.conf b/bin/tests/system/hooks/conf/good-toplevel.conf
new file mode 100644 (file)
index 0000000..ebfd44a
--- /dev/null
@@ -0,0 +1 @@
+plugin query "driver/.libs/test-syncplugin.so";
diff --git a/bin/tests/system/hooks/conf/good-viewlevel.conf b/bin/tests/system/hooks/conf/good-viewlevel.conf
new file mode 100644 (file)
index 0000000..24668bd
--- /dev/null
@@ -0,0 +1,3 @@
+view foo {
+       plugin query "driver/.libs/test-syncplugin.so";
+};
diff --git a/bin/tests/system/hooks/conf/good-viewzonelevel.conf b/bin/tests/system/hooks/conf/good-viewzonelevel.conf
new file mode 100644 (file)
index 0000000..41d4d4e
--- /dev/null
@@ -0,0 +1,8 @@
+view someview {
+       zone "foo.bar" {
+               plugin query "driver/.libs/test-syncplugin.so";
+               type primary;
+               file "foo.bar.db";
+       };
+       plugin query "driver/.libs/test-syncplugin.so";
+};
diff --git a/bin/tests/system/hooks/conf/good-zonelevel.conf b/bin/tests/system/hooks/conf/good-zonelevel.conf
new file mode 100644 (file)
index 0000000..d4e546b
--- /dev/null
@@ -0,0 +1,5 @@
+zone "foo.bar" {
+       plugin query "driver/.libs/test-syncplugin.so";
+       type primary;
+       file "foo.bar.db";
+};
diff --git a/bin/tests/system/hooks/driver/test-syncplugin.c b/bin/tests/system/hooks/driver/test-syncplugin.c
new file mode 100644 (file)
index 0000000..52fd183
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+ *
+ * SPDX-License-Identifier: MPL-2.0
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+#include <isccfg/aclconf.h>
+#include <isccfg/cfg.h>
+#include <isccfg/grammar.h>
+
+#include <ns/hooks.h>
+
+static ns_hookresult_t
+syncplugin_hook(void *arg, void *cbdata, isc_result_t *resp) {
+       UNUSED(arg);
+       UNUSED(cbdata);
+       UNUSED(resp);
+
+       return NS_HOOK_CONTINUE;
+}
+
+isc_result_t
+plugin_register(const char *parameters, const void *cfg, const char *cfgfile,
+               unsigned long cfgline, isc_mem_t *mctx, void *actx,
+               ns_hooktable_t *hooktable, void **instp) {
+       ns_hook_t hook;
+
+       UNUSED(parameters);
+       UNUSED(cfg);
+       UNUSED(cfgfile);
+       UNUSED(cfgline);
+       UNUSED(mctx);
+       UNUSED(actx);
+       UNUSED(hooktable);
+       UNUSED(instp);
+
+       hook = (ns_hook_t){ .action = syncplugin_hook,
+                           .action_data = NULL };
+       ns_hook_add(hooktable, mctx, NS_QUERY_NODATA_BEGIN, &hook);
+
+       return ISC_R_SUCCESS;
+}
+
+isc_result_t
+plugin_check(const char *parameters, const void *cfg, const char *cfgfile,
+            unsigned long cfgline, isc_mem_t *mctx, void *actx) {
+       UNUSED(parameters);
+       UNUSED(cfg);
+       UNUSED(cfgfile);
+       UNUSED(cfgline);
+       UNUSED(mctx);
+       UNUSED(actx);
+
+       return ISC_R_SUCCESS;
+}
+
+void
+plugin_destroy(void **instp) {
+       UNUSED(instp);
+}
+
+int
+plugin_version(void) {
+       return NS_PLUGIN_VERSION;
+}
diff --git a/bin/tests/system/hooks/tests.sh b/bin/tests/system/hooks/tests.sh
new file mode 100644 (file)
index 0000000..d54383b
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0.  If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+set -e
+
+. ../conf.sh
+
+status=0
+n=0
+
+for conf in conf/good*.conf; do
+  n=$((n + 1))
+  echo_i "checking that $conf is accepted ($n)"
+  ret=0
+  $CHECKCONF "$conf" || ret=1
+  if [ $ret != 0 ]; then echo_i "failed"; fi
+  status=$((status + ret))
+done
+
+for conf in conf/bad*.conf; do
+  n=$((n + 1))
+  echo_i "checking that $conf is rejected ($n)"
+  ret=0
+  $CHECKCONF "$conf" >/dev/null && ret=1
+  if [ $ret != 0 ]; then echo_i "failed"; fi
+  status=$((status + ret))
+done
+
+echo_i "exit status: $status"
+[ $status -eq 0 ] || exit 1
index 5de435825921c5b58ace89b09d443f0e23c3de65..98c23bf216ec1ddc91eca43768c3d831c4c69cb4 100644 (file)
@@ -25,3 +25,7 @@ def test_hooks_noextension(ns1, templates):
         ns1.rndc("reload")
         watcher.wait_for_line("all zones loaded")
     test_hooks()
+
+
+def test_plugins_config(run_tests_sh):
+    run_tests_sh()
index 88dfbd1e22e7278b24a0c6325ce3aa21c1a84a6a..bb81c5e9c9ddbc47a0f3954e9298d1027794c63b 100644 (file)
@@ -29,6 +29,7 @@ system_test_binaries += {
 
 system_test_libraries += {
     'driver-async': files('hooks' / 'driver' / 'test-async.c'),
+    'driver-syncplugin': files('hooks' / 'driver' / 'test-syncplugin.c'),
     'driver-dlzexternal': files('dlzexternal' / 'driver' / 'driver.c'),
     'driver-sample': files(
         'dyndb' / 'driver' / 'db.c',
index eec81a50014f1e8c4006fdff7a7ce1c5bd53f3fb..97097435c080e3b1a0d7f9994b00a24ef9f5b73f 100644 (file)
@@ -1662,6 +1662,7 @@ foreach name, sources : system_test_libraries
         dependencies: [
             libdns_dep,
             libisc_dep,
+            libisccfg_dep,
             libns_dep,
         ],
     )