]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Rewrite rrchecker system test to pytest
authorMichal Nowak <mnowak@isc.org>
Wed, 6 Mar 2024 14:57:24 +0000 (15:57 +0100)
committerMichal Nowak <mnowak@isc.org>
Fri, 15 Mar 2024 09:07:27 +0000 (10:07 +0100)
(cherry picked from commit 6a301c1d35fe6dc55a6a32814b43fb6d0acbb24f)

bin/tests/system/rrchecker/classlist.good [deleted file]
bin/tests/system/rrchecker/clean.sh
bin/tests/system/rrchecker/privatelist.good [deleted file]
bin/tests/system/rrchecker/tests.sh [deleted file]
bin/tests/system/rrchecker/tests_rrchecker.py [new file with mode: 0644]
bin/tests/system/rrchecker/tests_sh_rrchecker.py [deleted file]
bin/tests/system/rrchecker/typelist.good [deleted file]

diff --git a/bin/tests/system/rrchecker/classlist.good b/bin/tests/system/rrchecker/classlist.good
deleted file mode 100644 (file)
index f0fff1a..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-IN
-CH
-HS
index 166247d40c9a70fbeb8dd7d7d103492d243bedd2..934ec8b472c9b95eb56630d37bf8587dad164af9 100644 (file)
@@ -11,5 +11,4 @@
 # See the COPYRIGHT file distributed with this work for additional
 # information regarding copyright ownership.
 
-rm -f classlist.out privatelist.out typelist.out tempzone checkzone.out* checker.out
 rm -f ns*/named.lock
