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.
This commit is contained in:
Colin Vidal 2025-08-19 14:45:56 +02:00
parent 260bbc24c9
commit ced276b266
8 changed files with 58 additions and 14 deletions

View file

@ -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; };

View file

@ -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;
};

View file

@ -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;
};
};

View file

@ -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;
};
};

View file

@ -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";
};

View file

@ -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);

View file

@ -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);

View file

@ -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;
};
};