]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Rewrite names system test to pytest
authorMichal Nowak <mnowak@isc.org>
Wed, 21 Feb 2024 10:36:10 +0000 (11:36 +0100)
committerMichal Nowak <mnowak@isc.org>
Thu, 13 Feb 2025 16:55:38 +0000 (16:55 +0000)
dnspython 2.7.0 or newer is needed because of wire().

bin/tests/system/names/tests.sh [deleted file]
bin/tests/system/names/tests_names.py [new file with mode: 0644]
bin/tests/system/names/tests_sh_names.py [deleted file]

diff --git a/bin/tests/system/names/tests.sh b/bin/tests/system/names/tests.sh
deleted file mode 100644 (file)
index 453f8ef..0000000
+++ /dev/null
@@ -1,51 +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="+nosea +stat +noquest +nocomm +nocmd -p ${PORT}"
-
-status=0
-
-echo_i "Getting message size with compression enabled"
-$DIG $DIGOPTS -b 10.53.0.1 @10.53.0.1 mx example >dig.compen.test || ret=1
-COMPEN=$(grep ';; MSG SIZE' dig.compen.test | sed -e "s/.*: //g")
-cat dig.compen.test | grep -v ';;' | sort >dig.compen.sorted.test
-
-echo_i "Getting message size with compression disabled"
-$DIG $DIGOPTS -b 10.53.0.2 @10.53.0.1 mx example >dig.compdis.test || ret=1
-COMPDIS=$(grep ';; MSG SIZE' dig.compdis.test | sed -e "s/.*: //g")
-cat dig.compdis.test | grep -v ';;' | sort >dig.compdis.sorted.test
-
-# the compression disabled message should be at least twice as large as with
-# compression disabled, but the content should be the same
-echo_i "Checking if responses are identical other than in message size"
-{
-  diff dig.compdis.sorted.test dig.compen.sorted.test >/dev/null
-  ret=$?
-} || true
-if [ $ret != 0 ]; then echo_i "failed"; fi
-status=$((status + ret))
-
-echo_i "Checking if message with compression disabled is significantly larger"
-echo_i "Disabled $COMPDIS vs enabled $COMPEN"
-val=$(((COMPDIS * 3 / 2) / COMPEN))
-if [ $val -le 1 ]; then
-  echo_i "failed"
-  status=$((status + 1))
-fi
-
-echo_i "exit status: $status"
-[ $status -eq 0 ] || exit 1
diff --git a/bin/tests/system/names/tests_names.py b/bin/tests/system/names/tests_names.py
new file mode 100644 (file)
index 0000000..e4fc296
--- /dev/null
@@ -0,0 +1,33 @@
+# 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
+
+pytest.importorskip("dns", minversion="2.7.0")
+
+
+import dns.message
+import isctest
+
+
+# The query answer sent with compression disabled should have a size that is
+# about twice as large as the answer with compression enabled, while
+# maintaining identical content.
+def test_names():
+    msg = dns.message.make_query("example.", "MX")
+    # Getting message size with compression enabled
+    res_enabled = isctest.query.tcp(msg, ip="10.53.0.1", source="10.53.0.1")
+    # Getting message size with compression disabled
+    res_disabled = isctest.query.tcp(msg, ip="10.53.0.1", source="10.53.0.2")
+    # Checking if responses are identical content-wise
+    isctest.check.rrsets_equal(res_enabled.answer, res_disabled.answer)
+    # Checking if message with compression disabled is significantly (say 70%) larger
+    assert len(res_disabled.wire) > len(res_enabled.wire) * 1.7
diff --git a/bin/tests/system/names/tests_sh_names.py b/bin/tests/system/names/tests_sh_names.py
deleted file mode 100644 (file)
index 25e188e..0000000
+++ /dev/null
@@ -1,22 +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.
-
-import pytest
-
-pytestmark = pytest.mark.extra_artifacts(
-    [
-        "dig.*.test*",
-    ]
-)
-
-
-def test_names(run_tests_sh):
-    run_tests_sh()