]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
pytests: import test_prefix_cut_message_after_ok (test6)
authorTomas Krizek <tomas.krizek@nic.cz>
Tue, 13 Nov 2018 12:47:52 +0000 (13:47 +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 1af556751818c07082bedbdc405f055db4cafd0c..23ea4e3f5b8c541cf9e78ce314113e2800b50a21 100644 (file)
@@ -118,3 +118,41 @@ def test_prefix_cuts_message(kresd_sock):
             time.sleep(1)
     else:
         assert False, "kresd didn't close the connection"
+
+
+def test_prefix_cut_message_after_ok(kresd_sock):
+    """
+    At first test send normal DNS message. Then, it sequentially sends DNS message
+    with incorrect prefix, which is greater than the length of DNS message header,
+    but less than length of the whole DNS message.
+
+    Expected: TCP connection is closed after a timeout period.
+    """
+    NORMAL_MSG_ID = 1
+    CUT_MSG_ID = 2
+    buf_normal = utils.get_msgbuf('localhost.', dns.rdatatype.A, NORMAL_MSG_ID)
+
+    msg = dns.message.make_query('localhost.', dns.rdatatype.A, dns.rdataclass.IN)
+    msg.id = CUT_MSG_ID
+    data = msg.to_wire()
+    datalen = 14  # DNS Header size plus 2
+    assert datalen < len(data)
+    buf_cut = struct.pack("!H", datalen) + data
+
+    kresd_sock.sendall(buf_normal)
+    kresd_sock.sendall(buf_cut)
+
+    msg_answer = utils.receive_parse_answer(kresd_sock)
+    assert msg_answer.id == NORMAL_MSG_ID
+
+    for _ in range(12):
+        try:
+            kresd_sock.sendall(buf_cut)
+        except BrokenPipeError:
+            break
+        except ConnectionResetError:
+            break
+        else:
+            time.sleep(1)
+    else:
+        assert False, "kresd didn't close the connection"