]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Check parsed resconf values
authorPetr Menšík <pemensik@redhat.com>
Tue, 20 Jul 2021 17:34:42 +0000 (19:34 +0200)
committerEvan Hunt <each@isc.org>
Thu, 12 Aug 2021 16:52:52 +0000 (09:52 -0700)
Add 'attempts' check, fix 'ndots' data. Create a bunch of verification
functions and check parsed values, not just return codes.

lib/irs/tests/resconf_test.c
lib/irs/tests/testdata/options-attempts.conf [new file with mode: 0644]
lib/irs/tests/testdata/options-ndots.conf

index 8ca9762bffaae06983bace6574f1de16826acea4..4befe01f15be673b4221bb00216ca1380da648f2 100644 (file)
@@ -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 (file)
index 0000000..4538643
--- /dev/null
@@ -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
index ff4c7e99ee936414460f8234175390e77208df95..58b21b9f820a5f64bf3c75aa3d239ad86a80662e 100644 (file)
@@ -7,4 +7,4 @@
 # See the COPYRIGHT file distributed with this work for additional
 # information regarding copyright ownership.
 
-option ndots:2
+options ndots:2