diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/full_coverage_plugin.py | 7 | ||||
-rw-r--r-- | test/mitmproxy/net/test_tcp.py | 43 |
2 files changed, 45 insertions, 5 deletions
diff --git a/test/full_coverage_plugin.py b/test/full_coverage_plugin.py index d98c29d6..ec30a9f9 100644 --- a/test/full_coverage_plugin.py +++ b/test/full_coverage_plugin.py @@ -1,6 +1,7 @@ import os import configparser import pytest +import sys here = os.path.abspath(os.path.dirname(__file__)) @@ -59,6 +60,12 @@ def pytest_runtestloop(session): if os.name == 'nt': cov.exclude('pragma: windows no cover') + if sys.platform == 'darwin': + cov.exclude('pragma: osx no cover') + + if os.environ.get("OPENSSL") == "old": + cov.exclude('pragma: openssl-old no cover') + yield coverage_values = dict([(name, 0) for name in pytest.config.option.full_cov]) diff --git a/test/mitmproxy/net/test_tcp.py b/test/mitmproxy/net/test_tcp.py index 8b26784a..81d51888 100644 --- a/test/mitmproxy/net/test_tcp.py +++ b/test/mitmproxy/net/test_tcp.py @@ -529,10 +529,10 @@ class TestTimeOut(tservers.ServerTestBase): class TestCryptographyALPN: def test_has_alpn(self): - if 'OPENSSL_ALPN' in os.environ: + if os.environ.get("OPENSSL") == "with-alpn": assert tcp.HAS_ALPN assert SSL._lib.Cryptography_HAS_ALPN - elif 'OPENSSL_OLD' in os.environ: + elif os.environ.get("OPENSSL") == "old": assert not tcp.HAS_ALPN assert not SSL._lib.Cryptography_HAS_ALPN @@ -603,13 +603,36 @@ class TestDHParams(tservers.ServerTestBase): assert ret[0] == "DHE-RSA-AES256-SHA" -class TestTCPClient: +class TestTCPClient(tservers.ServerTestBase): def test_conerr(self): c = tcp.TCPClient(("127.0.0.1", 0)) - with pytest.raises(exceptions.TcpException): + with pytest.raises(exceptions.TcpException, match="Error connecting"): c.connect() + def test_timeout(self): + c = tcp.TCPClient(("127.0.0.1", self.port)) + with c.create_connection(timeout=20) as conn: + assert conn.gettimeout() == 20 + + def test_spoof_address(self): + c = tcp.TCPClient(("127.0.0.1", self.port), spoof_source_address=("127.0.0.1", 0)) + with pytest.raises(exceptions.TcpException, match="Failed to spoof"): + c.connect() + + +class TestTCPServer: + + def test_binderr(self): + with pytest.raises(socket.error, match="prohibited"): + tcp.TCPServer(("localhost", 8080)) + + def test_wait_for_silence(self): + s = tcp.TCPServer(("127.0.0.1", 0)) + with s.handler_counter: + with pytest.raises(exceptions.Timeout): + s.wait_for_silence() + class TestFileLike: @@ -811,7 +834,7 @@ class TestSSLKeyLogger(tservers.ServerTestBase): assert not tcp.SSLKeyLogger.create_logfun(False) -class TestSSLInvalidMethod(tservers.ServerTestBase): +class TestSSLInvalid(tservers.ServerTestBase): handler = EchoHandler ssl = True @@ -821,3 +844,13 @@ class TestSSLInvalidMethod(tservers.ServerTestBase): with c.connect(): with pytest.raises(exceptions.TlsException): c.convert_to_ssl(method=fake_ssl_method) + + def test_alpn_error(self): + c = tcp.TCPClient(("127.0.0.1", self.port)) + with c.connect(): + if tcp.HAS_ALPN: + with pytest.raises(exceptions.TlsException, match="must be a function"): + c.create_ssl_context(alpn_select_callback="foo") + + with pytest.raises(exceptions.TlsException, match="ALPN error"): + c.create_ssl_context(alpn_select="foo", alpn_select_callback="bar") |