2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 14:07:59 +00:00

Rewrite names system test to pytest

dnspython 2.7.0 or newer is needed because of wire().

(cherry picked from commit 5250ad8720)
This commit is contained in:
Michal Nowak
2024-02-21 11:36:10 +01:00
parent 97e7e9ff21
commit b04d28f1ef
3 changed files with 33 additions and 73 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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()