48bb18e175
Resolves rhbz#2087156
114 lines
3.8 KiB
Diff
114 lines
3.8 KiB
Diff
From 7270604440268bb17b39ae734ff33003a67c8343 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
|
|
Date: Tue, 20 Jul 2021 19:34:42 +0200
|
|
Subject: [PATCH] Check parsed resconf values
|
|
|
|
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 | 46 ++++++++++++++++++--
|
|
lib/irs/tests/testdata/options-attempts.conf | 10 +++++
|
|
lib/irs/tests/testdata/options-ndots.conf | 2 +-
|
|
3 files changed, 54 insertions(+), 4 deletions(-)
|
|
create mode 100644 lib/irs/tests/testdata/options-attempts.conf
|
|
|
|
diff --git a/lib/irs/tests/resconf_test.c b/lib/irs/tests/resconf_test.c
|
|
index 6951758..ce94345 100644
|
|
--- a/lib/irs/tests/resconf_test.c
|
|
+++ b/lib/irs/tests/resconf_test.c
|
|
@@ -45,6 +45,43 @@ setup_test() {
|
|
assert_return_code(chdir(TESTS), 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) {
|
|
@@ -64,15 +101,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 0000000..4538643
|
|
--- /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 5d18d26..f37c712 100644
|
|
--- a/lib/irs/tests/testdata/options-ndots.conf
|
|
+++ b/lib/irs/tests/testdata/options-ndots.conf
|
|
@@ -9,4 +9,4 @@
|
|
# See the COPYRIGHT file distributed with this work for additional
|
|
# information regarding copyright ownership.
|
|
|
|
-option ndots:2
|
|
+options ndots:2
|
|
--
|
|
2.35.3
|
|
|