From: Petr Menšík Date: Tue, 20 Jul 2021 17:34:42 +0000 (+0200) Subject: Check parsed resconf values X-Git-Tag: v9.17.18~39^2~1 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=48d5b503137aebffeb5d3374a1bb48e5cbbc7793;p=thirdparty%2Fbind9.git Check parsed resconf values Add 'attempts' check, fix 'ndots' data. Create a bunch of verification functions and check parsed values, not just return codes. --- diff --git a/lib/irs/tests/resconf_test.c b/lib/irs/tests/resconf_test.c index 8ca9762bffa..4befe01f15b 100644 --- a/lib/irs/tests/resconf_test.c +++ b/lib/irs/tests/resconf_test.c @@ -42,6 +42,43 @@ setup_test(void) { assert_return_code(chdir(TESTS_DIR), 0); } +static isc_result_t +check_number(unsigned int n, unsigned int expected) { + return ((n == expected) ? ISC_R_SUCCESS : ISC_R_BADNUMBER); +} + +static isc_result_t +check_attempts(irs_resconf_t *resconf) { + return (check_number(irs_resconf_getattempts(resconf), 4)); +} + +static isc_result_t +check_timeout(irs_resconf_t *resconf) { + return (check_number(irs_resconf_gettimeout(resconf), 1)); +} + +static isc_result_t +check_ndots(irs_resconf_t *resconf) { + return (check_number(irs_resconf_getndots(resconf), 2)); +} + +static isc_result_t +check_options(irs_resconf_t *resconf) { + if (irs_resconf_getattempts(resconf) != 3) { + return ISC_R_BADNUMBER; /* default value only */ + } + + if (irs_resconf_getndots(resconf) != 2) { + return ISC_R_BADNUMBER; + } + + if (irs_resconf_gettimeout(resconf) != 1) { + return ISC_R_BADNUMBER; + } + + return (ISC_R_SUCCESS); +} + /* test irs_resconf_load() */ static void irs_resconf_load_test(void **state) { @@ -61,15 +98,18 @@ irs_resconf_load_test(void **state) { ISC_R_SUCCESS }, { "testdata/nameserver-v6-scoped.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS }, + { "testdata/options-attempts.conf", ISC_R_SUCCESS, + check_attempts, ISC_R_SUCCESS }, { "testdata/options-debug.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS }, - { "testdata/options-ndots.conf", ISC_R_SUCCESS, NULL, + { "testdata/options-ndots.conf", ISC_R_SUCCESS, check_ndots, ISC_R_SUCCESS }, - { "testdata/options-timeout.conf", ISC_R_SUCCESS, NULL, + { "testdata/options-timeout.conf", ISC_R_SUCCESS, check_timeout, 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.conf", ISC_R_SUCCESS, check_options, + ISC_R_SUCCESS }, { "testdata/options-bad-ndots.conf", ISC_R_RANGE, NULL, ISC_R_SUCCESS }, { "testdata/options-empty.conf", ISC_R_UNEXPECTEDEND, NULL, diff --git a/lib/irs/tests/testdata/options-attempts.conf b/lib/irs/tests/testdata/options-attempts.conf new file mode 100644 index 00000000000..453864331d1 --- /dev/null +++ b/lib/irs/tests/testdata/options-attempts.conf @@ -0,0 +1,10 @@ +# Copyright (C) Internet Systems Consortium, Inc. ("ISC") +# +# 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 attempts:4 diff --git a/lib/irs/tests/testdata/options-ndots.conf b/lib/irs/tests/testdata/options-ndots.conf index ff4c7e99ee9..58b21b9f820 100644 --- a/lib/irs/tests/testdata/options-ndots.conf +++ b/lib/irs/tests/testdata/options-ndots.conf @@ -7,4 +7,4 @@ # See the COPYRIGHT file distributed with this work for additional # information regarding copyright ownership. -option ndots:2 +options ndots:2