From: Tomas Krizek Date: Tue, 13 Nov 2018 12:59:41 +0000 (+0100) Subject: pytests: import test_prefix_trailing_garbage (test7) X-Git-Tag: v3.2.0~18^2~50 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ac0fbd649e7f97e883dedccf51647478f3a91ebf;p=thirdparty%2Fknot-resolver.git pytests: import test_prefix_trailing_garbage (test7) --- diff --git a/tests/pytests/test_conn_mgmt.py b/tests/pytests/test_conn_mgmt.py index 23ea4e3f5..a9678a2cc 100644 --- a/tests/pytests/test_conn_mgmt.py +++ b/tests/pytests/test_conn_mgmt.py @@ -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)