]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Test checkconf and addzone with bad templates
authorMatthijs Mekking <matthijs@isc.org>
Thu, 28 May 2026 09:46:39 +0000 (11:46 +0200)
committerMatthijs Mekking <matthijs@isc.org>
Thu, 28 May 2026 14:25:48 +0000 (14:25 +0000)
named-checkconf should reject a template that has options that must be
non-zero (max-refresh-time, max-retry-time, min-refresh-time,
min-retry-time).

rndc addzone with a zone that refers to such template should fail
cleanly.

bin/tests/system/addzone/ns2/named.conf.j2
bin/tests/system/addzone/tests_rndc_addzone_template.py [new file with mode: 0644]
bin/tests/system/checkconf/bad-template-non-zero-check.conf [new file with mode: 0644]

index eb0bebe2af8e0bf253cd22d5c6785e554d653965..0b39c98dd58e18a218ec0d157c87817d4e9f6e81 100644 (file)
@@ -21,6 +21,15 @@ template primary {
        initial-file "added.db";
 };
 
+template bad {
+       type secondary;
+       primaries { 10.53.0.1; };
+       max-refresh-time 0;
+       max-retry-time 0;
+       min-refresh-time 0;
+       min-retry-time 0;
+};
+
 zone "." {
        type hint;
        file "../../_common/root.hint";
diff --git a/bin/tests/system/addzone/tests_rndc_addzone_template.py b/bin/tests/system/addzone/tests_rndc_addzone_template.py
new file mode 100644 (file)
index 0000000..dc6566c
--- /dev/null
@@ -0,0 +1,45 @@
+# 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 pytest
+
+pytestmark = pytest.mark.extra_artifacts(
+    [
+        "ns*/*.nzf*",
+        "ns*/*.nzd*",
+        "ns1/redirect.db",
+        "ns2/new-zones",
+        "ns2/redirect.db",
+        "ns3/redirect.db",
+    ]
+)
+
+
+def test_rndc_addzone_bad_template(ns2):
+    """
+    Confirm "rndc addzone" fails for a zone that refers to a badly configured template.
+    """
+    zone = "badtemplate.example"
+    cmd = ns2.rndc(
+        "addzone badtemplate.example {template bad;};",
+        raise_on_exception=False,
+    )
+    assert cmd.rc == 1
+
+    assert "'max-retry-time' must not be zero" in ns2.log
+    assert "'min-retry-time' must not be zero" in ns2.log
+    assert "'max-refresh-time' must not be zero" in ns2.log
+    assert "'min-refresh-time' must not be zero" in ns2.log
+
+    # Confirm that the addzone failed to add the zone
+    cmd = ns2.rndc(f"showzone {zone}", raise_on_exception=False)
+    assert cmd.rc == 1
+    assert f"no matching zone '{zone}' in any view" in cmd.err
diff --git a/bin/tests/system/checkconf/bad-template-non-zero-check.conf b/bin/tests/system/checkconf/bad-template-non-zero-check.conf
new file mode 100644 (file)
index 0000000..b7589a8
--- /dev/null
@@ -0,0 +1,12 @@
+template "a" {
+       type secondary;
+       primaries { 10.53.0.1; };
+       max-refresh-time 0;
+       max-retry-time 0;
+       min-refresh-time 0;
+       min-retry-time 0;
+};
+
+zone example {
+       template a;
+};