summaryrefslogtreecommitdiffstats
path: root/tests/pytests/test_random_close.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:26:00 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:26:00 +0000
commit830407e88f9d40d954356c3754f2647f91d5c06a (patch)
treed6a0ece6feea91f3c656166dbaa884ef8a29740e /tests/pytests/test_random_close.py
parentInitial commit. (diff)
downloadknot-resolver-830407e88f9d40d954356c3754f2647f91d5c06a.tar.xz
knot-resolver-830407e88f9d40d954356c3754f2647f91d5c06a.zip
Adding upstream version 5.6.0.upstream/5.6.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/pytests/test_random_close.py')
-rw-r--r--tests/pytests/test_random_close.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/pytests/test_random_close.py b/tests/pytests/test_random_close.py
new file mode 100644
index 0000000..a7cc877
--- /dev/null
+++ b/tests/pytests/test_random_close.py
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: GPL-3.0-or-later
+"""TLS test when forward target closes connection after one second
+
+Test utilizes TLS proxy, which forwards queries to configured
+resolver, but closes the connection 1s after establishing.
+
+Kresd must stay alive and be able to answer queries.
+"""
+
+import random
+import string
+import time
+
+from proxy import HINTS, kresd_tls_client, resolve_hint, TLSProxy
+import utils
+
+
+QPS = 500
+
+
+def random_string(size=32, chars=(string.ascii_lowercase + string.digits)):
+ return ''.join(random.choice(chars) for x in range(size))
+
+
+def rsa_cannon(sock, duration, domain='test.', qps=QPS):
+ end_time = time.time() + duration
+
+ while time.time() < end_time:
+ next_time = time.time() + 1/qps
+ buff, _ = utils.get_msgbuff('{}.{}'.format(random_string(), domain))
+ sock.sendall(buff)
+ time_left = next_time - time.time()
+ if time_left > 0:
+ time.sleep(time_left)
+
+
+def test_proxy_random_close(tmpdir):
+ proxy = TLSProxy(close=1000)
+
+ kresd_tls_client_kwargs = {
+ 'verbose': False,
+ 'policy_test_pass': True
+ }
+ kresd_fwd_target_kwargs = {
+ 'verbose': False
+ }
+ with kresd_tls_client(str(tmpdir), proxy, kresd_tls_client_kwargs, kresd_fwd_target_kwargs) \
+ as kresd:
+ sock2 = kresd.ip_tcp_socket()
+ rsa_cannon(sock2, 20)
+ sock3 = kresd.ip_tcp_socket()
+ for hint in HINTS:
+ resolve_hint(sock3, hint)
+ time.sleep(0.1)