]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Rewrite masterfile system test to pytest
authorMichal Nowak <mnowak@isc.org>
Tue, 19 Mar 2024 09:31:38 +0000 (10:31 +0100)
committerMichal Nowak <mnowak@isc.org>
Tue, 19 Mar 2024 09:51:02 +0000 (10:51 +0100)
bin/tests/system/masterfile/clean.sh
bin/tests/system/masterfile/knowngood.include [deleted file]
bin/tests/system/masterfile/knowngood.ttl1 [deleted file]
bin/tests/system/masterfile/knowngood.ttl2 [deleted file]
bin/tests/system/masterfile/tests.sh [deleted file]
bin/tests/system/masterfile/tests_masterfile.py [new file with mode: 0644]
bin/tests/system/masterfile/tests_sh_masterfile.py [deleted file]
bin/tests/system/masterfile/zone/inheritownerafterinclude.good [deleted file]

index a1e9d4b1b79f2686d15bddb9533d4b393e85a559..8883a9487dcf1b865e56ac52c0507ff6f1badd1d 100644 (file)
@@ -11,9 +11,7 @@
 # See the COPYRIGHT file distributed with this work for additional
 # information regarding copyright ownership.
 
-rm -f dig.out.*
 rm -f */named.memstats
 rm -f */named.conf
 rm -f */named.run
-rm -f checkzone.out*
 rm -f ns*/managed-keys.bind*
