diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/contrib/test_tls_parser.py | 38 | ||||
-rw-r--r-- | test/mitmproxy/net/test_tcp.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/proxy/protocol/test_tls.py | 3 | ||||
-rw-r--r-- | test/pathod/language/test_generators.py | 12 | ||||
-rw-r--r-- | test/pathod/test_test.py | 40 | ||||
-rw-r--r-- | test/pathod/tservers.py | 4 |
6 files changed, 22 insertions, 77 deletions
diff --git a/test/mitmproxy/contrib/test_tls_parser.py b/test/mitmproxy/contrib/test_tls_parser.py deleted file mode 100644 index 66972b62..00000000 --- a/test/mitmproxy/contrib/test_tls_parser.py +++ /dev/null @@ -1,38 +0,0 @@ -from mitmproxy.contrib import tls_parser - - -def test_parse_chrome(): - """ - Test if we properly parse a ClientHello sent by Chrome 54. - """ - data = bytes.fromhex( - "03033b70638d2523e1cba15f8364868295305e9c52aceabda4b5147210abc783e6e1000022c02bc02fc02cc030" - "cca9cca8cc14cc13c009c013c00ac014009c009d002f0035000a0100006cff0100010000000010000e00000b65" - "78616d706c652e636f6d0017000000230000000d00120010060106030501050304010403020102030005000501" - "00000000001200000010000e000c02683208687474702f312e3175500000000b00020100000a00080006001d00" - "170018" - ) - c = tls_parser.ClientHello.parse(data) - assert c.version.major == 3 - assert c.version.minor == 3 - - alpn = [a for a in c.extensions.extensions if a.type == 16] - assert len(alpn) == 1 - assert alpn[0].alpn_protocols == [b"h2", b"http/1.1"] - - sni = [a for a in c.extensions.extensions if a.type == 0] - assert len(sni) == 1 - assert sni[0].server_names[0].name_type == 0 - assert sni[0].server_names[0].host_name == b"example.com" - - -def test_parse_no_extensions(): - data = bytes.fromhex( - "03015658a756ab2c2bff55f636814deac086b7ca56b65058c7893ffc6074f5245f70205658a75475103a152637" - "78e1bb6d22e8bbd5b6b0a3a59760ad354e91ba20d353001a0035002f000a000500040009000300060008006000" - "61006200640100" - ) - c = tls_parser.ClientHello.parse(data) - assert c.version.major == 3 - assert c.version.minor == 1 - assert c.extensions is None diff --git a/test/mitmproxy/net/test_tcp.py b/test/mitmproxy/net/test_tcp.py index 234e8afb..adf8701a 100644 --- a/test/mitmproxy/net/test_tcp.py +++ b/test/mitmproxy/net/test_tcp.py @@ -391,7 +391,7 @@ class TestSNI(tservers.ServerTestBase): class TestServerCipherList(tservers.ServerTestBase): handler = ClientCipherListHandler ssl = dict( - cipher_list=b'AES256-GCM-SHA384' + cipher_list='AES256-GCM-SHA384' ) def test_echo(self): diff --git a/test/mitmproxy/proxy/protocol/test_tls.py b/test/mitmproxy/proxy/protocol/test_tls.py index e17ee46f..980ba7bd 100644 --- a/test/mitmproxy/proxy/protocol/test_tls.py +++ b/test/mitmproxy/proxy/protocol/test_tls.py @@ -23,4 +23,5 @@ class TestClientHello: ) c = TlsClientHello(data) assert c.sni == 'example.com' - assert c.alpn_protocols == [b'h2', b'http/1.1'] + assert c.alpn_protocols[0].name == b'h2' + assert c.alpn_protocols[1].name == b'http/1.1' diff --git a/test/pathod/language/test_generators.py b/test/pathod/language/test_generators.py index 6a67ab72..5e64c726 100644 --- a/test/pathod/language/test_generators.py +++ b/test/pathod/language/test_generators.py @@ -14,16 +14,14 @@ def test_randomgenerator(): def test_filegenerator(tmpdir): f = tmpdir.join("foo") - f.write(b"x" * 10000) + f.write(b"abcdefghijklmnopqrstuvwxyz" * 1000) g = generators.FileGenerator(str(f)) - assert len(g) == 10000 - assert g[0] == b"x" - assert g[-1] == b"x" - assert g[0:5] == b"xxxxx" + assert len(g) == 26000 + assert g[0] == b"a" + assert g[2:7] == b"cdefg" assert len(g[1:10]) == 9 - assert len(g[10000:10001]) == 0 + assert len(g[26000:26001]) == 0 assert repr(g) - g.close() def test_transform_generator(): diff --git a/test/pathod/test_test.py b/test/pathod/test_test.py index 40f45f53..d51a2c7a 100644 --- a/test/pathod/test_test.py +++ b/test/pathod/test_test.py @@ -1,15 +1,9 @@ -import logging +import os import requests import pytest from pathod import test - -from mitmproxy.test import tutils - -import requests.packages.urllib3 - -requests.packages.urllib3.disable_warnings() -logging.disable(logging.CRITICAL) +from pathod.pathod import SSLOptions, CA_CERT_NAME class TestDaemonManual: @@ -22,29 +16,17 @@ class TestDaemonManual: with pytest.raises(requests.ConnectionError): requests.get("http://localhost:%s/p/202:da" % d.port) - def test_startstop_ssl(self): - d = test.Daemon(ssl=True) - rsp = requests.get( - "https://localhost:%s/p/202:da" % - d.port, - verify=False) - assert rsp.ok - assert rsp.status_code == 202 - d.shutdown() - with pytest.raises(requests.ConnectionError): - requests.get("http://localhost:%s/p/202:da" % d.port) - - def test_startstop_ssl_explicit(self): - ssloptions = dict( - certfile=tutils.test_data.path("pathod/data/testkey.pem"), - cacert=tutils.test_data.path("pathod/data/testkey.pem"), - ssl_after_connect=False + @pytest.mark.parametrize('not_after_connect', [True, False]) + def test_startstop_ssl(self, not_after_connect): + ssloptions = SSLOptions( + cn=b'localhost', + sans=[b'localhost', b'127.0.0.1'], + not_after_connect=not_after_connect, ) - d = test.Daemon(ssl=ssloptions) + d = test.Daemon(ssl=True, ssloptions=ssloptions) rsp = requests.get( - "https://localhost:%s/p/202:da" % - d.port, - verify=False) + "https://localhost:%s/p/202:da" % d.port, + verify=os.path.expanduser(os.path.join(d.thread.server.ssloptions.confdir, CA_CERT_NAME))) assert rsp.ok assert rsp.status_code == 202 d.shutdown() diff --git a/test/pathod/tservers.py b/test/pathod/tservers.py index fab09288..a7c92964 100644 --- a/test/pathod/tservers.py +++ b/test/pathod/tservers.py @@ -1,3 +1,4 @@ +import os import tempfile import re import shutil @@ -13,6 +14,7 @@ from pathod import language from pathod import pathoc from pathod import pathod from pathod import test +from pathod.pathod import CA_CERT_NAME def treader(bytes): @@ -72,7 +74,7 @@ class DaemonTests: self.d.port, path ), - verify=False, + verify=os.path.join(self.d.thread.server.ssloptions.confdir, CA_CERT_NAME), params=params ) return resp |