diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 10:41:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 10:41:58 +0000 |
commit | 1852910ef0fd7393da62b88aee66ee092208748e (patch) | |
tree | ad3b659dbbe622b58a5bda4fe0b5e1d80eee9277 /tests/pytests/proxyutils.py | |
parent | Initial commit. (diff) | |
download | knot-resolver-1852910ef0fd7393da62b88aee66ee092208748e.tar.xz knot-resolver-1852910ef0fd7393da62b88aee66ee092208748e.zip |
Adding upstream version 5.3.1.upstream/5.3.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/pytests/proxyutils.py')
-rw-r--r-- | tests/pytests/proxyutils.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/pytests/proxyutils.py b/tests/pytests/proxyutils.py new file mode 100644 index 0000000..fa20d51 --- /dev/null +++ b/tests/pytests/proxyutils.py @@ -0,0 +1,41 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +from contextlib import contextmanager +import os +import subprocess + +import dns +import dns.rcode + +from kresd import CERTS_DIR +import utils + + +HINTS = { + '0.foo.': '127.0.0.1', + '1.foo.': '127.0.0.1', + '2.foo.': '127.0.0.1', + '3.foo.': '127.0.0.1', +} + +PROXY_CA_FILE = os.path.join(CERTS_DIR, 'tt.cert.pem') + + +def resolve_hint(sock, qname): + buff, msgid = utils.get_msgbuff(qname) + sock.sendall(buff) + answer = utils.receive_parse_answer(sock) + assert answer.id == msgid + assert answer.rcode() == dns.rcode.NOERROR + assert answer.answer[0][0].address == HINTS[qname] + + +@contextmanager +def proxy(path): + cwd, cmd = os.path.split(path) + cmd = './' + cmd + try: + proxy = subprocess.Popen( + [cmd], cwd=cwd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + yield proxy + finally: + proxy.terminate() |