diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/examples/test_xss_scanner.py | 9 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_allowremote.py | 5 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_dumper.py | 14 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_intercept.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_proxyauth.py | 10 | ||||
-rw-r--r-- | test/mitmproxy/net/test_tcp.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/tools/console/test_master.py | 15 | ||||
-rw-r--r-- | test/mitmproxy/tools/console/test_statusbar.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/tools/test_dump.py | 2 |
9 files changed, 28 insertions, 33 deletions
diff --git a/test/examples/test_xss_scanner.py b/test/examples/test_xss_scanner.py index 8cf06a2a..610bdd72 100644 --- a/test/examples/test_xss_scanner.py +++ b/test/examples/test_xss_scanner.py @@ -296,6 +296,14 @@ class TestXSSScanner(): assert xss_info == expected_xss_info assert sqli_info is None + def mocked_socket_gethostbyname(domain): + claimed_domains = ["google.com"] + if domain not in claimed_domains: + from socket import gaierror + raise gaierror("[Errno -2] Name or service not known") + else: + return '216.58.221.46' + @pytest.fixture def logger(self): class Logger(): @@ -309,6 +317,7 @@ class TestXSSScanner(): def test_find_unclaimed_URLs(self, monkeypatch, logger): logger.args = [] monkeypatch.setattr("mitmproxy.ctx.log", logger) + monkeypatch.setattr("socket.gethostbyname", self.mocked_socket_gethostbyname) xss.find_unclaimed_URLs("<html><script src=\"http://google.com\"></script></html>", "https://example.com") assert logger.args == [] diff --git a/test/mitmproxy/addons/test_allowremote.py b/test/mitmproxy/addons/test_allowremote.py index 52dae68d..69019726 100644 --- a/test/mitmproxy/addons/test_allowremote.py +++ b/test/mitmproxy/addons/test_allowremote.py @@ -1,7 +1,7 @@ from unittest import mock import pytest -from mitmproxy.addons import allowremote +from mitmproxy.addons import allowremote, proxyauth from mitmproxy.test import taddons @@ -19,7 +19,8 @@ from mitmproxy.test import taddons ]) def test_allowremote(allow_remote, ip, should_be_killed): ar = allowremote.AllowRemote() - with taddons.context(ar) as tctx: + up = proxyauth.ProxyAuth() + with taddons.context(ar, up) as tctx: tctx.options.allow_remote = allow_remote with mock.patch('mitmproxy.proxy.protocol.base.Layer') as layer: diff --git a/test/mitmproxy/addons/test_dumper.py b/test/mitmproxy/addons/test_dumper.py index 9774e131..ead6b7e7 100644 --- a/test/mitmproxy/addons/test_dumper.py +++ b/test/mitmproxy/addons/test_dumper.py @@ -14,7 +14,7 @@ from mitmproxy import http def test_configure(): d = dumper.Dumper() - with taddons.context() as ctx: + with taddons.context(d) as ctx: ctx.configure(d, view_filter="~b foo") assert d.filter @@ -33,7 +33,7 @@ def test_configure(): def test_simple(): sio = io.StringIO() d = dumper.Dumper(sio) - with taddons.context() as ctx: + with taddons.context(d) as ctx: ctx.configure(d, flow_detail=0) d.response(tflow.tflow(resp=True)) assert not sio.getvalue() @@ -101,7 +101,7 @@ def test_echo_body(): sio = io.StringIO() d = dumper.Dumper(sio) - with taddons.context() as ctx: + with taddons.context(d) as ctx: ctx.configure(d, flow_detail=3) d._echo_message(f.response) t = sio.getvalue() @@ -111,7 +111,7 @@ def test_echo_body(): def test_echo_request_line(): sio = io.StringIO() d = dumper.Dumper(sio) - with taddons.context() as ctx: + with taddons.context(d) as ctx: ctx.configure(d, flow_detail=3, showhost=True) f = tflow.tflow(client_conn=None, server_conn=True, resp=True) f.request.is_replay = True @@ -146,7 +146,7 @@ class TestContentView: view_auto.side_effect = exceptions.ContentViewException("") sio = io.StringIO() d = dumper.Dumper(sio) - with taddons.context() as ctx: + with taddons.context(d) as ctx: ctx.configure(d, flow_detail=4, verbosity='debug') d.response(tflow.tflow()) assert ctx.master.has_log("content viewer failed") @@ -155,7 +155,7 @@ class TestContentView: def test_tcp(): sio = io.StringIO() d = dumper.Dumper(sio) - with taddons.context() as ctx: + with taddons.context(d) as ctx: ctx.configure(d, flow_detail=3, showhost=True) f = tflow.ttcpflow() d.tcp_message(f) @@ -170,7 +170,7 @@ def test_tcp(): def test_websocket(): sio = io.StringIO() d = dumper.Dumper(sio) - with taddons.context() as ctx: + with taddons.context(d) as ctx: ctx.configure(d, flow_detail=3, showhost=True) f = tflow.twebsocketflow() d.websocket_message(f) diff --git a/test/mitmproxy/addons/test_intercept.py b/test/mitmproxy/addons/test_intercept.py index d9598101..b3d24626 100644 --- a/test/mitmproxy/addons/test_intercept.py +++ b/test/mitmproxy/addons/test_intercept.py @@ -8,7 +8,7 @@ from mitmproxy.test import tflow def test_simple(): r = intercept.Intercept() - with taddons.context() as tctx: + with taddons.context(r) as tctx: assert not r.filt tctx.configure(r, intercept="~q") assert r.filt diff --git a/test/mitmproxy/addons/test_proxyauth.py b/test/mitmproxy/addons/test_proxyauth.py index 97259d1c..9e2365cf 100644 --- a/test/mitmproxy/addons/test_proxyauth.py +++ b/test/mitmproxy/addons/test_proxyauth.py @@ -49,7 +49,7 @@ class TestProxyAuth: ]) def test_is_proxy_auth(self, mode, expected): up = proxyauth.ProxyAuth() - with taddons.context() as ctx: + with taddons.context(up) as ctx: ctx.options.mode = mode assert up.is_proxy_auth() is expected @@ -75,7 +75,7 @@ class TestProxyAuth: def test_check(self): up = proxyauth.ProxyAuth() - with taddons.context() as ctx: + with taddons.context(up) as ctx: ctx.configure(up, proxyauth="any", mode="regular") f = tflow.tflow() assert not up.check(f) @@ -133,7 +133,7 @@ class TestProxyAuth: def test_authenticate(self): up = proxyauth.ProxyAuth() - with taddons.context() as ctx: + with taddons.context(up) as ctx: ctx.configure(up, proxyauth="any", mode="regular") f = tflow.tflow() @@ -165,7 +165,7 @@ class TestProxyAuth: def test_configure(self): up = proxyauth.ProxyAuth() - with taddons.context() as ctx: + with taddons.context(up) as ctx: with pytest.raises(exceptions.OptionsError): ctx.configure(up, proxyauth="foo") @@ -223,7 +223,7 @@ class TestProxyAuth: def test_handlers(self): up = proxyauth.ProxyAuth() - with taddons.context() as ctx: + with taddons.context(up) as ctx: ctx.configure(up, proxyauth="any", mode="regular") f = tflow.tflow() diff --git a/test/mitmproxy/net/test_tcp.py b/test/mitmproxy/net/test_tcp.py index 8c012e42..e862d0ad 100644 --- a/test/mitmproxy/net/test_tcp.py +++ b/test/mitmproxy/net/test_tcp.py @@ -485,7 +485,7 @@ class TestSSLDisconnect(tservers.ServerTestBase): c = tcp.TCPClient(("127.0.0.1", self.port)) with c.connect(): c.convert_to_tls() - # Excercise SSL.ZeroReturnError + # Exercise SSL.ZeroReturnError c.rfile.read(10) c.close() with pytest.raises(exceptions.TcpDisconnect): diff --git a/test/mitmproxy/tools/console/test_master.py b/test/mitmproxy/tools/console/test_master.py index 6ea61991..5be035e8 100644 --- a/test/mitmproxy/tools/console/test_master.py +++ b/test/mitmproxy/tools/console/test_master.py @@ -1,8 +1,6 @@ import urwid from mitmproxy import options -from mitmproxy.test import tflow -from mitmproxy.test import tutils from mitmproxy.tools import console from ... import tservers @@ -24,16 +22,3 @@ class TestMaster(tservers.MasterTest): except urwid.ExitMainLoop: pass assert len(m.view) == i - - def test_intercept(self): - """regression test for https://github.com/mitmproxy/mitmproxy/issues/1605""" - m = self.mkmaster(intercept="~b bar") - f = tflow.tflow(req=tutils.treq(content=b"foo")) - m.addons.handle_lifecycle("request", f) - assert not m.view[0].intercepted - f = tflow.tflow(req=tutils.treq(content=b"bar")) - m.addons.handle_lifecycle("request", f) - assert m.view[1].intercepted - f = tflow.tflow(resp=tutils.tresp(content=b"bar")) - m.addons.handle_lifecycle("request", f) - assert m.view[2].intercepted diff --git a/test/mitmproxy/tools/console/test_statusbar.py b/test/mitmproxy/tools/console/test_statusbar.py index ac17c5c0..db8a63a7 100644 --- a/test/mitmproxy/tools/console/test_statusbar.py +++ b/test/mitmproxy/tools/console/test_statusbar.py @@ -14,7 +14,7 @@ def test_statusbar(monkeypatch): view_filter="~dst example.com", stickycookie="~dst example.com", stickyauth="~dst example.com", - default_contentview="javascript", + console_default_contentview="javascript", anticache=True, anticomp=True, showhost=True, diff --git a/test/mitmproxy/tools/test_dump.py b/test/mitmproxy/tools/test_dump.py index 952c3f4f..f303c808 100644 --- a/test/mitmproxy/tools/test_dump.py +++ b/test/mitmproxy/tools/test_dump.py @@ -11,7 +11,7 @@ from .. import tservers class TestDumpMaster(tservers.MasterTest): def mkmaster(self, flt, **opts): - o = options.Options(view_filter=flt, verbosity='error', flow_detail=0, **opts) + o = options.Options(view_filter=flt, verbosity='error', **opts) m = dump.DumpMaster(o, with_termlog=False, with_dumper=False) return m |