From fb7366db3ebec021baf7297282bae190132fa883 Mon Sep 17 00:00:00 2001 From: Michal Nowak Date: Thu, 29 Feb 2024 18:25:38 +0100 Subject: [PATCH] Rewrite include-multiplecfg system test to pytest (cherry picked from commit e9e87533061d0e5ca1e976606e16ef9c4b276339) --- bin/tests/system/include-multiplecfg/clean.sh | 1 - .../include-multiplecfg/ns2/named.conf.in | 2 +- bin/tests/system/include-multiplecfg/tests.sh | 67 ------------------- .../tests_include_multiplecfg.py | 39 +++++++++++ .../tests_sh_include_multiplecfg.py | 14 ---- 5 files changed, 40 insertions(+), 83 deletions(-) delete mode 100644 bin/tests/system/include-multiplecfg/tests.sh create mode 100644 bin/tests/system/include-multiplecfg/tests_include_multiplecfg.py delete mode 100644 bin/tests/system/include-multiplecfg/tests_sh_include_multiplecfg.py diff --git a/bin/tests/system/include-multiplecfg/clean.sh b/bin/tests/system/include-multiplecfg/clean.sh index 905b2dd29a..62e1dcfd9d 100644 --- a/bin/tests/system/include-multiplecfg/clean.sh +++ b/bin/tests/system/include-multiplecfg/clean.sh @@ -15,7 +15,6 @@ # Clean up after allow query tests. # -rm -f dig.out.* rm -f ns*/named.conf rm -f */named.memstats rm -f ns*/named.lock diff --git a/bin/tests/system/include-multiplecfg/ns2/named.conf.in b/bin/tests/system/include-multiplecfg/ns2/named.conf.in index b38c228013..0dfe01d9a8 100644 --- a/bin/tests/system/include-multiplecfg/ns2/named.conf.in +++ b/bin/tests/system/include-multiplecfg/ns2/named.conf.in @@ -17,7 +17,7 @@ options { listen-on { 10.53.0.2; }; listen-on-v6 { none; }; recursion no; - notify no; + notify no; dnssec-validation no; }; diff --git a/bin/tests/system/include-multiplecfg/tests.sh b/bin/tests/system/include-multiplecfg/tests.sh deleted file mode 100644 index 8422417719..0000000000 --- a/bin/tests/system/include-multiplecfg/tests.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/sh - -# 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. - -# Test of include statement with glob expression. - -set -e - -. ../conf.sh - -DIGOPTS="+tcp +nosea +nostat +nocmd +norec +noques +noadd +nostats -p ${PORT}" - -status=0 -n=0 - -# Test 1 - check if zone1 was loaded. -n=$((n + 1)) -echo_i "checking glob include of zone1 config ($n)" -ret=0 -$DIG $DIGOPTS @10.53.0.2 -b 10.53.0.2 zone1.com. a >dig.out.ns2.$n || ret=1 -grep 'status: NOERROR' dig.out.ns2.$n >/dev/null || ret=1 -grep '^zone1.com.' dig.out.ns2.$n >/dev/null || ret=1 -if [ $ret != 0 ]; then echo_i "failed"; fi -status=$((status + ret)) - -# Test 2 - check if zone2 was loaded. -n=$((n + 1)) -echo_i "checking glob include of zone2 config ($n)" -ret=0 -$DIG $DIGOPTS @10.53.0.2 -b 10.53.0.2 zone2.com. a >dig.out.ns2.$n || ret=1 -grep 'status: NOERROR' dig.out.ns2.$n >/dev/null || ret=1 -grep '^zone2.com.' dig.out.ns2.$n >/dev/null || ret=1 -if [ $ret != 0 ]; then echo_i "failed"; fi -status=$((status + ret)) - -# Test 3 - check if standard file path (no magic chars) works. -n=$((n + 1)) -echo_i "checking include of standard file path config ($n)" -ret=0 -$DIG $DIGOPTS @10.53.0.2 -b 10.53.0.2 mars.com. a >dig.out.ns2.$n || ret=1 -grep 'status: NOERROR' dig.out.ns2.$n >/dev/null || ret=1 -grep '^mars.com.' dig.out.ns2.$n >/dev/null || ret=1 -if [ $ret != 0 ]; then echo_i "failed"; fi -status=$((status + ret)) - -# Test 4: named-checkconf correctly parses glob includes. -n=$((n + 1)) -echo_i "checking named-checkconf with glob include ($n)" -ret=0 -( - cd ns2 - $CHECKCONF named.conf -) || ret=1 -if [ $ret != 0 ]; then echo_i "failed"; fi -status=$((status + ret)) - -echo_i "exit status: $status" -[ $status -eq 0 ] || exit 1 diff --git a/bin/tests/system/include-multiplecfg/tests_include_multiplecfg.py b/bin/tests/system/include-multiplecfg/tests_include_multiplecfg.py new file mode 100644 index 0000000000..346f33453e --- /dev/null +++ b/bin/tests/system/include-multiplecfg/tests_include_multiplecfg.py @@ -0,0 +1,39 @@ +# 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. + +import os + +import isctest +import pytest + +import dns.message + + +@pytest.mark.parametrize( + "qname", + [ + "zone1.com.", # glob include of zone1 config + "zone2.com.", # glob include of zone2 config + "mars.com.", # checking include of standard file path config + ], +) +def test_include_multiplecfg(qname): + msg = dns.message.make_query(qname, "A") + res = isctest.query.tcp(msg, "10.53.0.2") + + isctest.check.noerror(res) + + assert res.answer[0] == dns.rrset.from_text(qname, 86400, "IN", "A", "10.53.0.1") + + +def test_include_multiplecfg_checkconf(): + """Test that named-checkconf correctly parses glob includes""" + isctest.run.cmd([os.environ["CHECKCONF"], "named.conf"], cwd="ns2") diff --git a/bin/tests/system/include-multiplecfg/tests_sh_include_multiplecfg.py b/bin/tests/system/include-multiplecfg/tests_sh_include_multiplecfg.py deleted file mode 100644 index e767c1d698..0000000000 --- a/bin/tests/system/include-multiplecfg/tests_sh_include_multiplecfg.py +++ /dev/null @@ -1,14 +0,0 @@ -# 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. - - -def test_include_multiplecfg(run_tests_sh): - run_tests_sh()