]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
pytests: import test_prefix_trailing_garbage (test7)
authorTomas Krizek <tomas.krizek@nic.cz>
Tue, 13 Nov 2018 12:59:41 +0000 (13:59 +0100)
committerTomas Krizek <tomas.krizek@nic.cz>
Tue, 4 Dec 2018 16:13:42 +0000 (17:13 +0100)
tests/pytests/test_conn_mgmt.py

index 23ea4e3f5b8c541cf9e78ce314113e2800b50a21..a9678a2cc3db2b1339f63b9fb5afef148e149252 100644 (file)
@@ -4,6 +4,7 @@ import time
 
 import dns
 import dns.message
+import pytest
 
 import utils
 
@@ -156,3 +157,33 @@ def test_prefix_cut_message_after_ok(kresd_sock):
             time.sleep(1)
     else:
         assert False, "kresd didn't close the connection"
+
+
+def test_prefix_trailing_garbage(kresd_sock):
+    """
+    Test repeatedly sends correct message with garbage after the message's end.
+    Message is prefixed by the length that includes garbage length.
+
+    Expected: TCP connection must not be closed until all the queries have been sent
+    """
+    msg = dns.message.make_query('localhost.', dns.rdatatype.A, dns.rdataclass.IN)
+    msg.id = 1
+
+    for _ in range(10):
+        msg.id += 1
+        data = msg.to_wire() + b'garbage'
+        data_len = len(data)
+        buf = struct.pack("!H", data_len) + data
+        try:
+            kresd_sock.sendall(buf)
+        except BrokenPipeError:
+            raise pytest.fail("kresd closed the connection")
+
+        try:
+            msg_answer = utils.receive_parse_answer(kresd_sock)
+        except BrokenPipeError:
+            raise pytest.fail("kresd closed the connection")
+        else:
+            assert msg_answer.id == msg.id
+
+        time.sleep(0.1)