diff --git a/bin/tests/system/rrchecker/privatelist.good b/bin/tests/system/rrchecker/privatelist.good
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/bin/tests/system/rrchecker/tests.sh b/bin/tests/system/rrchecker/tests.sh
deleted file mode 100644 (file)
index 0edf303..0000000
+++ /dev/null
@@ -1,98 +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
-
-status=0
-n=0
-
-n=$((n + 1))
-echo_i "class list ($n)"
-$RRCHECKER -C >classlist.out
-diff classlist.out classlist.good || {
-  echo_i "failed"
-  status=$((status + 1))
-}
-
-n=$((n + 1))
-echo_i "type list ($n)"
-$RRCHECKER -T >typelist.out
-diff typelist.out typelist.good || {
-  echo_i "failed"
-  status=$((status + 1))
-}
-
-n=$((n + 1))
-echo_i "private type list ($n)"
-$RRCHECKER -P >privatelist.out
-diff privatelist.out privatelist.good || {
-  echo_i "failed"
-  status=$((status + 1))
-}
-
-myecho() {
-  cat <<EOF
-$*
-EOF
-}
-
-n=$((n + 1))
-echo_i "check conversions to canonical format ($n)"
-ret=0
-$SHELL ${TOP_SRCDIR}/bin/tests/system/genzone.sh 0 >tempzone
-$CHECKZONE -Dq . tempzone | sed '/^;/d' >checkzone.out$n
-while read -r name tt cl ty rest; do
-  myecho "$cl $ty $rest" | $RRCHECKER -p >checker.out || {
-    ret=1
-    echo_i "'$cl $ty $rest' not handled."
-  }
-  read -r cl0 ty0 rest0 <checker.out
-  test "$cl $ty $rest" = "$cl0 $ty0 $rest0" || {
-    ret=1
-    echo_i "'$cl $ty $rest' != '$cl0 $ty0 $rest0'"
-  }
-done <checkzone.out$n
-test $ret -eq 0 || {
-  echo_i "failed"
-  status=$((status + 1))
-}
-
-n=$((n + 1))
-echo_i "check conversions to and from unknown record format ($n)"
-ret=0
-$CHECKZONE -Dq . tempzone | sed '/^;/d' >checkzone.out$n
-while read -r name tt cl ty rest; do
-  myecho "$cl $ty $rest" | $RRCHECKER -u >checker.out || {
-    ret=1
-    echo_i "'$cl $ty $rest' not converted to unknown record format"
-  }
-  read -r clu tyu restu <checker.out
-  myecho "$clu $tyu $restu" | $RRCHECKER -p >checker.out || {
-    ret=1
-    echo_i "'$cl $ty $rest' not converted back to canonical format"
-  }
-  read -r cl0 ty0 rest0 <checker.out
-  test "$cl $ty $rest" = "$cl0 $ty0 $rest0" || {
-    ret=1
-    echo_i "'$cl $ty $rest' != '$cl0 $ty0 $rest0'"
-  }
-done <checkzone.out$n
-test $ret -eq 0 || {
-  echo_i "failed"
-  status=$((status + 1))
-}
-
-echo_i "exit status: $status"
-[ $status -eq 0 ] || exit 1
diff --git a/bin/tests/system/rrchecker/tests_rrchecker.py b/bin/tests/system/rrchecker/tests_rrchecker.py
new file mode 100644 (file)
index 0000000..743949a
--- /dev/null
@@ -0,0 +1,188 @@
+# 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 pytest
+
+
+@pytest.mark.parametrize(
+    "option,expected_result",
+    [
+        ("-C", ["HS", "CH", "IN"]),
+        (
+            "-T",
+            [
+                "A",
+                "A6",
+                "AAAA",
+                "AFSDB",
+                "AMTRELAY",
+                "APL",
+                "ATMA",
+                "AVC",
+                "CAA",
+                "CDNSKEY",
+                "CDS",
+                "CERT",
+                "CNAME",
+                "CSYNC",
+                "DHCID",
+                "DLV",
+                "DNAME",
+                "DNSKEY",
+                "DOA",
+                "DS",
+                "EID",
+                "EUI48",
+                "EUI64",
+                "GID",
+                "GPOS",
+                "HINFO",
+                "HIP",
+                "HTTPS",
+                "IPSECKEY",
+                "ISDN",
+                "KEY",
+                "KX",
+                "L32",
+                "L64",
+                "LOC",
+                "LP",
+                "MB",
+                "MD",
+                "MF",
+                "MG",
+                "MINFO",
+                "MR",
+                "MX",
+                "NAPTR",
+                "NID",
+                "NIMLOC",
+                "NINFO",
+                "NS",
+                "NSAP",
+                "NSAP-PTR",
+                "NSEC",
+                "NSEC3",
+                "NSEC3PARAM",
+                "NULL",
+                "NXT",
+                "OPENPGPKEY",
+                "PTR",
+                "PX",
+                "RESINFO",
+                "RKEY",
+                "RP",
+                "RRSIG",
+                "RT",
+                "SIG",
+                "SINK",
+                "SMIMEA",
+                "SOA",
+                "SPF",
+                "SRV",
+                "SSHFP",
+                "SVCB",
+                "TA",
+                "TALINK",
+                "TLSA",
+                "TXT",
+                "UID",
+                "UINFO",
+                "UNSPEC",
+                "URI",
+                "WKS",
+                "X25",
+                "ZONEMD",
+            ],
+        ),
+        ("-P", []),
+    ],
+)
+def test_rrchecker_list_standard_names(option, expected_result):
+    stdout = subprocess.run(
+        [
+            os.environ["RRCHECKER"],
+            option,
+        ],
+        stdout=subprocess.PIPE,
+        stderr=subprocess.PIPE,
+        check=True,
+    ).stdout.decode("utf-8")
+    values = [line for line in stdout.split("\n") if line.strip()]
+
+    assert sorted(values) == sorted(expected_result)
+
+
+def run_rrchecker(option, rr_class, rr_type, rr_rest):
+    with subprocess.Popen(
+        [os.environ["RRCHECKER"], option],
+        stdin=subprocess.PIPE,
+        stdout=subprocess.PIPE,
+    ) as process:
+        rrchecker_output, _ = process.communicate(
+            f"{rr_class} {rr_type} {rr_rest}".encode("utf-8")
+        )
+    return rrchecker_output.decode("utf-8").split()
+
+
+@pytest.mark.parametrize("option", ["-p", "-u"])
+def test_rrchecker_conversions(option):
+    tempzone_file = "tempzone"
+    with open(tempzone_file, "w", encoding="utf-8") as file:
+        subprocess.run(
+            [
+                os.environ["SHELL"],
+                os.environ["TOP_SRCDIR"] + "/bin/tests/system/genzone.sh",
+                "0",
+            ],
+            stdout=file,
+            stderr=subprocess.PIPE,
+            check=True,
+        )
+    checkzone_output = subprocess.run(
+        [
+            os.environ["CHECKZONE"],
+            "-D",
+            "-q",
+            ".",
+            tempzone_file,
+        ],
+        stdout=subprocess.PIPE,
+        stderr=subprocess.PIPE,
+        check=True,
+    ).stdout.decode("utf-8")
+    checkzone_output = [
+        line for line in checkzone_output.splitlines() if not line.startswith(";")
+    ]
+
+    for rr in checkzone_output:
+        rr_parts_orig = rr.split()
+        assert len(rr_parts_orig) >= 4, f"invalid rr: {rr}"
+        rr_class_orig, rr_type_orig, rr_rest_orig = (
+            rr_parts_orig[2],
+            rr_parts_orig[3],
+            " ".join(rr_parts_orig[4:]),
+        )
+        rr_class, rr_type, rr_rest = rr_class_orig, rr_type_orig, rr_rest_orig
+        if option == "-u":
+            rr_class, rr_type, *rr_rest = run_rrchecker(
+                "-u", rr_class_orig, rr_type_orig, rr_rest_orig
+            )
+            rr_rest = " ".join(rr_rest)
+
+        rr_class, rr_type, *rr_rest = run_rrchecker("-p", rr_class, rr_type, rr_rest)
+
+        assert rr_class_orig == rr_class
+        assert rr_type_orig == rr_type
+        assert rr_rest_orig == " ".join(rr_rest)
diff --git a/bin/tests/system/rrchecker/tests_sh_rrchecker.py b/bin/tests/system/rrchecker/tests_sh_rrchecker.py
deleted file mode 100644 (file)
index 16368e7..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_rrchecker(run_tests_sh):
-    run_tests_sh()
diff --git a/bin/tests/system/rrchecker/typelist.good b/bin/tests/system/rrchecker/typelist.good
deleted file mode 100644 (file)
index 506bfa0..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-A
-NS
-MD
-MF
-CNAME
-SOA
-MB
-MG
-MR
-NULL
-WKS
-PTR
-HINFO
-MINFO
-MX
-TXT
-RP
-AFSDB
-X25
-ISDN
-RT
-NSAP
-NSAP-PTR
-SIG
-KEY
-PX
-GPOS
-AAAA
-LOC
-NXT
-EID
-NIMLOC
-SRV
-ATMA
-NAPTR
-KX
-CERT
-A6
-DNAME
-SINK
-APL
-DS
-SSHFP
-IPSECKEY
-RRSIG
-NSEC
-DNSKEY
-DHCID
-NSEC3
-NSEC3PARAM
-TLSA
-SMIMEA
-HIP
-NINFO
-RKEY
-TALINK
-CDS
-CDNSKEY
-OPENPGPKEY
-CSYNC
-ZONEMD
-SVCB
-HTTPS
-SPF
-UINFO
-UID
-GID
-UNSPEC
-NID
-L32
-L64
-LP
-EUI48
-EUI64
-URI
-CAA
-AVC
-DOA
-AMTRELAY
-RESINFO
-TA
-DLV