]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
pytests/test_rehandshake: fix test
authorTomas Krizek <tomas.krizek@nic.cz>
Tue, 4 Dec 2018 07:40:54 +0000 (08:40 +0100)
committerTomas Krizek <tomas.krizek@nic.cz>
Tue, 4 Dec 2018 16:13:42 +0000 (17:13 +0100)
tests/pytests/kresd.py
tests/pytests/test_rehandshake.py

index 2e770ba55547f16fa9190a7139727bfab0a8f6ce..b27d116b28eb32e8e689a0f9a08c1c1b2162206a 100644 (file)
@@ -91,7 +91,7 @@ class Kresd(ContextDecorator):
         create_file_from_template(KRESD_CONF_TEMPLATE, self.config_path, {'kresd': self})
         self.logfile = open(self.logfile_path, 'w')
         self.process = subprocess.Popen(
-            ['/usr/bin/env', 'kresd', '-c', self.config_path, self.workdir, '-f', '1'],
+            ['kresd', '-c', self.config_path, '-f', '1', self.workdir],
             stdout=self.logfile, env=os.environ.copy())
 
         try:
index e4b164335ff960e0906bdb1c38d82dae4e2eb968..ffbc10bdb63acfcd1d7b066cb491a4634bb8e2d5 100644 (file)
@@ -2,7 +2,7 @@
 
 Test utilizes rehandshake/tls-proxy, which forwards queries to configured
 resolver, but when it sends the response back to the query source, it
-performs a rehandshake after every byte sent.
+performs a rehandshake after every 8 bytes sent.
 
 It is expected the answer will be received by the source kresd instance
 and sent back to the client (this test).
@@ -15,6 +15,8 @@ import re
 import subprocess
 import time
 
+import dns
+import dns.rcode
 import pytest
 
 from kresd import CERTS_DIR, Forward, make_kresd, PYTESTS_DIR
@@ -32,6 +34,7 @@ def test_rehandshake(tmpdir):
         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 == '127.0.0.1'
 
     hints = {
@@ -54,7 +57,7 @@ def test_rehandshake(tmpdir):
         ca_file = os.path.join(CERTS_DIR, 'tt.cert.pem')
         try:
             proxy = subprocess.Popen(
-                [cmd], cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+                [cmd], cwd=cwd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
 
             # run test kresd instance
             workdir2 = os.path.join(str(tmpdir), 'kresd')
@@ -63,19 +66,22 @@ def test_rehandshake(tmpdir):
                               hostname='transport-test-server.com', ca_file=ca_file)
             with make_kresd(workdir2, forward=forward) as kresd:
                 sock2 = kresd.ip_tcp_socket()
-                for hint in hints:
-                    resolve_hint(sock2, hint)
-                    time.sleep(1)
-
-                # verify log
-                n_connecting_to = 0
-                n_rehandshake = 0
-                for line in kresd.partial_log().splitlines():
-                    if re.search(r"connecting to: .*", line) is not None:
-                        n_connecting_to += 1
-                    elif re.search(r"TLS rehandshake .* has started", line) is not None:
-                        n_rehandshake += 1
-                assert n_connecting_to == 0  # shouldn't be present in partial log
-                assert n_rehandshake > 0
+                try:
+                    for hint in hints:
+                        resolve_hint(sock2, hint)
+                        time.sleep(0.1)
+                finally:
+                    # verify log
+                    n_connecting_to = 0
+                    n_rehandshake = 0
+                    partial_log = kresd.partial_log()
+                    print(partial_log)
+                    for line in partial_log.splitlines():
+                        if re.search(r"connecting to: .*", line) is not None:
+                            n_connecting_to += 1
+                        elif re.search(r"TLS rehandshake .* has started", line) is not None:
+                            n_rehandshake += 1
+                    assert n_connecting_to == 0  # shouldn't be present in partial log
+                    assert n_rehandshake > 0
         finally:
             proxy.terminate()