From: Colin Vidal Date: Tue, 21 Oct 2025 10:10:34 +0000 (+0200) Subject: add system test for rndc showconf X-Git-Tag: v9.21.15~20^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb064875688631b5751a0f7cfc178eac12fc2a74;p=thirdparty%2Fbind9.git add system test for rndc showconf Add system tests covering the rndc showconf command. It doesn't attempt to check the whole effective configuration (as any change to the builtin configuration would break it) but instead ensures that some parts of the user config are present, as well as some parts of the builtin config as well. It also checks that the effective config (in this context of running named instance) is about static configuration: a newly added zone is not visible in the effective configuration. --- diff --git a/bin/tests/system/showconf/ns1/example.db b/bin/tests/system/showconf/ns1/example.db new file mode 100644 index 00000000000..1d7173fea3a --- /dev/null +++ b/bin/tests/system/showconf/ns1/example.db @@ -0,0 +1,21 @@ +; 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. + +$TTL 120 +@ SOA ns.unsigned. hostmaster.ns.unsigned. ( 1 3600 1200 604800 60 ) +@ NS ns +@ MX 10 mx + +ns A 10.53.0.1 + AAAA fd92:7065:b8e:ffff::1 + +a A 1.1.1.1 +mx A 2.2.2.2 diff --git a/bin/tests/system/showconf/ns1/named.conf.j2 b/bin/tests/system/showconf/ns1/named.conf.j2 new file mode 100644 index 00000000000..ad42e4bc257 --- /dev/null +++ b/bin/tests/system/showconf/ns1/named.conf.j2 @@ -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. + */ +options { + query-source address 10.53.0.1; + notify-source 10.53.0.1; + transfer-source 10.53.0.1; + port @PORT@; + pid-file "named.pid"; + listen-on { 10.53.0.1; }; + recursion no; + dnssec-validation no; + notify yes; + minimal-responses no; + allow-new-zones yes; +}; + +key rndc_key { + secret "1234abcd8765"; + algorithm @DEFAULT_HMAC@; +}; + +controls { + inet 10.53.0.1 port @CONTROLPORT@ allow { any; } keys { rndc_key; }; +}; + +zone "example.com" { + type primary; + file "example.db"; +}; diff --git a/bin/tests/system/showconf/tests_showconf.py b/bin/tests/system/showconf/tests_showconf.py new file mode 100644 index 00000000000..ae7e3833cc1 --- /dev/null +++ b/bin/tests/system/showconf/tests_showconf.py @@ -0,0 +1,62 @@ +# 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 dns +import isctest + + +def test_showconf(ns1): + # Basic testing of rndc showconf + msg = isctest.query.create("a.example.com", "A") + res = isctest.query.udp(msg, "10.53.0.1") + isctest.check.rcode(res, dns.rcode.NOERROR) + + effectiveconfig = ns1.rndc("showconf -effective", log=False) + assert 'zone "example.com"' in effectiveconfig + assert 'view "_bind" chaos {' in effectiveconfig + + # builtin-trust-anchors is non documented and internal clause only, it must + # not be visible. + assert "builtin-trust-anchors" not in effectiveconfig + + # Dynamically added zones are not visible from the effectiveconfig + zonedata = '"added.example" { type primary; file "example.db"; };' + ns1.rndc(f"addzone {zonedata}", log=False) + + msg = isctest.query.create("a.added.example", "A") + res = isctest.query.udp(msg, "10.53.0.1") + isctest.check.rcode(res, dns.rcode.NOERROR) + + effectiveconfig = ns1.rndc("showconf -effective", log=False) + assert 'zone "added.example"' not in effectiveconfig + + userconfig = ns1.rndc("showconf -user", log=False) + assert 'zone "example.com"' in userconfig + assert 'view "_bind" chaos {' not in userconfig + + builtinconfig = ns1.rndc("showconf -builtin", log=False) + assert len(userconfig.split()) < len(builtinconfig.split()) + assert len(builtinconfig.split()) < len(effectiveconfig.split()) + + # Errors handling + error_msg = "" + + try: + ns1.rndc("showconf -idontexist", log=False) + except isctest.rndc.RNDCException as e: + error_msg = str(e) + assert error_msg == "rndc: 'showconf' failed: syntax error\n" + + try: + ns1.rndc("showconf", log=False) + except isctest.rndc.RNDCException as e: + error_msg = str(e) + assert error_msg == "rndc: 'showconf' failed: unexpected end of input\n"