diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/conftest.py | 13 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_check_alpn.py | 23 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_view.py | 4 | ||||
-rw-r--r-- | test/mitmproxy/data/no_common_name.pem | 96 | ||||
-rw-r--r-- | test/mitmproxy/net/test_tcp.py | 41 | ||||
-rw-r--r-- | test/mitmproxy/proxy/protocol/test_http2.py | 12 | ||||
-rw-r--r-- | test/mitmproxy/tools/console/conftest.py | 9 | ||||
-rw-r--r-- | test/mitmproxy/tools/console/test_master.py | 14 | ||||
-rw-r--r-- | test/mitmproxy/tools/console/test_statusbar.py | 34 | ||||
-rw-r--r-- | test/mitmproxy/tools/web/test_app.py | 4 | ||||
-rw-r--r-- | test/mitmproxy/utils/test_version_check.py | 25 | ||||
-rw-r--r-- | test/pathod/protocols/test_http2.py | 4 | ||||
-rw-r--r-- | test/pathod/test_pathoc.py | 15 | ||||
-rw-r--r-- | test/pathod/test_pathod.py | 6 |
14 files changed, 143 insertions, 157 deletions
diff --git a/test/conftest.py b/test/conftest.py index bb913548..b0842bc3 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,15 +1,8 @@ import os import pytest -import OpenSSL - -import mitmproxy.net.tcp pytest_plugins = ('test.full_coverage_plugin',) -requires_alpn = pytest.mark.skipif( - not mitmproxy.net.tcp.HAS_ALPN, - reason='requires OpenSSL with ALPN support') - skip_windows = pytest.mark.skipif( os.name == "nt", reason='Skipping due to Windows' @@ -24,9 +17,3 @@ skip_appveyor = pytest.mark.skipif( "APPVEYOR" in os.environ, reason='Skipping due to Appveyor' ) - - -@pytest.fixture() -def disable_alpn(monkeypatch): - monkeypatch.setattr(mitmproxy.net.tcp, 'HAS_ALPN', False) - monkeypatch.setattr(OpenSSL.SSL._lib, 'Cryptography_HAS_ALPN', False) diff --git a/test/mitmproxy/addons/test_check_alpn.py b/test/mitmproxy/addons/test_check_alpn.py deleted file mode 100644 index 2b1d6058..00000000 --- a/test/mitmproxy/addons/test_check_alpn.py +++ /dev/null @@ -1,23 +0,0 @@ -from mitmproxy.addons import check_alpn -from mitmproxy.test import taddons -from ...conftest import requires_alpn - - -class TestCheckALPN: - - @requires_alpn - def test_check_alpn(self): - msg = 'ALPN support missing' - - with taddons.context() as tctx: - a = check_alpn.CheckALPN() - tctx.configure(a) - assert not tctx.master.has_log(msg) - - def test_check_no_alpn(self, disable_alpn): - msg = 'ALPN support missing' - - with taddons.context() as tctx: - a = check_alpn.CheckALPN() - tctx.configure(a) - assert tctx.master.has_log(msg) diff --git a/test/mitmproxy/addons/test_view.py b/test/mitmproxy/addons/test_view.py index 40136f1f..e8eeb591 100644 --- a/test/mitmproxy/addons/test_view.py +++ b/test/mitmproxy/addons/test_view.py @@ -170,6 +170,10 @@ def test_load(tmpdir): assert len(v) == 2 v.load_file(path) assert len(v) == 4 + try: + v.load_file("nonexistent_file_path") + except IOError: + assert False def test_resolve(): diff --git a/test/mitmproxy/data/no_common_name.pem b/test/mitmproxy/data/no_common_name.pem index fc271a0e..d46448f5 100644 --- a/test/mitmproxy/data/no_common_name.pem +++ b/test/mitmproxy/data/no_common_name.pem @@ -1,20 +1,84 @@ -----BEGIN RSA PRIVATE KEY----- -MIIBOQIBAAJBAKVJ43C+8SjOvN9/pP/8HwzmHGQmRvdK/R6KlWdr7He6iiXDQNfH -RAp+gqX0hBRT80eRjGhSmTTBLCWiXVny4UUCAwEAAQJAUQ8nZ0d85VJd9g2XUaLH -Z4ACNGtBKk2wTKYSFyIqWZxsF5qhh7HGshJIAP6tYiX8ZW+mMSfme+zsJzWe8ChL -gQIhAM8QpAgUHnNteZvkv0XqceX1GILEWifMt+hO9yTp4dY5AiEAzFnKr77CKCri -/DPig4R/5q4KMpMx9EqJufHdGNmIA20CICMARxnufK86RCIr6oEg/hvG8Fu6YRr1 -Kekk3/XnavtRAiBVLVQ7vwKE5aNpRmMzOKZrS736aLpYvjz8IaFr+zgjXQIgdad5 -QZoTD49NTyM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fkC9m19nQHeYz3JlNC7sf80top2H2HEZMVVOAD+MxXkcAjNbjBRT3/KAIyWex +2fmoGRbvCIU0LFyyyk7/tG1xTgxNuBmd4Byz1LI25uz6eK4Ey8LeZmp5mvaewI53 +t65sAGBkx+LIRt0yGmMCRRFl735Ya4SJD7je1GTiw9I3Yd63dtaJTVd65kkFkLOk +LD56iJHSyCY6JkDXd8RjozIVoaXkVQh2wFq/ZfXzAgIx/u5cJQCMG2DAu6/WI74+ +7invOv7dbYfoI02N4iB57iRbPxE4gSrRayYxUVdH1R/tlXbN9Fkd30fl2WfSO897 +QC/ODA9w86FSFANhn6nv2KuKIMUSEW+5ZhBowSFIBEdAaMS7yj9uuBWmQKrWNfOh +mZJF1YiFmgRybkdKHPrlCSZyvVBdmnmM6g== -----END CERTIFICATE----- diff --git a/test/mitmproxy/net/test_tcp.py b/test/mitmproxy/net/test_tcp.py index 73de0879..3345840e 100644 --- a/test/mitmproxy/net/test_tcp.py +++ b/test/mitmproxy/net/test_tcp.py @@ -3,7 +3,6 @@ import queue import time import socket import random -import os import threading import pytest from unittest import mock @@ -15,7 +14,6 @@ from mitmproxy import exceptions from mitmproxy.test import tutils from . import tservers -from ...conftest import requires_alpn class EchoHandler(tcp.BaseHandler): @@ -534,36 +532,18 @@ class TestTimeOut(tservers.ServerTestBase): c.rfile.read(10) -class TestCryptographyALPN: - - def test_has_alpn(self): - if os.environ.get("OPENSSL") == "with-alpn": - assert tcp.HAS_ALPN - assert SSL._lib.Cryptography_HAS_ALPN - elif os.environ.get("OPENSSL") == "old": - assert not tcp.HAS_ALPN - assert not SSL._lib.Cryptography_HAS_ALPN - - class TestALPNClient(tservers.ServerTestBase): handler = ALPNHandler ssl = dict( alpn_select=b"bar" ) - @requires_alpn - @pytest.mark.parametrize('has_alpn,alpn_protos, expected_negotiated, expected_response', [ - (True, [b"foo", b"bar", b"fasel"], b'bar', b'bar'), - (True, [], b'', b'NONE'), - (True, None, b'', b'NONE'), - (False, [b"foo", b"bar", b"fasel"], b'', b'NONE'), - (False, [], b'', b'NONE'), - (False, None, b'', b'NONE'), + @pytest.mark.parametrize('alpn_protos, expected_negotiated, expected_response', [ + ([b"foo", b"bar", b"fasel"], b'bar', b'bar'), + ([], b'', b'NONE'), + (None, b'', b'NONE'), ]) - def test_alpn(self, monkeypatch, has_alpn, alpn_protos, expected_negotiated, expected_response): - monkeypatch.setattr(tcp, 'HAS_ALPN', has_alpn) - monkeypatch.setattr(SSL._lib, 'Cryptography_HAS_ALPN', has_alpn) - + def test_alpn(self, monkeypatch, alpn_protos, expected_negotiated, expected_response): c = tcp.TCPClient(("127.0.0.1", self.port)) with c.connect(): c.convert_to_ssl(alpn_protos=alpn_protos) @@ -574,7 +554,7 @@ class TestALPNClient(tservers.ServerTestBase): class TestNoSSLNoALPNClient(tservers.ServerTestBase): handler = ALPNHandler - def test_no_ssl_no_alpn(self, disable_alpn): + def test_no_ssl_no_alpn(self): c = tcp.TCPClient(("127.0.0.1", self.port)) with c.connect(): assert c.get_alpn_proto_negotiated() == b"" @@ -857,9 +837,8 @@ class TestSSLInvalid(tservers.ServerTestBase): 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="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") + with pytest.raises(exceptions.TlsException, match="ALPN error"): + c.create_ssl_context(alpn_select="foo", alpn_select_callback="bar") diff --git a/test/mitmproxy/proxy/protocol/test_http2.py b/test/mitmproxy/proxy/protocol/test_http2.py index 487d8890..583e6e27 100644 --- a/test/mitmproxy/proxy/protocol/test_http2.py +++ b/test/mitmproxy/proxy/protocol/test_http2.py @@ -17,7 +17,6 @@ from mitmproxy.net.http import http1, http2 from pathod.language import generators from ... import tservers -from ....conftest import requires_alpn import logging logging.getLogger("hyper.packages.hpack.hpack").setLevel(logging.WARNING) @@ -203,7 +202,6 @@ class _Http2Test(_Http2TestBase, _Http2ServerBase): _Http2ServerBase.teardown_class() -@requires_alpn class TestSimple(_Http2Test): request_body_buffer = b'' @@ -286,7 +284,6 @@ class TestSimple(_Http2Test): assert response_body_buffer == b'response body' -@requires_alpn class TestRequestWithPriority(_Http2Test): @classmethod @@ -368,7 +365,6 @@ class TestRequestWithPriority(_Http2Test): assert resp.headers.get('priority_weight', None) == expected_priority[2] -@requires_alpn class TestPriority(_Http2Test): @classmethod @@ -453,7 +449,6 @@ class TestPriority(_Http2Test): assert self.priority_data == expected_priority -@requires_alpn class TestStreamResetFromServer(_Http2Test): @classmethod @@ -504,7 +499,6 @@ class TestStreamResetFromServer(_Http2Test): assert self.master.state.flows[0].response is None -@requires_alpn class TestBodySizeLimit(_Http2Test): @classmethod @@ -554,7 +548,6 @@ class TestBodySizeLimit(_Http2Test): assert len(self.master.state.flows) == 0 -@requires_alpn class TestPushPromise(_Http2Test): @classmethod @@ -723,7 +716,6 @@ class TestPushPromise(_Http2Test): # the other two bodies might not be transmitted before the reset -@requires_alpn class TestConnectionLost(_Http2Test): @classmethod @@ -765,7 +757,6 @@ class TestConnectionLost(_Http2Test): assert self.master.state.flows[0].response is None -@requires_alpn class TestMaxConcurrentStreams(_Http2Test): @classmethod @@ -826,7 +817,6 @@ class TestMaxConcurrentStreams(_Http2Test): assert b"Stream-ID " in flow.response.content -@requires_alpn class TestConnectionTerminated(_Http2Test): @classmethod @@ -867,7 +857,6 @@ class TestConnectionTerminated(_Http2Test): assert connection_terminated_event.additional_data == b'foobar' -@requires_alpn class TestRequestStreaming(_Http2Test): @classmethod @@ -926,7 +915,6 @@ class TestRequestStreaming(_Http2Test): assert connection_terminated_event is None -@requires_alpn class TestResponseStreaming(_Http2Test): @classmethod diff --git a/test/mitmproxy/tools/console/conftest.py b/test/mitmproxy/tools/console/conftest.py new file mode 100644 index 00000000..afd94c6a --- /dev/null +++ b/test/mitmproxy/tools/console/conftest.py @@ -0,0 +1,9 @@ +from unittest import mock + +import pytest + + +@pytest.fixture(scope="module", autouse=True) +def definitely_atty(): + with mock.patch("sys.stdout.isatty", lambda: True): + yield diff --git a/test/mitmproxy/tools/console/test_master.py b/test/mitmproxy/tools/console/test_master.py index 7732483f..a3478bdc 100644 --- a/test/mitmproxy/tools/console/test_master.py +++ b/test/mitmproxy/tools/console/test_master.py @@ -1,20 +1,12 @@ -import pytest +import urwid +from mitmproxy import options +from mitmproxy import proxy from mitmproxy.test import tflow from mitmproxy.test import tutils from mitmproxy.tools import console -from mitmproxy import proxy -from mitmproxy import options from mitmproxy.tools.console import common from ... import tservers -import urwid -from unittest import mock - - -@pytest.fixture(scope="module", autouse=True) -def definitely_atty(): - with mock.patch("sys.stdout.isatty", lambda: True): - yield def test_format_keyvals(): diff --git a/test/mitmproxy/tools/console/test_statusbar.py b/test/mitmproxy/tools/console/test_statusbar.py new file mode 100644 index 00000000..55a3c4a0 --- /dev/null +++ b/test/mitmproxy/tools/console/test_statusbar.py @@ -0,0 +1,34 @@ +from mitmproxy import options, proxy +from mitmproxy.tools.console import statusbar, master + + +def test_statusbar(monkeypatch): + o = options.Options( + setheaders=[":~q:foo:bar"], + replacements=[":~q:foo:bar"], + ignore_hosts=["example.com", "example.org"], + tcp_hosts=["example.tcp"], + intercept="~q", + view_filter="~dst example.com", + stickycookie="~dst example.com", + stickyauth="~dst example.com", + default_contentview="javascript", + console_order="url", + anticache=True, + anticomp=True, + showhost=True, + refresh_server_playback=False, + replay_kill_extra=True, + upstream_cert=False, + console_focus_follow=True, + stream_large_bodies="3m", + mode="transparent", + scripts=["nonexistent"], + save_stream_file="foo", + ) + m = master.ConsoleMaster(o, proxy.DummyServer()) + monkeypatch.setattr(m.addons.get("clientplayback"), "count", lambda: 42) + monkeypatch.setattr(m.addons.get("serverplayback"), "count", lambda: 42) + + bar = statusbar.StatusBar(m) # this already causes a redraw + assert bar.ib._w diff --git a/test/mitmproxy/tools/web/test_app.py b/test/mitmproxy/tools/web/test_app.py index bb439b34..4d290284 100644 --- a/test/mitmproxy/tools/web/test_app.py +++ b/test/mitmproxy/tools/web/test_app.py @@ -263,6 +263,9 @@ class TestApp(tornado.testing.AsyncHTTPTestCase): assert self.put_json("/options", {"wtf": True}).code == 400 assert self.put_json("/options", {"anticache": "foo"}).code == 400 + def test_option_save(self): + assert self.fetch("/options/save", method="POST").code == 200 + def test_err(self): with mock.patch("mitmproxy.tools.web.app.IndexHandler.get") as f: f.side_effect = RuntimeError @@ -279,7 +282,6 @@ class TestApp(tornado.testing.AsyncHTTPTestCase): r2 = yield ws_client.read_message() j1 = _json.loads(r1) j2 = _json.loads(r2) - print(j1) response = dict() response[j1['resource']] = j1 response[j2['resource']] = j2 diff --git a/test/mitmproxy/utils/test_version_check.py b/test/mitmproxy/utils/test_version_check.py deleted file mode 100644 index d7929378..00000000 --- a/test/mitmproxy/utils/test_version_check.py +++ /dev/null @@ -1,25 +0,0 @@ -import io -from unittest import mock -from mitmproxy.utils import version_check - - -@mock.patch("sys.exit") -def test_check_pyopenssl_version(sexit): - fp = io.StringIO() - version_check.check_pyopenssl_version(fp=fp) - assert not fp.getvalue() - assert not sexit.called - - version_check.check_pyopenssl_version((9999,), fp=fp) - assert "outdated" in fp.getvalue() - assert sexit.called - - -@mock.patch("sys.exit") -@mock.patch("OpenSSL.__version__") -def test_unparseable_pyopenssl_version(version, sexit): - version.split.return_value = ["foo", "bar"] - fp = io.StringIO() - version_check.check_pyopenssl_version(fp=fp) - assert "Cannot parse" in fp.getvalue() - assert not sexit.called diff --git a/test/pathod/protocols/test_http2.py b/test/pathod/protocols/test_http2.py index c16a6d40..b1eebc73 100644 --- a/test/pathod/protocols/test_http2.py +++ b/test/pathod/protocols/test_http2.py @@ -11,8 +11,6 @@ from ...mitmproxy.net import tservers as net_tservers from pathod.protocols.http2 import HTTP2StateProtocol, TCPHandler -from ...conftest import requires_alpn - class TestTCPHandlerWrapper: def test_wrapped(self): @@ -68,7 +66,6 @@ class TestProtocol: assert mock_server_method.called -@requires_alpn class TestCheckALPNMatch(net_tservers.ServerTestBase): handler = EchoHandler ssl = dict( @@ -83,7 +80,6 @@ class TestCheckALPNMatch(net_tservers.ServerTestBase): assert protocol.check_alpn() -@requires_alpn class TestCheckALPNMismatch(net_tservers.ServerTestBase): handler = EchoHandler ssl = dict( diff --git a/test/pathod/test_pathoc.py b/test/pathod/test_pathoc.py index 2dd29e20..4b50e2a7 100644 --- a/test/pathod/test_pathoc.py +++ b/test/pathod/test_pathoc.py @@ -11,7 +11,6 @@ from pathod.protocols.http2 import HTTP2StateProtocol from mitmproxy.test import tutils from . import tservers -from ..conftest import requires_alpn def test_response(): @@ -216,7 +215,6 @@ class TestDaemonHTTP2(PathocTestDaemon): ssl = True explain = False - @requires_alpn def test_http2(self): c = pathoc.Pathoc( ("127.0.0.1", self.d.port), @@ -231,7 +229,6 @@ class TestDaemonHTTP2(PathocTestDaemon): ) assert c.protocol == http1 - @requires_alpn def test_http2_alpn(self): c = pathoc.Pathoc( ("127.0.0.1", self.d.port), @@ -248,7 +245,6 @@ class TestDaemonHTTP2(PathocTestDaemon): _, kwargs = c.convert_to_ssl.call_args assert set(kwargs['alpn_protos']) == set([b'http/1.1', b'h2']) - @requires_alpn def test_request(self): c = pathoc.Pathoc( ("127.0.0.1", self.d.port), @@ -259,14 +255,3 @@ class TestDaemonHTTP2(PathocTestDaemon): with c.connect(): resp = c.request("get:/p/200") assert resp.status_code == 200 - - def test_failing_request(self, disable_alpn): - c = pathoc.Pathoc( - ("127.0.0.1", self.d.port), - fp=None, - ssl=True, - use_http2=True, - ) - with pytest.raises(NotImplementedError): - with c.connect(): - c.request("get:/p/200") diff --git a/test/pathod/test_pathod.py b/test/pathod/test_pathod.py index 88480a59..5f191c0d 100644 --- a/test/pathod/test_pathod.py +++ b/test/pathod/test_pathod.py @@ -8,7 +8,6 @@ from mitmproxy import exceptions from mitmproxy.test import tutils from . import tservers -from ..conftest import requires_alpn class TestPathod: @@ -257,11 +256,6 @@ class TestHTTP2(tservers.DaemonTests): ssl = True nohang = True - @requires_alpn def test_http2(self): r, _ = self.pathoc(["GET:/"], ssl=True, use_http2=True) assert r[0].status_code == 800 - - def test_no_http2(self, disable_alpn): - with pytest.raises(NotImplementedError): - r, _ = self.pathoc(["GET:/"], ssl=True, use_http2=True) |