From: Colin Vidal Date: Mon, 26 May 2025 14:55:26 +0000 (+0200) Subject: test for namedconf zone plugin support X-Git-Tag: v9.21.14~56^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0247506ddc2c1b017b33dbb1f818314a62174052;p=thirdparty%2Fbind9.git test for namedconf zone plugin support add a system test, using a dummy plugin, to test named.conf validation of a plugin inside a zone definition. --- diff --git a/bin/tests/system/hooks/conf/bad-topviewlevel.conf b/bin/tests/system/hooks/conf/bad-topviewlevel.conf new file mode 100644 index 00000000000..b5b267adac8 --- /dev/null +++ b/bin/tests/system/hooks/conf/bad-topviewlevel.conf @@ -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 index 00000000000..ebfd44a9cc3 --- /dev/null +++ b/bin/tests/system/hooks/conf/good-toplevel.conf @@ -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 index 00000000000..24668bd8c25 --- /dev/null +++ b/bin/tests/system/hooks/conf/good-viewlevel.conf @@ -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 index 00000000000..41d4d4ecee7 --- /dev/null +++ b/bin/tests/system/hooks/conf/good-viewzonelevel.conf @@ -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 index 00000000000..d4e546bb364 --- /dev/null +++ b/bin/tests/system/hooks/conf/good-zonelevel.conf @@ -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 index 00000000000..52fd1835fcc --- /dev/null +++ b/bin/tests/system/hooks/driver/test-syncplugin.c @@ -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 +#include +#include + +#include + +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 index 00000000000..d54383b3850 --- /dev/null +++ b/bin/tests/system/hooks/tests.sh @@ -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 diff --git a/bin/tests/system/hooks/tests_hooks.py b/bin/tests/system/hooks/tests_hooks.py index 5de43582592..98c23bf216e 100644 --- a/bin/tests/system/hooks/tests_hooks.py +++ b/bin/tests/system/hooks/tests_hooks.py @@ -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() diff --git a/bin/tests/system/meson.build b/bin/tests/system/meson.build index 88dfbd1e22e..bb81c5e9c9d 100644 --- a/bin/tests/system/meson.build +++ b/bin/tests/system/meson.build @@ -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', diff --git a/meson.build b/meson.build index eec81a50014..97097435c08 100644 --- a/meson.build +++ b/meson.build @@ -1662,6 +1662,7 @@ foreach name, sources : system_test_libraries dependencies: [ libdns_dep, libisc_dep, + libisccfg_dep, libns_dep, ], )