From: Colin Vidal Date: Tue, 19 Aug 2025 12:45:56 +0000 (+0200) Subject: add unit test for plugin_register source param X-Git-Tag: v9.21.14~56^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ced276b26614805b252e37a3b041bcb6bd09ab3f;p=thirdparty%2Fbind9.git add unit test for plugin_register source param Update the existing test's syncplugin plugin with a new parameter indicating whether the plugin should be loaded in a view or a zone. If it doesn't match where the plugin is actually loaded, it fails the initialization. This covers the correctless of the `source` parameter of `plugin_register` API. --- diff --git a/bin/tests/system/hooks/conf/bad-topviewlevel.conf.j2 b/bin/tests/system/hooks/conf/bad-topviewlevel.conf.j2 index 9e7338dbd76..7e213436cb8 100644 --- a/bin/tests/system/hooks/conf/bad-topviewlevel.conf.j2 +++ b/bin/tests/system/hooks/conf/bad-topviewlevel.conf.j2 @@ -12,6 +12,10 @@ */ view foo { - plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { rcode servfail; }; + plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" { + rcode servfail; + }; +}; +plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" { + rcode servfail; }; -plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { rcode servfail; }; diff --git a/bin/tests/system/hooks/conf/good-toplevel.conf.j2 b/bin/tests/system/hooks/conf/good-toplevel.conf.j2 index 3e416a6c6a4..9064bf4116d 100644 --- a/bin/tests/system/hooks/conf/good-toplevel.conf.j2 +++ b/bin/tests/system/hooks/conf/good-toplevel.conf.j2 @@ -11,4 +11,6 @@ * information regarding copyright ownership. */ -plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { rcode servfail; }; +plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" { + rcode servfail; +}; diff --git a/bin/tests/system/hooks/conf/good-viewlevel.conf.j2 b/bin/tests/system/hooks/conf/good-viewlevel.conf.j2 index 7efc0a175de..4e1a2d64bda 100644 --- a/bin/tests/system/hooks/conf/good-viewlevel.conf.j2 +++ b/bin/tests/system/hooks/conf/good-viewlevel.conf.j2 @@ -12,5 +12,7 @@ */ view foo { - plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { rcode servfail; }; + plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" { + rcode servfail; + }; }; diff --git a/bin/tests/system/hooks/conf/good-viewzonelevel.conf.j2 b/bin/tests/system/hooks/conf/good-viewzonelevel.conf.j2 index a1b0f2cf46e..7d992824cda 100644 --- a/bin/tests/system/hooks/conf/good-viewzonelevel.conf.j2 +++ b/bin/tests/system/hooks/conf/good-viewzonelevel.conf.j2 @@ -13,9 +13,13 @@ view someview { zone "foo.bar" { - plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { rcode servfail; }; + plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" { + rcode servfail; + }; type primary; file "foo.bar.db"; }; - plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { rcode servfail; }; + plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { + rcode servfail; + }; }; diff --git a/bin/tests/system/hooks/conf/good-zonelevel.conf.j2 b/bin/tests/system/hooks/conf/good-zonelevel.conf.j2 index 133ef864d7b..cf8162193d0 100644 --- a/bin/tests/system/hooks/conf/good-zonelevel.conf.j2 +++ b/bin/tests/system/hooks/conf/good-zonelevel.conf.j2 @@ -12,7 +12,9 @@ */ zone "foo.bar" { - plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { rcode servfail; }; + plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" { + rcode servfail; + }; type primary; file "foo.bar.db"; }; diff --git a/bin/tests/system/hooks/driver/test-async.c b/bin/tests/system/hooks/driver/test-async.c index d6b9faa25e8..4cc8ef79431 100644 --- a/bin/tests/system/hooks/driver/test-async.c +++ b/bin/tests/system/hooks/driver/test-async.c @@ -125,9 +125,11 @@ logmsg(const char *fmt, ...) { isc_result_t plugin_register(const char *parameters, const void *cfg, const char *cfg_file, unsigned long cfg_line, isc_mem_t *mctx, void *actx, - ns_hooktable_t *hooktable, void **instp) { + ns_hooktable_t *hooktable, ns_hooksource_t source, + void **instp) { async_instance_t *inst = NULL; + UNUSED(source); UNUSED(parameters); UNUSED(cfg); UNUSED(actx); diff --git a/bin/tests/system/hooks/driver/test-syncplugin.c b/bin/tests/system/hooks/driver/test-syncplugin.c index 1d082900b66..4ab4be49668 100644 --- a/bin/tests/system/hooks/driver/test-syncplugin.c +++ b/bin/tests/system/hooks/driver/test-syncplugin.c @@ -67,6 +67,7 @@ syncplugin__hook(void *arg, void *cbdata, isc_result_t *resp) { static cfg_clausedef_t syncplugin__cfgclauses[] = { { "rcode", &cfg_type_astring, 0 }, + { "source", &cfg_type_astring, 0 }, { "firstlbl", &cfg_type_qstring, CFG_CLAUSEFLAG_OPTIONAL } }; @@ -112,7 +113,8 @@ syncplugin__parse_rcode(const cfg_obj_t *syncplugincfg, uint8_t *rcode) { 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_hooktable_t *hooktable, ns_hooksource_t source, + void **instp) { isc_result_t result; cfg_parser_t *parser = NULL; cfg_obj_t *syncplugincfg = NULL; @@ -120,9 +122,11 @@ plugin_register(const char *parameters, const void *cfg, const char *cfgfile, isc_buffer_t b; ns_hook_t hook; syncplugin_t *inst = NULL; + char *sourcestr = NULL; UNUSED(cfg); UNUSED(actx); + UNUSED(source); inst = isc_mem_get(mctx, sizeof(*inst)); *inst = (syncplugin_t){ .mctx = mctx }; @@ -146,6 +150,25 @@ plugin_register(const char *parameters, const void *cfg, const char *cfgfile, strncpy(inst->firstlbl, firstlbl, len); } + obj = NULL; + CHECK(cfg_map_get(syncplugincfg, "source", &obj)); + sourcestr = obj->value.string.base; + + if (strcmp(sourcestr, "zone") == 0) { + if (source != NS_HOOKSOURCE_ZONE) { + result = ISC_R_FAILURE; + goto cleanup; + } + } else if (strcmp(sourcestr, "view") == 0) { + if (source != NS_HOOKSOURCE_VIEW) { + result = ISC_R_FAILURE; + goto cleanup; + } + } else { + result = ISC_R_FAILURE; + goto cleanup; + } + hook = (ns_hook_t){ .action = syncplugin__hook, .action_data = inst }; ns_hook_add(hooktable, mctx, NS_QUERY_NXDOMAIN_BEGIN, &hook); diff --git a/bin/tests/system/hooks/ns2/named.conf.j2 b/bin/tests/system/hooks/ns2/named.conf.j2 index 35431d89142..87678738cee 100644 --- a/bin/tests/system/hooks/ns2/named.conf.j2 +++ b/bin/tests/system/hooks/ns2/named.conf.j2 @@ -35,8 +35,9 @@ controls { inet 10.53.0.2 port @CONTROLPORT@ allow { any; } keys { rndc_key; }; }; -plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { +plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" { rcode noerror; + source view; }; zone "example.com" { @@ -47,31 +48,35 @@ zone "example.com" { zone "example2.com" { type primary; file "example.db"; - plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { + plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" { rcode servfail; + source zone; }; }; zone "example3.com" { type primary; file "example.db"; - plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { + plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" { rcode notimp; + source zone; }; }; template exampletmpl { type primary; file "$name.db"; - plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { + plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" { rcode notauth; firstlbl "skipfoo"; + source zone; }; }; zone "example4.com" { template exampletmpl; - plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { + plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" { rcode notzone; + source zone; }; };