diff --git a/bin/tests/system/masterfile/knowngood.include b/bin/tests/system/masterfile/knowngood.include
deleted file mode 100644 (file)
index 795cc34..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-include.               300     IN      SOA     ns.include. hostmaster.include. 1 3600 1800 1814400 3600
-include.               300     IN      NS      ns.include.
-a.include.             300     IN      A       10.0.0.1
-a.include.             300     IN      A       10.0.0.99
-a.a.include.           300     IN      A       10.0.1.1
-b.foo.a.include.       300     IN      A       10.0.2.2
-b.include.             300     IN      A       10.0.0.2
-a.b.include.           300     IN      A       10.0.1.1
-c.b.include.           300     IN      A       10.0.0.3
-b.foo.b.include.       300     IN      A       10.0.2.2
-ns.include.            300     IN      A       127.0.0.1
-include.               300     IN      SOA     ns.include. hostmaster.include. 1 3600 1800 1814400 3600
diff --git a/bin/tests/system/masterfile/knowngood.ttl1 b/bin/tests/system/masterfile/knowngood.ttl1
deleted file mode 100644 (file)
index 86baa95..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-ttl1.                  3       IN      SOA     ns.ttl1. hostmaster.ttl1. 1 3600 1800 1814400 3
-ttl1.                  3       IN      NS      ns.ttl1.
-a.ttl1.                        3       IN      TXT     "soa minttl 3"
-b.ttl1.                        2       IN      TXT     "explicit ttl 2"
-c.ttl1.                        3       IN      TXT     "soa minttl 3"
-d.ttl1.                        1       IN      TXT     "default ttl 1"
-e.ttl1.                        4       IN      TXT     "explicit ttl 4"
-f.ttl1.                        1       IN      TXT     "default ttl 1"
-ns.ttl1.               3       IN      A       10.53.0.1
-ttl1.                  3       IN      SOA     ns.ttl1. hostmaster.ttl1. 1 3600 1800 1814400 3
diff --git a/bin/tests/system/masterfile/knowngood.ttl2 b/bin/tests/system/masterfile/knowngood.ttl2
deleted file mode 100644 (file)
index 2f2a9f9..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-ttl2.                  1       IN      SOA     ns.ttl2. hostmaster.ttl2. 1 3600 1800 1814400 3
-ttl2.                  1       IN      NS      ns.ttl2.
-a.ttl2.                        1       IN      TXT     "inherited ttl 1"
-b.ttl2.                        2       IN      TXT     "explicit ttl 2"
-c.ttl2.                        2       IN      TXT     "inherited ttl 2"
-d.ttl2.                        3       IN      TXT     "default ttl 3"
-e.ttl2.                        2       IN      TXT     "explicit ttl 2"
-f.ttl2.                        3       IN      TXT     "default ttl 3"
-ns.ttl2.               1       IN      A       10.53.0.1
-ttl2.                  1       IN      SOA     ns.ttl2. hostmaster.ttl2. 1 3600 1800 1814400 3
diff --git a/bin/tests/system/masterfile/tests.sh b/bin/tests/system/masterfile/tests.sh
deleted file mode 100644 (file)
index dbe04ae..0000000
+++ /dev/null
@@ -1,75 +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.
-
-set -e
-
-. ../conf.sh
-
-DIGOPTS="-p ${PORT}"
-
-status=0
-n=0
-
-ret=0
-n=$((n + 1))
-echo_i "test master file \$INCLUDE semantics ($n)"
-$DIG $DIGOPTS +nostats +nocmd include. axfr @10.53.0.1 >dig.out.$n || ret=1
-
-diff dig.out.$n knowngood.include || ret=1
-if [ $ret != 0 ]; then echo_i "failed"; fi
-status=$((status + ret))
-
-ret=0
-n=$((n + 1))
-echo_i "test master file BIND 8 compatibility TTL and \$TTL semantics ($n)"
-$DIG $DIGOPTS +nostats +nocmd ttl1. axfr @10.53.0.1 >dig.out.$n || ret=1
-
-diff dig.out.$n knowngood.ttl1 || ret=1
-if [ $ret != 0 ]; then echo_i "failed"; fi
-status=$((status + ret))
-
-ret=0
-n=$((n + 1))
-echo_i "test of master file RFC1035 TTL and \$TTL semantics ($n)"
-$DIG $DIGOPTS +nostats +nocmd ttl2. axfr @10.53.0.1 >dig.out.$n || ret=1
-
-diff dig.out.$n knowngood.ttl2 || ret=1
-if [ $ret != 0 ]; then echo_i "failed"; fi
-status=$((status + ret))
-
-ret=0
-n=$((n + 1))
-echo_i "test that the nameserver is running with a missing master file ($n)"
-$DIG $DIGOPTS +tcp +noall +answer example soa @10.53.0.2 >dig.out.$n || ret=1
-grep SOA dig.out.$n >/dev/null || ret=1
-if [ $ret != 0 ]; then echo_i "failed"; fi
-status=$((status + ret))
-
-ret=0
-n=$((n + 1))
-echo_i "test that the nameserver returns SERVFAIL for a missing master file ($n)"
-$DIG $DIGOPTS +tcp +all missing soa @10.53.0.2 >dig.out.$n || ret=1
-grep "status: SERVFAIL" dig.out.$n >/dev/null || ret=1
-if [ $ret != 0 ]; then echo_i "failed"; fi
-status=$((status + ret))
-
-ret=0
-n=$((n + 1))
-echo_i "test owner inheritance after "'$INCLUDE'" ($n)"
-$CHECKZONE -Dq example zone/inheritownerafterinclude.db >checkzone.out$n
-diff checkzone.out$n zone/inheritownerafterinclude.good || 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/masterfile/tests_masterfile.py b/bin/tests/system/masterfile/tests_masterfile.py
new file mode 100644 (file)
index 0000000..9843a47
--- /dev/null
@@ -0,0 +1,119 @@
+# 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 subprocess
+
+import dns.message
+import dns.zone
+
+import isctest
+
+
+def test_masterfile_include_semantics():
+    """Test master file $INCLUDE semantics"""
+    msg_axfr = dns.message.make_query("include.", "AXFR")
+    res_axfr = isctest.query.tcp(msg_axfr, "10.53.0.1")
+    axfr_include_semantics = """;ANSWER
+include.                       300     IN      SOA     ns.include. hostmaster.include. 1 3600 1800 1814400 3600
+include.                       300     IN      NS      ns.include.
+a.include.                     300     IN      A       10.0.0.1
+a.include.                     300     IN      A       10.0.0.99
+a.a.include.           300     IN      A       10.0.1.1
+b.foo.a.include.       300     IN      A       10.0.2.2
+b.include.                     300     IN      A       10.0.0.2
+a.b.include.           300     IN      A       10.0.1.1
+c.b.include.           300     IN      A       10.0.0.3
+b.foo.b.include.       300     IN      A       10.0.2.2
+ns.include.                    300     IN      A       127.0.0.1
+"""
+    expected = dns.message.from_text(axfr_include_semantics)
+    isctest.check.rrsets_equal(res_axfr.answer, expected.answer, compare_ttl=True)
+
+
+def test_masterfile_bind_8_compat_semantics():
+    """Test master file BIND 8 TTL and $TTL semantics compatibility"""
+    msg_axfr = dns.message.make_query("ttl1.", "AXFR")
+    res_axfr = isctest.query.tcp(msg_axfr, "10.53.0.1")
+    axfr_ttl_semantics = """;ANSWER
+ttl1.          3       IN      SOA     ns.ttl1. hostmaster.ttl1. 1 3600 1800 1814400 3
+ttl1.          3       IN      NS      ns.ttl1.
+a.ttl1.                3       IN      TXT     "soa minttl 3"
+b.ttl1.                2       IN      TXT     "explicit ttl 2"
+c.ttl1.                3       IN      TXT     "soa minttl 3"
+d.ttl1.                1       IN      TXT     "default ttl 1"
+e.ttl1.                4       IN      TXT     "explicit ttl 4"
+f.ttl1.                1       IN      TXT     "default ttl 1"
+ns.ttl1.       3       IN      A       10.53.0.1
+"""
+    expected = dns.message.from_text(axfr_ttl_semantics)
+    isctest.check.rrsets_equal(res_axfr.answer, expected.answer, compare_ttl=True)
+
+
+def test_masterfile_rfc_1035_semantics():
+    """Test master file RFC1035 TTL and $TTL semantics"""
+    msg_axfr = dns.message.make_query("ttl2.", "AXFR")
+    res_axfr = isctest.query.tcp(msg_axfr, "10.53.0.1")
+    axfr_ttl_semantics = """;ANSWER
+ttl2.          1       IN      SOA     ns.ttl2. hostmaster.ttl2. 1 3600 1800 1814400 3
+ttl2.          1       IN      NS      ns.ttl2.
+a.ttl2.                1       IN      TXT     "inherited ttl 1"
+b.ttl2.                2       IN      TXT     "explicit ttl 2"
+c.ttl2.                2       IN      TXT     "inherited ttl 2"
+d.ttl2.                3       IN      TXT     "default ttl 3"
+e.ttl2.                2       IN      TXT     "explicit ttl 2"
+f.ttl2.                3       IN      TXT     "default ttl 3"
+ns.ttl2.       1       IN      A       10.53.0.1
+"""
+    expected = dns.message.from_text(axfr_ttl_semantics)
+    isctest.check.rrsets_equal(res_axfr.answer, expected.answer, compare_ttl=True)
+
+
+def test_masterfile_missing_master_file():
+    """Test nameserver running with a missing master file"""
+    msg_soa = dns.message.make_query("example.", "SOA")
+    res_soa = isctest.query.tcp(msg_soa, "10.53.0.2")
+    expected_soa_rr = """;ANSWER
+example.       300     IN      SOA     mname1. . 2010042407 20 20 1814400 3600
+"""
+    expected = dns.message.from_text(expected_soa_rr)
+    isctest.check.rrsets_equal(res_soa.answer, expected.answer, compare_ttl=True)
+
+
+def test_masterfile_missing_master_file_servfail():
+    """Test nameserver returning SERVFAIL for a missing master file"""
+    msg_soa = dns.message.make_query("missing.", "SOA")
+    res_soa = isctest.query.tcp(msg_soa, "10.53.0.2")
+    isctest.check.servfail(res_soa)
+
+
+def test_masterfile_owner_inheritance():
+    """Test owner inheritance after $INCLUDE"""
+    checker_output = subprocess.run(
+        [
+            os.environ["CHECKZONE"],
+            "-D",
+            "-q",
+            "example",
+            "zone/inheritownerafterinclude.db",
+        ],
+        stdout=subprocess.PIPE,
+        stderr=subprocess.PIPE,
+        check=True,
+    ).stdout.decode("utf-8")
+    owner_inheritance_zone = """
+example.       0       IN      SOA     . . 0 0 0 0 0
+example.       0       IN      TXT     "this should be at the zone apex"
+example.       0       IN      NS      .
+"""
+    checker_zone = dns.zone.from_text(checker_output, origin="example.")
+    expected = dns.zone.from_text(owner_inheritance_zone, origin="example.")
+    isctest.check.zones_equal(checker_zone, expected, compare_ttl=True)
diff --git a/bin/tests/system/masterfile/tests_sh_masterfile.py b/bin/tests/system/masterfile/tests_sh_masterfile.py
deleted file mode 100644 (file)
index 1556892..0000000
+++ /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_masterfile(run_tests_sh):
-    run_tests_sh()
diff --git a/bin/tests/system/masterfile/zone/inheritownerafterinclude.good b/bin/tests/system/masterfile/zone/inheritownerafterinclude.good
deleted file mode 100644 (file)
index 3877ed5..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-example.                                     0 IN SOA          . . 0 0 0 0 0
-example.                                     0 IN NS           .
-example.                                     0 IN TXT          "this should be at the zone apex"