diff options
Diffstat (limited to '')
-rw-r--r-- | lib/irs/tests/Kyuafile | 15 | ||||
-rw-r--r-- | lib/irs/tests/Makefile.in | 51 | ||||
-rw-r--r-- | lib/irs/tests/resconf_test.c | 142 | ||||
-rw-r--r-- | lib/irs/tests/testdata/domain.conf | 12 | ||||
-rw-r--r-- | lib/irs/tests/testdata/nameserver-v4.conf | 12 | ||||
-rw-r--r-- | lib/irs/tests/testdata/nameserver-v6-scoped.conf | 12 | ||||
-rw-r--r-- | lib/irs/tests/testdata/nameserver-v6.conf | 12 | ||||
-rw-r--r-- | lib/irs/tests/testdata/options-bad-ndots.conf | 13 | ||||
-rw-r--r-- | lib/irs/tests/testdata/options-debug.conf | 12 | ||||
-rw-r--r-- | lib/irs/tests/testdata/options-empty.conf | 13 | ||||
-rw-r--r-- | lib/irs/tests/testdata/options-ndots.conf | 12 | ||||
-rw-r--r-- | lib/irs/tests/testdata/options-timeout.conf | 12 | ||||
-rw-r--r-- | lib/irs/tests/testdata/options-unknown.conf | 12 | ||||
-rw-r--r-- | lib/irs/tests/testdata/options.conf | 12 | ||||
-rw-r--r-- | lib/irs/tests/testdata/port.conf | 12 | ||||
-rw-r--r-- | lib/irs/tests/testdata/resolv.conf | 19 | ||||
-rw-r--r-- | lib/irs/tests/testdata/search.conf | 12 | ||||
-rw-r--r-- | lib/irs/tests/testdata/sortlist-v4.conf | 12 | ||||
-rw-r--r-- | lib/irs/tests/testdata/timeout.conf | 12 | ||||
-rw-r--r-- | lib/irs/tests/testdata/unknown.conf | 12 |
20 files changed, 421 insertions, 0 deletions
diff --git a/lib/irs/tests/Kyuafile b/lib/irs/tests/Kyuafile new file mode 100644 index 0000000..a203172 --- /dev/null +++ b/lib/irs/tests/Kyuafile @@ -0,0 +1,15 @@ +-- 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. + +syntax(2) +test_suite('bind9') + +tap_test_program{name='resconf_test'} diff --git a/lib/irs/tests/Makefile.in b/lib/irs/tests/Makefile.in new file mode 100644 index 0000000..327d31d --- /dev/null +++ b/lib/irs/tests/Makefile.in @@ -0,0 +1,51 @@ +# 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. + +srcdir = @srcdir@ +VPATH = @srcdir@ +top_srcdir = @top_srcdir@ + +VERSION=@BIND9_VERSION@ + +@BIND9_MAKE_INCLUDES@ + +CINCLUDES = -I. -Iinclude -I../include ${ISC_INCLUDES} ${IRS_INCLUDES} @CMOCKA_CFLAGS@ +CDEFINES = -DTESTS="\"${top_builddir}/lib/irs/tests/\"" + +CFGLIBS = ../../isccfg/libisccfg.@A@ +CFGDEPLIBS = ../../isccfg/libisccfg.@A@ +DNSLIBS = ../../dns/libdns.@A@ @NO_LIBTOOL_DNSLIBS@ +DNSDEPLIBS = ../../dns/libdns.@A@ +ISCLIBS = ../../isc/libisc.@A@ @NO_LIBTOOL_ISCLIBS@ +ISCDEPLIBS = ../../isc/libisc.@A@ +IRSLIBS = ../libirs.@A@ +IRSDEPLIBS = ../libirs.@A@ + +LIBS = ${IRSLIBS} ${CFGLIBS} ${DNSLIBS} ${ISCLIBS} @LIBS@ @CMOCKA_LIBS@ + +OBJS = +SRCS = resconf_test.c + +SUBDIRS = +TARGETS = resconf_test@EXEEXT@ + +@BIND9_MAKE_RULES@ + +resconf_test@EXEEXT@: resconf_test.@O@ ${CFGDEPLIBS} ${DNSDEPLIBS} ${IRSDEPLIBS} ${ISCDEPLIBS} + ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \ + ${LDFLAGS} -o $@ resconf_test.@O@ ${LIBS} + +unit:: + sh ${top_builddir}/unit/unittest.sh + +clean distclean:: + rm -f ${TARGETS} + rm -f atf.out diff --git a/lib/irs/tests/resconf_test.c b/lib/irs/tests/resconf_test.c new file mode 100644 index 0000000..6951758 --- /dev/null +++ b/lib/irs/tests/resconf_test.c @@ -0,0 +1,142 @@ +/* + * 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. + */ + +#if HAVE_CMOCKA + +#include <sched.h> /* IWYU pragma: keep */ +#include <setjmp.h> +#include <stdarg.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#define UNIT_TESTING +#include <cmocka.h> + +#include <isc/mem.h> +#include <isc/util.h> + +#include <irs/resconf.h> +#include <irs/types.h> + +static isc_mem_t *mctx = NULL; + +static void +setup_test() { + isc_mem_create(&mctx); + + /* + * the caller might run from another directory, but tests + * that access test data files must first chdir to the proper + * location. + */ + assert_return_code(chdir(TESTS), 0); +} + +/* test irs_resconf_load() */ +static void +irs_resconf_load_test(void **state) { + isc_result_t result; + irs_resconf_t *resconf = NULL; + unsigned int i; + struct { + const char *file; + isc_result_t loadres; + isc_result_t (*check)(irs_resconf_t *resconf); + isc_result_t checkres; + } tests[] = { + { "testdata/domain.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS }, + { "testdata/nameserver-v4.conf", ISC_R_SUCCESS, NULL, + ISC_R_SUCCESS }, + { "testdata/nameserver-v6.conf", ISC_R_SUCCESS, NULL, + ISC_R_SUCCESS }, + { "testdata/nameserver-v6-scoped.conf", ISC_R_SUCCESS, NULL, + ISC_R_SUCCESS }, + { "testdata/options-debug.conf", ISC_R_SUCCESS, NULL, + ISC_R_SUCCESS }, + { "testdata/options-ndots.conf", ISC_R_SUCCESS, NULL, + ISC_R_SUCCESS }, + { "testdata/options-timeout.conf", ISC_R_SUCCESS, NULL, + ISC_R_SUCCESS }, + { "testdata/options-unknown.conf", ISC_R_SUCCESS, NULL, + ISC_R_SUCCESS }, + { "testdata/options.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS }, + { "testdata/options-bad-ndots.conf", ISC_R_RANGE, NULL, + ISC_R_SUCCESS }, + { "testdata/options-empty.conf", ISC_R_UNEXPECTEDEND, NULL, + ISC_R_SUCCESS }, + { "testdata/port.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS }, + { "testdata/resolv.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS }, + { "testdata/search.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS }, + { "testdata/sortlist-v4.conf", ISC_R_SUCCESS, NULL, + ISC_R_SUCCESS }, + { "testdata/timeout.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS }, + { "testdata/unknown.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS } + }; + + UNUSED(state); + + setup_test(); + + for (i = 0; i < sizeof(tests) / sizeof(tests[1]); i++) { + result = irs_resconf_load(mctx, tests[i].file, &resconf); + if (result != tests[i].loadres) { + fail_msg("# unexpected result %s loading %s", + isc_result_totext(result), tests[i].file); + } + + if (result == ISC_R_SUCCESS && resconf == NULL) { + fail_msg("# NULL on success loading %s", tests[i].file); + } else if (result != ISC_R_SUCCESS && resconf != NULL) { + fail_msg("# non-NULL on failure loading %s", + tests[i].file); + } + + if (resconf != NULL && tests[i].check != NULL) { + result = (tests[i].check)(resconf); + if (result != tests[i].checkres) { + fail_msg("# unexpected result %s loading %s", + isc_result_totext(result), + tests[i].file); + } + } + if (resconf != NULL) { + irs_resconf_destroy(&resconf); + } + } + + isc_mem_detach(&mctx); +} + +int +main(void) { + const struct CMUnitTest tests[] = { + cmocka_unit_test(irs_resconf_load_test), + }; + + return (cmocka_run_group_tests(tests, NULL, NULL)); +} + +#else /* HAVE_CMOCKA */ + +#include <stdio.h> + +int +main(void) { + printf("1..0 # Skipped: cmocka not available\n"); + return (SKIPPED_TEST_EXIT_CODE); +} + +#endif /* if HAVE_CMOCKA */ diff --git a/lib/irs/tests/testdata/domain.conf b/lib/irs/tests/testdata/domain.conf new file mode 100644 index 0000000..ee43f5c --- /dev/null +++ b/lib/irs/tests/testdata/domain.conf @@ -0,0 +1,12 @@ +# 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. + +domain example.com diff --git a/lib/irs/tests/testdata/nameserver-v4.conf b/lib/irs/tests/testdata/nameserver-v4.conf new file mode 100644 index 0000000..5054de0 --- /dev/null +++ b/lib/irs/tests/testdata/nameserver-v4.conf @@ -0,0 +1,12 @@ +# 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. + +nameserver 10.0.0.1 diff --git a/lib/irs/tests/testdata/nameserver-v6-scoped.conf b/lib/irs/tests/testdata/nameserver-v6-scoped.conf new file mode 100644 index 0000000..d5bd97f --- /dev/null +++ b/lib/irs/tests/testdata/nameserver-v6-scoped.conf @@ -0,0 +1,12 @@ +# 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. + +nameserver fe80::1%1 diff --git a/lib/irs/tests/testdata/nameserver-v6.conf b/lib/irs/tests/testdata/nameserver-v6.conf new file mode 100644 index 0000000..b9ed093 --- /dev/null +++ b/lib/irs/tests/testdata/nameserver-v6.conf @@ -0,0 +1,12 @@ +# 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. + +nameserver 2001:DB8::1 diff --git a/lib/irs/tests/testdata/options-bad-ndots.conf b/lib/irs/tests/testdata/options-bad-ndots.conf new file mode 100644 index 0000000..18d3f8b --- /dev/null +++ b/lib/irs/tests/testdata/options-bad-ndots.conf @@ -0,0 +1,13 @@ +# 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. + +search example.com example.net +options ndots:256 diff --git a/lib/irs/tests/testdata/options-debug.conf b/lib/irs/tests/testdata/options-debug.conf new file mode 100644 index 0000000..04bcf2e --- /dev/null +++ b/lib/irs/tests/testdata/options-debug.conf @@ -0,0 +1,12 @@ +# 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. + +options debug diff --git a/lib/irs/tests/testdata/options-empty.conf b/lib/irs/tests/testdata/options-empty.conf new file mode 100644 index 0000000..0b1dc9e --- /dev/null +++ b/lib/irs/tests/testdata/options-empty.conf @@ -0,0 +1,13 @@ +# 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. + +domain example.com +options diff --git a/lib/irs/tests/testdata/options-ndots.conf b/lib/irs/tests/testdata/options-ndots.conf new file mode 100644 index 0000000..5d18d26 --- /dev/null +++ b/lib/irs/tests/testdata/options-ndots.conf @@ -0,0 +1,12 @@ +# 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. + +option ndots:2 diff --git a/lib/irs/tests/testdata/options-timeout.conf b/lib/irs/tests/testdata/options-timeout.conf new file mode 100644 index 0000000..96787c4 --- /dev/null +++ b/lib/irs/tests/testdata/options-timeout.conf @@ -0,0 +1,12 @@ +# 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. + +options timeout:1 diff --git a/lib/irs/tests/testdata/options-unknown.conf b/lib/irs/tests/testdata/options-unknown.conf new file mode 100644 index 0000000..fdf82b4 --- /dev/null +++ b/lib/irs/tests/testdata/options-unknown.conf @@ -0,0 +1,12 @@ +# 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. + +options unknown diff --git a/lib/irs/tests/testdata/options.conf b/lib/irs/tests/testdata/options.conf new file mode 100644 index 0000000..7a8d5f3 --- /dev/null +++ b/lib/irs/tests/testdata/options.conf @@ -0,0 +1,12 @@ +# 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. + +options unknown debug timeout:1 ndots:2 diff --git a/lib/irs/tests/testdata/port.conf b/lib/irs/tests/testdata/port.conf new file mode 100644 index 0000000..54e2094 --- /dev/null +++ b/lib/irs/tests/testdata/port.conf @@ -0,0 +1,12 @@ +# 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. + +port 5300 diff --git a/lib/irs/tests/testdata/resolv.conf b/lib/irs/tests/testdata/resolv.conf new file mode 100644 index 0000000..3c14408 --- /dev/null +++ b/lib/irs/tests/testdata/resolv.conf @@ -0,0 +1,19 @@ +# 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. + +port 5300 +nameserver 10.0.0.1 +nameserver 2001:DB8::1 +search example.com example.net +sortlist 130.155.160.0/255.255.240.0 130.155.0.0 +timeout 10 +unknown directive +options unknown debug timeout:1 ndots:2 diff --git a/lib/irs/tests/testdata/search.conf b/lib/irs/tests/testdata/search.conf new file mode 100644 index 0000000..f019ab9 --- /dev/null +++ b/lib/irs/tests/testdata/search.conf @@ -0,0 +1,12 @@ +# 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. + +search example.com example.net diff --git a/lib/irs/tests/testdata/sortlist-v4.conf b/lib/irs/tests/testdata/sortlist-v4.conf new file mode 100644 index 0000000..3f4d54a --- /dev/null +++ b/lib/irs/tests/testdata/sortlist-v4.conf @@ -0,0 +1,12 @@ +# 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. + +sortlist 130.155.160.0/255.255.240.0 130.155.0.0 diff --git a/lib/irs/tests/testdata/timeout.conf b/lib/irs/tests/testdata/timeout.conf new file mode 100644 index 0000000..2ccb92d --- /dev/null +++ b/lib/irs/tests/testdata/timeout.conf @@ -0,0 +1,12 @@ +# 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. + +timeout 10 diff --git a/lib/irs/tests/testdata/unknown.conf b/lib/irs/tests/testdata/unknown.conf new file mode 100644 index 0000000..0eafb76 --- /dev/null +++ b/lib/irs/tests/testdata/unknown.conf @@ -0,0 +1,12 @@ +# 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. + +unknown directive |