Blame bind-9.16-resolv.conf-options-timeout-test.patch

48bb18
From 7270604440268bb17b39ae734ff33003a67c8343 Mon Sep 17 00:00:00 2001
48bb18
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
48bb18
Date: Tue, 20 Jul 2021 19:34:42 +0200
48bb18
Subject: [PATCH] Check parsed resconf values
48bb18
48bb18
Add 'attempts' check, fix 'ndots' data. Create a bunch of verification
48bb18
functions and check parsed values, not just return codes.
48bb18
---
48bb18
 lib/irs/tests/resconf_test.c                 | 46 ++++++++++++++++++--
48bb18
 lib/irs/tests/testdata/options-attempts.conf | 10 +++++
48bb18
 lib/irs/tests/testdata/options-ndots.conf    |  2 +-
48bb18
 3 files changed, 54 insertions(+), 4 deletions(-)
48bb18
 create mode 100644 lib/irs/tests/testdata/options-attempts.conf
48bb18
48bb18
diff --git a/lib/irs/tests/resconf_test.c b/lib/irs/tests/resconf_test.c
48bb18
index 6951758..ce94345 100644
48bb18
--- a/lib/irs/tests/resconf_test.c
48bb18
+++ b/lib/irs/tests/resconf_test.c
48bb18
@@ -45,6 +45,43 @@ setup_test() {
48bb18
 	assert_return_code(chdir(TESTS), 0);
48bb18
 }
48bb18
 
48bb18
+static isc_result_t
48bb18
+check_number(unsigned int n, unsigned int expected) {
48bb18
+	return ((n == expected) ? ISC_R_SUCCESS : ISC_R_BADNUMBER);
48bb18
+}
48bb18
+
48bb18
+static isc_result_t
48bb18
+check_attempts(irs_resconf_t *resconf) {
48bb18
+	return (check_number(irs_resconf_getattempts(resconf), 4));
48bb18
+}
48bb18
+
48bb18
+static isc_result_t
48bb18
+check_timeout(irs_resconf_t *resconf) {
48bb18
+	return (check_number(irs_resconf_gettimeout(resconf), 1));
48bb18
+}
48bb18
+
48bb18
+static isc_result_t
48bb18
+check_ndots(irs_resconf_t *resconf) {
48bb18
+	return (check_number(irs_resconf_getndots(resconf), 2));
48bb18
+}
48bb18
+
48bb18
+static isc_result_t
48bb18
+check_options(irs_resconf_t *resconf) {
48bb18
+	if (irs_resconf_getattempts(resconf) != 3) {
48bb18
+		return ISC_R_BADNUMBER; /* default value only */
48bb18
+	}
48bb18
+
48bb18
+	if (irs_resconf_getndots(resconf) != 2) {
48bb18
+		return ISC_R_BADNUMBER;
48bb18
+	}
48bb18
+
48bb18
+	if (irs_resconf_gettimeout(resconf) != 1) {
48bb18
+		return ISC_R_BADNUMBER;
48bb18
+	}
48bb18
+
48bb18
+	return (ISC_R_SUCCESS);
48bb18
+}
48bb18
+
48bb18
 /* test irs_resconf_load() */
48bb18
 static void
48bb18
 irs_resconf_load_test(void **state) {
48bb18
@@ -64,15 +101,18 @@ irs_resconf_load_test(void **state) {
48bb18
 		  ISC_R_SUCCESS },
48bb18
 		{ "testdata/nameserver-v6-scoped.conf", ISC_R_SUCCESS, NULL,
48bb18
 		  ISC_R_SUCCESS },
48bb18
+		{ "testdata/options-attempts.conf", ISC_R_SUCCESS,
48bb18
+		  check_attempts, ISC_R_SUCCESS },
48bb18
 		{ "testdata/options-debug.conf", ISC_R_SUCCESS, NULL,
48bb18
 		  ISC_R_SUCCESS },
48bb18
-		{ "testdata/options-ndots.conf", ISC_R_SUCCESS, NULL,
48bb18
+		{ "testdata/options-ndots.conf", ISC_R_SUCCESS, check_ndots,
48bb18
 		  ISC_R_SUCCESS },
48bb18
-		{ "testdata/options-timeout.conf", ISC_R_SUCCESS, NULL,
48bb18
+		{ "testdata/options-timeout.conf", ISC_R_SUCCESS, check_timeout,
48bb18
 		  ISC_R_SUCCESS },
48bb18
 		{ "testdata/options-unknown.conf", ISC_R_SUCCESS, NULL,
48bb18
 		  ISC_R_SUCCESS },
48bb18
-		{ "testdata/options.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS },
48bb18
+		{ "testdata/options.conf", ISC_R_SUCCESS, check_options,
48bb18
+		  ISC_R_SUCCESS },
48bb18
 		{ "testdata/options-bad-ndots.conf", ISC_R_RANGE, NULL,
48bb18
 		  ISC_R_SUCCESS },
48bb18
 		{ "testdata/options-empty.conf", ISC_R_UNEXPECTEDEND, NULL,
48bb18
diff --git a/lib/irs/tests/testdata/options-attempts.conf b/lib/irs/tests/testdata/options-attempts.conf
48bb18
new file mode 100644
48bb18
index 0000000..4538643
48bb18
--- /dev/null
48bb18
+++ b/lib/irs/tests/testdata/options-attempts.conf
48bb18
@@ -0,0 +1,10 @@
48bb18
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
48bb18
+#
48bb18
+# This Source Code Form is subject to the terms of the Mozilla Public
48bb18
+# License, v. 2.0. If a copy of the MPL was not distributed with this
48bb18
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
48bb18
+#
48bb18
+# See the COPYRIGHT file distributed with this work for additional
48bb18
+# information regarding copyright ownership.
48bb18
+
48bb18
+options attempts:4
48bb18
diff --git a/lib/irs/tests/testdata/options-ndots.conf b/lib/irs/tests/testdata/options-ndots.conf
48bb18
index 5d18d26..f37c712 100644
48bb18
--- a/lib/irs/tests/testdata/options-ndots.conf
48bb18
+++ b/lib/irs/tests/testdata/options-ndots.conf
48bb18
@@ -9,4 +9,4 @@
48bb18
 # See the COPYRIGHT file distributed with this work for additional
48bb18
 # information regarding copyright ownership.
48bb18
 
48bb18
-option ndots:2
48bb18
+options ndots:2
48bb18
-- 
48bb18
2.35.3
48bb18