bind9/bin/tests/system/doth/conftest.py
Michał Kępień 29961bd741 Reimplement the gnutls-cli check in Python
gnutls-cli is tricky to script around as it immediately closes the
server connection when its standard input is closed.  This prevents
simple shell-based I/O redirection from being used for capturing the DNS
response sent over a TLS connection and the workarounds for this issue
employ non-standard utilities like "timeout".

Instead of resorting to clever shell hacks, reimplement the relevant
check in Python.  Exit immediately upon receiving a valid DNS response
or when gnutls-cli exits in order to decrease the test's run time.
Employ dnspython to avoid the need for storing DNS queries in binary
files and to improve test readability.  Capture more diagnostic output
to facilitate troubleshooting.  Use a pytest fixture instead of an
Autoconf macro to keep test requirements localized.
2022-01-18 11:00:46 +01:00

43 lines
1.2 KiB
Python

#!/usr/bin/python3
# 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 shutil
import subprocess
import pytest
@pytest.fixture
def gnutls_cli_executable():
# Ensure gnutls-cli is available.
executable = shutil.which('gnutls-cli')
if not executable:
pytest.skip('gnutls-cli not found in PATH')
# Ensure gnutls-cli supports the --logfile command-line option.
args = [executable, '--logfile=/dev/null']
try:
with subprocess.check_output(args, stderr=subprocess.STDOUT) as _:
pass
except subprocess.CalledProcessError as exc:
stderr = exc.output
if b'illegal option' in stderr:
pytest.skip('gnutls-cli does not support the --logfile option')
return executable
@pytest.fixture
def named_tlsport():
return int(os.environ.get('TLSPORT', '853'))