From b04d28f1ef4b5dc0ddef220cf05e9e5cf884dbf9 Mon Sep 17 00:00:00 2001 From: Michal Nowak Date: Wed, 21 Feb 2024 11:36:10 +0100 Subject: [PATCH] Rewrite names system test to pytest dnspython 2.7.0 or newer is needed because of wire(). (cherry picked from commit 5250ad87207e0ba05d4cb04f1fce661a0d66ec28) --- bin/tests/system/names/tests.sh | 51 ------------------------ bin/tests/system/names/tests_names.py | 33 +++++++++++++++ bin/tests/system/names/tests_sh_names.py | 22 ---------- 3 files changed, 33 insertions(+), 73 deletions(-) delete mode 100644 bin/tests/system/names/tests.sh create mode 100644 bin/tests/system/names/tests_names.py delete mode 100644 bin/tests/system/names/tests_sh_names.py diff --git a/bin/tests/system/names/tests.sh b/bin/tests/system/names/tests.sh deleted file mode 100644 index 453f8ef520..0000000000 --- a/bin/tests/system/names/tests.sh +++ /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 index 0000000000..e4fc296277 --- /dev/null +++ b/bin/tests/system/names/tests_names.py @@ -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 index 25e188e697..0000000000 --- a/bin/tests/system/names/tests_sh_names.py +++ /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()