aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/examples/test_xss_scanner.py12
-rwxr-xr-xtest/helper_tools/dumperview.py3
-rw-r--r--test/mitmproxy/addons/test_allowremote.py6
-rw-r--r--test/mitmproxy/addons/test_anticache.py2
-rw-r--r--test/mitmproxy/addons/test_anticomp.py2
-rw-r--r--test/mitmproxy/addons/test_clientplayback.py6
-rw-r--r--test/mitmproxy/addons/test_core.py99
-rw-r--r--test/mitmproxy/addons/test_core_option_validation.py42
-rw-r--r--test/mitmproxy/addons/test_dumper.py23
-rw-r--r--test/mitmproxy/addons/test_intercept.py3
-rw-r--r--test/mitmproxy/addons/test_keepserving.py3
-rw-r--r--test/mitmproxy/addons/test_onboarding.py18
-rw-r--r--test/mitmproxy/addons/test_proxyauth.py10
-rw-r--r--test/mitmproxy/addons/test_readfile.py10
-rw-r--r--test/mitmproxy/addons/test_replace.py10
-rw-r--r--test/mitmproxy/addons/test_save.py3
-rw-r--r--test/mitmproxy/addons/test_script.py13
-rw-r--r--test/mitmproxy/addons/test_serverplayback.py38
-rw-r--r--test/mitmproxy/addons/test_setheaders.py4
-rw-r--r--test/mitmproxy/addons/test_stickyauth.py4
-rw-r--r--test/mitmproxy/addons/test_stickycookie.py16
-rw-r--r--test/mitmproxy/addons/test_streambodies.py2
-rw-r--r--test/mitmproxy/addons/test_termlog.py4
-rw-r--r--test/mitmproxy/addons/test_upstream_auth.py6
-rw-r--r--test/mitmproxy/contentviews/test_api.py13
-rw-r--r--test/mitmproxy/net/http/test_cookies.py21
-rw-r--r--test/mitmproxy/net/test_tcp.py2
-rw-r--r--test/mitmproxy/proxy/protocol/test_http2.py2
-rw-r--r--test/mitmproxy/proxy/protocol/test_websocket.py2
-rw-r--r--test/mitmproxy/proxy/test_config.py18
-rw-r--r--test/mitmproxy/proxy/test_server.py41
-rw-r--r--test/mitmproxy/test_addonmanager.py2
-rw-r--r--test/mitmproxy/test_command.py16
-rw-r--r--test/mitmproxy/test_optmanager.py6
-rw-r--r--test/mitmproxy/test_proxy.py5
-rw-r--r--test/mitmproxy/tools/console/test_master.py21
-rw-r--r--test/mitmproxy/tools/console/test_statusbar.py14
-rw-r--r--test/mitmproxy/tools/test_dump.py6
-rw-r--r--test/mitmproxy/tools/web/test_static_viewer.py5
-rw-r--r--test/mitmproxy/tservers.py7
40 files changed, 244 insertions, 276 deletions
diff --git a/test/examples/test_xss_scanner.py b/test/examples/test_xss_scanner.py
index 8cf06a2a..1d723d53 100644
--- a/test/examples/test_xss_scanner.py
+++ b/test/examples/test_xss_scanner.py
@@ -296,12 +296,23 @@ 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():
def __init__(self):
self.args = []
+ def info(self, str):
+ self.args.append(str)
+
def error(self, str):
self.args.append(str)
return Logger()
@@ -309,6 +320,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/helper_tools/dumperview.py b/test/helper_tools/dumperview.py
index d417d767..e17dc77b 100755
--- a/test/helper_tools/dumperview.py
+++ b/test/helper_tools/dumperview.py
@@ -4,12 +4,11 @@ import click
from mitmproxy.addons import dumper
from mitmproxy.test import tflow
from mitmproxy.test import taddons
-from mitmproxy.tools import options
def show(flow_detail, flows):
d = dumper.Dumper()
- with taddons.context(options=options.Options()) as ctx:
+ with taddons.context() as ctx:
ctx.configure(d, flow_detail=flow_detail)
for f in flows:
ctx.cycle(d, f)
diff --git a/test/mitmproxy/addons/test_allowremote.py b/test/mitmproxy/addons/test_allowremote.py
index 9fc71525..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,8 +19,8 @@ from mitmproxy.test import taddons
])
def test_allowremote(allow_remote, ip, should_be_killed):
ar = allowremote.AllowRemote()
- with taddons.context() as tctx:
- tctx.master.addons.register(ar)
+ 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_anticache.py b/test/mitmproxy/addons/test_anticache.py
index 928f2180..d1765fe0 100644
--- a/test/mitmproxy/addons/test_anticache.py
+++ b/test/mitmproxy/addons/test_anticache.py
@@ -7,7 +7,7 @@ from mitmproxy.test import taddons
class TestAntiCache:
def test_simple(self):
sa = anticache.AntiCache()
- with taddons.context() as tctx:
+ with taddons.context(sa) as tctx:
f = tflow.tflow(resp=True)
f.request.headers["if-modified-since"] = "test"
f.request.headers["if-none-match"] = "test"
diff --git a/test/mitmproxy/addons/test_anticomp.py b/test/mitmproxy/addons/test_anticomp.py
index 2a6cf3ce..92650332 100644
--- a/test/mitmproxy/addons/test_anticomp.py
+++ b/test/mitmproxy/addons/test_anticomp.py
@@ -7,7 +7,7 @@ from mitmproxy.test import taddons
class TestAntiComp:
def test_simple(self):
sa = anticomp.AntiComp()
- with taddons.context() as tctx:
+ with taddons.context(sa) as tctx:
f = tflow.tflow(resp=True)
sa.request(f)
diff --git a/test/mitmproxy/addons/test_clientplayback.py b/test/mitmproxy/addons/test_clientplayback.py
index 3f990668..f172af83 100644
--- a/test/mitmproxy/addons/test_clientplayback.py
+++ b/test/mitmproxy/addons/test_clientplayback.py
@@ -24,7 +24,7 @@ class MockThread():
class TestClientPlayback:
def test_playback(self):
cp = clientplayback.ClientPlayback()
- with taddons.context() as tctx:
+ with taddons.context(cp) as tctx:
assert cp.count() == 0
f = tflow.tflow(resp=True)
cp.start_replay([f])
@@ -58,7 +58,7 @@ class TestClientPlayback:
def test_load_file(self, tmpdir):
cp = clientplayback.ClientPlayback()
- with taddons.context():
+ with taddons.context(cp):
fpath = str(tmpdir.join("flows"))
tdump(fpath, [tflow.tflow(resp=True)])
cp.load_file(fpath)
@@ -68,7 +68,7 @@ class TestClientPlayback:
def test_configure(self, tmpdir):
cp = clientplayback.ClientPlayback()
- with taddons.context() as tctx:
+ with taddons.context(cp) as tctx:
path = str(tmpdir.join("flows"))
tdump(path, [tflow.tflow()])
tctx.configure(cp, client_replay=[path])
diff --git a/test/mitmproxy/addons/test_core.py b/test/mitmproxy/addons/test_core.py
index 5aa4ef37..3c674b3f 100644
--- a/test/mitmproxy/addons/test_core.py
+++ b/test/mitmproxy/addons/test_core.py
@@ -1,18 +1,19 @@
+from unittest import mock
+
from mitmproxy.addons import core
from mitmproxy.test import taddons
from mitmproxy.test import tflow
+from mitmproxy.test import tutils
from mitmproxy import exceptions
import pytest
def test_set():
sa = core.Core()
- with taddons.context() as tctx:
- tctx.master.addons.add(sa)
-
- assert not tctx.master.options.anticomp
- tctx.command(sa.set, "anticomp")
- assert tctx.master.options.anticomp
+ with taddons.context(loadcore=False) as tctx:
+ assert tctx.master.options.server
+ tctx.command(sa.set, "server=false")
+ assert not tctx.master.options.server
with pytest.raises(exceptions.CommandError):
tctx.command(sa.set, "nonexistent")
@@ -20,7 +21,7 @@ def test_set():
def test_resume():
sa = core.Core()
- with taddons.context():
+ with taddons.context(loadcore=False):
f = tflow.tflow()
assert not sa.resume([f])
f.intercept()
@@ -30,7 +31,7 @@ def test_resume():
def test_mark():
sa = core.Core()
- with taddons.context():
+ with taddons.context(loadcore=False):
f = tflow.tflow()
assert not f.marked
sa.mark([f], True)
@@ -44,7 +45,7 @@ def test_mark():
def test_kill():
sa = core.Core()
- with taddons.context():
+ with taddons.context(loadcore=False):
f = tflow.tflow()
f.intercept()
assert f.killable
@@ -54,7 +55,7 @@ def test_kill():
def test_revert():
sa = core.Core()
- with taddons.context():
+ with taddons.context(loadcore=False):
f = tflow.tflow()
f.backup()
f.request.content = b"bar"
@@ -65,7 +66,7 @@ def test_revert():
def test_flow_set():
sa = core.Core()
- with taddons.context():
+ with taddons.context(loadcore=False):
f = tflow.tflow(resp=True)
assert sa.flow_set_options()
@@ -101,7 +102,7 @@ def test_flow_set():
def test_encoding():
sa = core.Core()
- with taddons.context():
+ with taddons.context(loadcore=False):
f = tflow.tflow()
assert sa.encode_options()
sa.encode([f], "request", "deflate")
@@ -128,28 +129,23 @@ def test_options(tmpdir):
p = str(tmpdir.join("path"))
sa = core.Core()
with taddons.context() as tctx:
- tctx.options.stickycookie = "foo"
- assert tctx.options.stickycookie == "foo"
- sa.options_reset()
- assert tctx.options.stickycookie is None
-
- tctx.options.stickycookie = "foo"
- tctx.options.stickyauth = "bar"
- sa.options_reset_one("stickycookie")
- assert tctx.options.stickycookie is None
- assert tctx.options.stickyauth == "bar"
+ tctx.options.listen_host = "foo"
+ assert tctx.options.listen_host == "foo"
+ sa.options_reset_one("listen_host")
+ assert tctx.options.listen_host != "foo"
with pytest.raises(exceptions.CommandError):
sa.options_reset_one("unknown")
+ tctx.options.listen_host = "foo"
sa.options_save(p)
with pytest.raises(exceptions.CommandError):
sa.options_save("/")
sa.options_reset()
- assert tctx.options.stickyauth is None
+ assert tctx.options.listen_host == ""
sa.options_load(p)
- assert tctx.options.stickyauth == "bar"
+ assert tctx.options.listen_host == "foo"
sa.options_load("/nonexistent")
@@ -157,3 +153,58 @@ def test_options(tmpdir):
f.write("'''")
with pytest.raises(exceptions.CommandError):
sa.options_load(p)
+
+
+def test_validation_simple():
+ sa = core.Core()
+ with taddons.context() as tctx:
+ with pytest.raises(exceptions.OptionsError):
+ tctx.configure(sa, body_size_limit = "invalid")
+ tctx.configure(sa, body_size_limit = "1m")
+
+ with pytest.raises(exceptions.OptionsError, match="mutually exclusive"):
+ tctx.configure(
+ sa,
+ add_upstream_certs_to_client_chain = True,
+ upstream_cert = False
+ )
+ with pytest.raises(exceptions.OptionsError, match="requires certificate verification to be disabled"):
+ tctx.configure(
+ sa,
+ add_upstream_certs_to_client_chain = True,
+ ssl_insecure = False
+ )
+ with pytest.raises(exceptions.OptionsError, match="Invalid mode"):
+ tctx.configure(
+ sa,
+ mode = "Flibble"
+ )
+
+
+@mock.patch("mitmproxy.platform.original_addr", None)
+def test_validation_no_transparent():
+ sa = core.Core()
+ with taddons.context() as tctx:
+ with pytest.raises(Exception, match="Transparent mode not supported"):
+ tctx.configure(sa, mode = "transparent")
+
+
+@mock.patch("mitmproxy.platform.original_addr")
+def test_validation_modes(m):
+ sa = core.Core()
+ with taddons.context() as tctx:
+ tctx.configure(sa, mode = "reverse:http://localhost")
+ with pytest.raises(Exception, match="Invalid server specification"):
+ tctx.configure(sa, mode = "reverse:")
+
+
+def test_client_certs():
+ sa = core.Core()
+ with taddons.context() as tctx:
+ # Folders should work.
+ tctx.configure(sa, client_certs = tutils.test_data.path("mitmproxy/data/clientcert"))
+ # Files, too.
+ tctx.configure(sa, client_certs = tutils.test_data.path("mitmproxy/data/clientcert/client.pem"))
+
+ with pytest.raises(exceptions.OptionsError, match="certificate path does not exist"):
+ tctx.configure(sa, client_certs = "invalid")
diff --git a/test/mitmproxy/addons/test_core_option_validation.py b/test/mitmproxy/addons/test_core_option_validation.py
deleted file mode 100644
index cd5d4dfa..00000000
--- a/test/mitmproxy/addons/test_core_option_validation.py
+++ /dev/null
@@ -1,42 +0,0 @@
-from mitmproxy import exceptions
-from mitmproxy.addons import core_option_validation
-from mitmproxy.test import taddons
-import pytest
-from unittest import mock
-
-
-def test_simple():
- sa = core_option_validation.CoreOptionValidation()
- with taddons.context() as tctx:
- with pytest.raises(exceptions.OptionsError):
- tctx.configure(sa, body_size_limit = "invalid")
- tctx.configure(sa, body_size_limit = "1m")
-
- with pytest.raises(exceptions.OptionsError, match="mutually exclusive"):
- tctx.configure(
- sa,
- add_upstream_certs_to_client_chain = True,
- upstream_cert = False
- )
- with pytest.raises(exceptions.OptionsError, match="Invalid mode"):
- tctx.configure(
- sa,
- mode = "Flibble"
- )
-
-
-@mock.patch("mitmproxy.platform.original_addr", None)
-def test_no_transparent():
- sa = core_option_validation.CoreOptionValidation()
- with taddons.context() as tctx:
- with pytest.raises(Exception, match="Transparent mode not supported"):
- tctx.configure(sa, mode = "transparent")
-
-
-@mock.patch("mitmproxy.platform.original_addr")
-def test_modes(m):
- sa = core_option_validation.CoreOptionValidation()
- with taddons.context() as tctx:
- tctx.configure(sa, mode = "reverse:http://localhost")
- with pytest.raises(Exception, match="Invalid server specification"):
- tctx.configure(sa, mode = "reverse:")
diff --git a/test/mitmproxy/addons/test_dumper.py b/test/mitmproxy/addons/test_dumper.py
index fb80f3ce..228bacf8 100644
--- a/test/mitmproxy/addons/test_dumper.py
+++ b/test/mitmproxy/addons/test_dumper.py
@@ -10,13 +10,12 @@ from mitmproxy.test import tutils
from mitmproxy.addons import dumper
from mitmproxy import exceptions
from mitmproxy import http
-from mitmproxy import options
def test_configure():
d = dumper.Dumper()
- with taddons.context(options=options.Options()) as ctx:
- ctx.configure(d, view_filter="~b foo")
+ with taddons.context(d) as ctx:
+ ctx.configure(d, dumper_filter="~b foo")
assert d.filter
f = tflow.tflow(resp=True)
@@ -24,17 +23,17 @@ def test_configure():
f.response.content = b"foo"
assert d.match(f)
- ctx.configure(d, view_filter=None)
+ ctx.configure(d, dumper_filter=None)
assert not d.filter
with pytest.raises(exceptions.OptionsError):
- ctx.configure(d, view_filter="~~")
+ ctx.configure(d, dumper_filter="~~")
assert not d.filter
def test_simple():
sio = io.StringIO()
d = dumper.Dumper(sio)
- with taddons.context(options=options.Options()) as ctx:
+ with taddons.context(d) as ctx:
ctx.configure(d, flow_detail=0)
d.response(tflow.tflow(resp=True))
assert not sio.getvalue()
@@ -102,7 +101,7 @@ def test_echo_body():
sio = io.StringIO()
d = dumper.Dumper(sio)
- with taddons.context(options=options.Options()) as ctx:
+ with taddons.context(d) as ctx:
ctx.configure(d, flow_detail=3)
d._echo_message(f.response)
t = sio.getvalue()
@@ -112,7 +111,7 @@ def test_echo_body():
def test_echo_request_line():
sio = io.StringIO()
d = dumper.Dumper(sio)
- with taddons.context(options=options.Options()) 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
@@ -147,8 +146,8 @@ class TestContentView:
view_auto.side_effect = exceptions.ContentViewException("")
sio = io.StringIO()
d = dumper.Dumper(sio)
- with taddons.context(options=options.Options()) as ctx:
- ctx.configure(d, flow_detail=4, verbosity='debug')
+ with taddons.context(d) as ctx:
+ ctx.configure(d, flow_detail=4)
d.response(tflow.tflow())
assert ctx.master.has_log("content viewer failed")
@@ -156,7 +155,7 @@ class TestContentView:
def test_tcp():
sio = io.StringIO()
d = dumper.Dumper(sio)
- with taddons.context(options=options.Options()) as ctx:
+ with taddons.context(d) as ctx:
ctx.configure(d, flow_detail=3, showhost=True)
f = tflow.ttcpflow()
d.tcp_message(f)
@@ -171,7 +170,7 @@ def test_tcp():
def test_websocket():
sio = io.StringIO()
d = dumper.Dumper(sio)
- with taddons.context(options=options.Options()) 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 d4999eb5..b3d24626 100644
--- a/test/mitmproxy/addons/test_intercept.py
+++ b/test/mitmproxy/addons/test_intercept.py
@@ -1,7 +1,6 @@
import pytest
from mitmproxy.addons import intercept
-from mitmproxy import options
from mitmproxy import exceptions
from mitmproxy.test import taddons
from mitmproxy.test import tflow
@@ -9,7 +8,7 @@ from mitmproxy.test import tflow
def test_simple():
r = intercept.Intercept()
- with taddons.context(options=options.Options()) 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_keepserving.py b/test/mitmproxy/addons/test_keepserving.py
index 70f7e1e6..2869d097 100644
--- a/test/mitmproxy/addons/test_keepserving.py
+++ b/test/mitmproxy/addons/test_keepserving.py
@@ -4,7 +4,6 @@ from mitmproxy.test import taddons
def test_keepserving():
ks = keepserving.KeepServing()
-
- with taddons.context() as tctx:
+ with taddons.context(ks) as tctx:
ks.event_processing_complete()
assert tctx.master.should_exit.is_set()
diff --git a/test/mitmproxy/addons/test_onboarding.py b/test/mitmproxy/addons/test_onboarding.py
index 474e6c3c..810ddef1 100644
--- a/test/mitmproxy/addons/test_onboarding.py
+++ b/test/mitmproxy/addons/test_onboarding.py
@@ -2,7 +2,6 @@ import pytest
from mitmproxy.addons import onboarding
from mitmproxy.test import taddons
-from mitmproxy import options
from .. import tservers
@@ -11,25 +10,28 @@ class TestApp(tservers.HTTPProxyTest):
return [onboarding.Onboarding()]
def test_basic(self):
- with taddons.context() as tctx:
- tctx.configure(self.addons()[0])
+ ob = onboarding.Onboarding()
+ with taddons.context(ob) as tctx:
+ tctx.configure(ob)
assert self.app("/").status_code == 200
@pytest.mark.parametrize("ext", ["pem", "p12"])
def test_cert(self, ext):
- with taddons.context() as tctx:
- tctx.configure(self.addons()[0])
+ ob = onboarding.Onboarding()
+ with taddons.context(ob) as tctx:
+ tctx.configure(ob)
resp = self.app("/cert/%s" % ext)
assert resp.status_code == 200
assert resp.content
@pytest.mark.parametrize("ext", ["pem", "p12"])
def test_head(self, ext):
- with taddons.context() as tctx:
- tctx.configure(self.addons()[0])
+ ob = onboarding.Onboarding()
+ with taddons.context(ob) as tctx:
+ tctx.configure(ob)
p = self.pathoc()
with p.connect():
- resp = p.request("head:'http://%s/cert/%s'" % (options.APP_HOST, ext))
+ resp = p.request("head:'http://%s/cert/%s'" % (tctx.options.onboarding_host, ext))
assert resp.status_code == 200
assert "Content-Length" in resp.headers
assert not resp.content
diff --git a/test/mitmproxy/addons/test_proxyauth.py b/test/mitmproxy/addons/test_proxyauth.py
index 97259d1c..7816dd18 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, loadcore=False) 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, loadcore=False) 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/addons/test_readfile.py b/test/mitmproxy/addons/test_readfile.py
index 813aa10e..0439862a 100644
--- a/test/mitmproxy/addons/test_readfile.py
+++ b/test/mitmproxy/addons/test_readfile.py
@@ -41,7 +41,7 @@ class TestReadFile:
@mock.patch('mitmproxy.master.Master.load_flow')
def test_configure(self, mck, tmpdir, data, corrupt_data):
rf = readfile.ReadFile()
- with taddons.context() as tctx:
+ with taddons.context(rf) as tctx:
tf = tmpdir.join("tfile")
tf.write(data.getvalue())
@@ -58,7 +58,7 @@ class TestReadFile:
@mock.patch('mitmproxy.master.Master.load_flow')
def test_corrupt(self, mck, corrupt_data):
rf = readfile.ReadFile()
- with taddons.context() as tctx:
+ with taddons.context(rf) as tctx:
with pytest.raises(exceptions.FlowReadException):
rf.load_flows(io.BytesIO(b"qibble"))
assert not mck.called
@@ -71,7 +71,7 @@ class TestReadFile:
def test_nonexisting_file(self):
rf = readfile.ReadFile()
- with taddons.context() as tctx:
+ with taddons.context(rf) as tctx:
with pytest.raises(exceptions.FlowReadException):
rf.load_flows_from_path("nonexistent")
assert len(tctx.master.logs) == 1
@@ -82,7 +82,7 @@ class TestReadFileStdin:
@mock.patch('sys.stdin')
def test_stdin(self, stdin, load_flow, data, corrupt_data):
rf = readfile.ReadFileStdin()
- with taddons.context() as tctx:
+ with taddons.context(rf) as tctx:
stdin.buffer = data
tctx.configure(rf, rfile="-")
assert not load_flow.called
@@ -97,7 +97,7 @@ class TestReadFileStdin:
@mock.patch('mitmproxy.master.Master.load_flow')
def test_normal(self, load_flow, tmpdir, data):
rf = readfile.ReadFileStdin()
- with taddons.context():
+ with taddons.context(rf):
tfile = tmpdir.join("tfile")
tfile.write(data.getvalue())
rf.load_flows_from_path(str(tfile))
diff --git a/test/mitmproxy/addons/test_replace.py b/test/mitmproxy/addons/test_replace.py
index 9002afb5..9c1f7f79 100644
--- a/test/mitmproxy/addons/test_replace.py
+++ b/test/mitmproxy/addons/test_replace.py
@@ -18,7 +18,7 @@ class TestReplace:
def test_configure(self):
r = replace.Replace()
- with taddons.context() as tctx:
+ with taddons.context(r) as tctx:
tctx.configure(r, replacements=["one/two/three"])
with pytest.raises(Exception, match="Invalid filter pattern"):
tctx.configure(r, replacements=["/~b/two/three"])
@@ -28,7 +28,7 @@ class TestReplace:
def test_simple(self):
r = replace.Replace()
- with taddons.context() as tctx:
+ with taddons.context(r) as tctx:
tctx.configure(
r,
replacements=[
@@ -48,7 +48,7 @@ class TestReplace:
def test_order(self):
r = replace.Replace()
- with taddons.context() as tctx:
+ with taddons.context(r) as tctx:
tctx.configure(
r,
replacements=[
@@ -67,7 +67,7 @@ class TestReplace:
class TestReplaceFile:
def test_simple(self, tmpdir):
r = replace.Replace()
- with taddons.context() as tctx:
+ with taddons.context(r) as tctx:
tmpfile = tmpdir.join("replacement")
tmpfile.write("bar")
tctx.configure(
@@ -81,7 +81,7 @@ class TestReplaceFile:
def test_nonexistent(self, tmpdir):
r = replace.Replace()
- with taddons.context() as tctx:
+ with taddons.context(r) as tctx:
with pytest.raises(Exception, match="Invalid file path"):
tctx.configure(
r,
diff --git a/test/mitmproxy/addons/test_save.py b/test/mitmproxy/addons/test_save.py
index 2dee708f..4486ff78 100644
--- a/test/mitmproxy/addons/test_save.py
+++ b/test/mitmproxy/addons/test_save.py
@@ -5,14 +5,13 @@ from mitmproxy.test import tflow
from mitmproxy import io
from mitmproxy import exceptions
-from mitmproxy import options
from mitmproxy.addons import save
from mitmproxy.addons import view
def test_configure(tmpdir):
sa = save.Save()
- with taddons.context(options=options.Options()) as tctx:
+ with taddons.context() as tctx:
with pytest.raises(exceptions.OptionsError):
tctx.configure(sa, save_stream_file=str(tmpdir))
with pytest.raises(Exception, match="Invalid filter"):
diff --git a/test/mitmproxy/addons/test_script.py b/test/mitmproxy/addons/test_script.py
index 78a5be6c..dc21e6fd 100644
--- a/test/mitmproxy/addons/test_script.py
+++ b/test/mitmproxy/addons/test_script.py
@@ -171,7 +171,7 @@ class TestScriptLoader:
"mitmproxy/data/addonscripts/recorder/recorder.py"
)
sc = script.ScriptLoader()
- with taddons.context() as tctx:
+ with taddons.context(sc) as tctx:
sc.script_run([tflow.tflow(resp=True)], rp)
debug = [i.msg for i in tctx.master.logs if i.level == "debug"]
assert debug == [
@@ -183,13 +183,13 @@ class TestScriptLoader:
def test_script_run_nonexistent(self):
sc = script.ScriptLoader()
- with taddons.context():
+ with taddons.context(sc):
with pytest.raises(exceptions.CommandError):
sc.script_run([tflow.tflow(resp=True)], "/")
def test_simple(self):
sc = script.ScriptLoader()
- with taddons.context() as tctx:
+ with taddons.context(loadcore=False) as tctx:
tctx.master.addons.add(sc)
sc.running()
assert len(tctx.master.addons) == 1
@@ -208,8 +208,7 @@ class TestScriptLoader:
def test_dupes(self):
sc = script.ScriptLoader()
- with taddons.context() as tctx:
- tctx.master.addons.add(sc)
+ with taddons.context(sc) as tctx:
with pytest.raises(exceptions.OptionsError):
tctx.configure(
sc,
@@ -232,7 +231,7 @@ class TestScriptLoader:
def test_load_err(self):
sc = script.ScriptLoader()
- with taddons.context() as tctx:
+ with taddons.context(sc, loadcore=False) as tctx:
tctx.configure(sc, scripts=[
tutils.test_data.path("mitmproxy/data/addonscripts/load_error.py")
])
@@ -242,7 +241,7 @@ class TestScriptLoader:
pass # this is expected and normally guarded.
# on the next tick we should not fail however.
tctx.invoke(sc, "tick")
- assert len(tctx.master.addons) == 0
+ assert len(tctx.master.addons) == 1
def test_order(self):
rec = tutils.test_data.path("mitmproxy/data/addonscripts/recorder")
diff --git a/test/mitmproxy/addons/test_serverplayback.py b/test/mitmproxy/addons/test_serverplayback.py
index 7605a5d9..0bc28ac8 100644
--- a/test/mitmproxy/addons/test_serverplayback.py
+++ b/test/mitmproxy/addons/test_serverplayback.py
@@ -19,7 +19,7 @@ def tdump(path, flows):
def test_load_file(tmpdir):
s = serverplayback.ServerPlayback()
- with taddons.context():
+ with taddons.context(s):
fpath = str(tmpdir.join("flows"))
tdump(fpath, [tflow.tflow(resp=True)])
s.load_file(fpath)
@@ -30,7 +30,7 @@ def test_load_file(tmpdir):
def test_config(tmpdir):
s = serverplayback.ServerPlayback()
- with taddons.context() as tctx:
+ with taddons.context(s) as tctx:
fpath = str(tmpdir.join("flows"))
tdump(fpath, [tflow.tflow(resp=True)])
tctx.configure(s, server_replay=[fpath])
@@ -41,7 +41,7 @@ def test_config(tmpdir):
def test_tick():
s = serverplayback.ServerPlayback()
- with taddons.context() as tctx:
+ with taddons.context(s) as tctx:
s.stop = True
s.final_flow = tflow.tflow()
s.final_flow.live = False
@@ -51,7 +51,7 @@ def test_tick():
def test_server_playback():
sp = serverplayback.ServerPlayback()
- with taddons.context() as tctx:
+ with taddons.context(sp) as tctx:
tctx.configure(sp)
f = tflow.tflow(resp=True)
@@ -70,7 +70,7 @@ def test_server_playback():
def test_ignore_host():
sp = serverplayback.ServerPlayback()
- with taddons.context() as tctx:
+ with taddons.context(sp) as tctx:
tctx.configure(sp, server_replay_ignore_host=True)
r = tflow.tflow(resp=True)
@@ -85,7 +85,7 @@ def test_ignore_host():
def test_ignore_content():
s = serverplayback.ServerPlayback()
- with taddons.context() as tctx:
+ with taddons.context(s) as tctx:
tctx.configure(s, server_replay_ignore_content=False)
r = tflow.tflow(resp=True)
@@ -113,7 +113,7 @@ def test_ignore_content():
def test_ignore_content_wins_over_params():
s = serverplayback.ServerPlayback()
- with taddons.context() as tctx:
+ with taddons.context(s) as tctx:
tctx.configure(
s,
server_replay_ignore_content=True,
@@ -137,7 +137,7 @@ def test_ignore_content_wins_over_params():
def test_ignore_payload_params_other_content_type():
s = serverplayback.ServerPlayback()
- with taddons.context() as tctx:
+ with taddons.context(s) as tctx:
tctx.configure(
s,
server_replay_ignore_content=False,
@@ -161,7 +161,7 @@ def test_ignore_payload_params_other_content_type():
def test_hash():
s = serverplayback.ServerPlayback()
- with taddons.context() as tctx:
+ with taddons.context(s) as tctx:
tctx.configure(s)
r = tflow.tflow()
@@ -181,7 +181,7 @@ def test_hash():
def test_headers():
s = serverplayback.ServerPlayback()
- with taddons.context() as tctx:
+ with taddons.context(s) as tctx:
tctx.configure(s, server_replay_use_headers=["foo"])
r = tflow.tflow(resp=True)
@@ -200,7 +200,7 @@ def test_headers():
def test_load():
s = serverplayback.ServerPlayback()
- with taddons.context() as tctx:
+ with taddons.context(s) as tctx:
tctx.configure(s)
r = tflow.tflow(resp=True)
@@ -227,7 +227,7 @@ def test_load():
def test_load_with_server_replay_nopop():
s = serverplayback.ServerPlayback()
- with taddons.context() as tctx:
+ with taddons.context(s) as tctx:
tctx.configure(s, server_replay_nopop=True)
r = tflow.tflow(resp=True)
@@ -245,7 +245,7 @@ def test_load_with_server_replay_nopop():
def test_ignore_params():
s = serverplayback.ServerPlayback()
- with taddons.context() as tctx:
+ with taddons.context(s) as tctx:
tctx.configure(
s,
server_replay_ignore_params=["param1", "param2"]
@@ -266,7 +266,7 @@ def test_ignore_params():
def thash(r, r2, setter):
s = serverplayback.ServerPlayback()
- with taddons.context() as tctx:
+ with taddons.context(s) as tctx:
s = serverplayback.ServerPlayback()
tctx.configure(
s,
@@ -328,10 +328,10 @@ def test_ignore_payload_params():
def test_server_playback_full():
s = serverplayback.ServerPlayback()
- with taddons.context() as tctx:
+ with taddons.context(s) as tctx:
tctx.configure(
s,
- refresh_server_playback = True,
+ server_replay_refresh = True,
)
f = tflow.tflow()
@@ -360,11 +360,11 @@ def test_server_playback_full():
def test_server_playback_kill():
s = serverplayback.ServerPlayback()
- with taddons.context() as tctx:
+ with taddons.context(s) as tctx:
tctx.configure(
s,
- refresh_server_playback = True,
- replay_kill_extra=True
+ server_replay_refresh = True,
+ server_replay_kill_extra=True
)
f = tflow.tflow()
diff --git a/test/mitmproxy/addons/test_setheaders.py b/test/mitmproxy/addons/test_setheaders.py
index 3aaee7f4..2d5e9e3c 100644
--- a/test/mitmproxy/addons/test_setheaders.py
+++ b/test/mitmproxy/addons/test_setheaders.py
@@ -19,14 +19,14 @@ class TestSetHeaders:
def test_configure(self):
sh = setheaders.SetHeaders()
- with taddons.context() as tctx:
+ with taddons.context(sh) as tctx:
with pytest.raises(Exception, match="Invalid setheader filter pattern"):
tctx.configure(sh, setheaders = ["/~b/one/two"])
tctx.configure(sh, setheaders = ["/foo/bar/voing"])
def test_setheaders(self):
sh = setheaders.SetHeaders()
- with taddons.context() as tctx:
+ with taddons.context(sh) as tctx:
tctx.configure(
sh,
setheaders = [
diff --git a/test/mitmproxy/addons/test_stickyauth.py b/test/mitmproxy/addons/test_stickyauth.py
index ef7d0793..7b422fdd 100644
--- a/test/mitmproxy/addons/test_stickyauth.py
+++ b/test/mitmproxy/addons/test_stickyauth.py
@@ -9,7 +9,7 @@ from mitmproxy import exceptions
def test_configure():
r = stickyauth.StickyAuth()
- with taddons.context() as tctx:
+ with taddons.context(r) as tctx:
tctx.configure(r, stickyauth="~s")
with pytest.raises(exceptions.OptionsError):
tctx.configure(r, stickyauth="~~")
@@ -20,7 +20,7 @@ def test_configure():
def test_simple():
r = stickyauth.StickyAuth()
- with taddons.context() as tctx:
+ with taddons.context(r) as tctx:
tctx.configure(r, stickyauth=".*")
f = tflow.tflow(resp=True)
f.request.headers["authorization"] = "foo"
diff --git a/test/mitmproxy/addons/test_stickycookie.py b/test/mitmproxy/addons/test_stickycookie.py
index f77d019d..4493e9cc 100644
--- a/test/mitmproxy/addons/test_stickycookie.py
+++ b/test/mitmproxy/addons/test_stickycookie.py
@@ -15,7 +15,7 @@ def test_domain_match():
class TestStickyCookie:
def test_config(self):
sc = stickycookie.StickyCookie()
- with taddons.context() as tctx:
+ with taddons.context(sc) as tctx:
with pytest.raises(Exception, match="invalid filter"):
tctx.configure(sc, stickycookie="~b")
@@ -26,7 +26,7 @@ class TestStickyCookie:
def test_simple(self):
sc = stickycookie.StickyCookie()
- with taddons.context() as tctx:
+ with taddons.context(sc) as tctx:
tctx.configure(sc, stickycookie=".*")
f = tflow.tflow(resp=True)
f.response.headers["set-cookie"] = "foo=bar"
@@ -50,7 +50,7 @@ class TestStickyCookie:
def test_response(self):
sc = stickycookie.StickyCookie()
- with taddons.context() as tctx:
+ with taddons.context(sc) as tctx:
tctx.configure(sc, stickycookie=".*")
c = "SSID=mooo; domain=.google.com, FOO=bar; Domain=.google.com; Path=/; " \
@@ -68,7 +68,7 @@ class TestStickyCookie:
def test_response_multiple(self):
sc = stickycookie.StickyCookie()
- with taddons.context() as tctx:
+ with taddons.context(sc) as tctx:
tctx.configure(sc, stickycookie=".*")
# Test setting of multiple cookies
@@ -82,7 +82,7 @@ class TestStickyCookie:
def test_response_weird(self):
sc = stickycookie.StickyCookie()
- with taddons.context() as tctx:
+ with taddons.context(sc) as tctx:
tctx.configure(sc, stickycookie=".*")
# Test setting of weird cookie keys
@@ -100,7 +100,7 @@ class TestStickyCookie:
def test_response_overwrite(self):
sc = stickycookie.StickyCookie()
- with taddons.context() as tctx:
+ with taddons.context(sc) as tctx:
tctx.configure(sc, stickycookie=".*")
# Test overwriting of a cookie value
@@ -115,7 +115,7 @@ class TestStickyCookie:
def test_response_delete(self):
sc = stickycookie.StickyCookie()
- with taddons.context() as tctx:
+ with taddons.context(sc) as tctx:
tctx.configure(sc, stickycookie=".*")
# Test that a cookie is be deleted
@@ -127,7 +127,7 @@ class TestStickyCookie:
def test_request(self):
sc = stickycookie.StickyCookie()
- with taddons.context() as tctx:
+ with taddons.context(sc) as tctx:
tctx.configure(sc, stickycookie=".*")
f = self._response(sc, "SSID=mooo", "www.google.com")
diff --git a/test/mitmproxy/addons/test_streambodies.py b/test/mitmproxy/addons/test_streambodies.py
index 426ec9ae..b980ea0b 100644
--- a/test/mitmproxy/addons/test_streambodies.py
+++ b/test/mitmproxy/addons/test_streambodies.py
@@ -7,7 +7,7 @@ import pytest
def test_simple():
sa = streambodies.StreamBodies()
- with taddons.context() as tctx:
+ with taddons.context(sa) as tctx:
with pytest.raises(exceptions.OptionsError):
tctx.configure(sa, stream_large_bodies = "invalid")
tctx.configure(sa, stream_large_bodies = "10")
diff --git a/test/mitmproxy/addons/test_termlog.py b/test/mitmproxy/addons/test_termlog.py
index 027bdfeb..6c95df0c 100644
--- a/test/mitmproxy/addons/test_termlog.py
+++ b/test/mitmproxy/addons/test_termlog.py
@@ -3,7 +3,6 @@ import pytest
from mitmproxy.addons import termlog
from mitmproxy import log
-from mitmproxy.options import Options
from mitmproxy.test import taddons
@@ -16,7 +15,8 @@ class TestTermLog:
])
def test_output(self, outfile, expected_out, expected_err, capfd):
t = termlog.TermLog(outfile=outfile)
- with taddons.context(options=Options(verbosity='info')) as tctx:
+ with taddons.context(t) as tctx:
+ tctx.options.termlog_verbosity = "info"
tctx.configure(t)
t.log(log.LogEntry("one", "info"))
t.log(log.LogEntry("two", "debug"))
diff --git a/test/mitmproxy/addons/test_upstream_auth.py b/test/mitmproxy/addons/test_upstream_auth.py
index c7342bb5..ae037693 100644
--- a/test/mitmproxy/addons/test_upstream_auth.py
+++ b/test/mitmproxy/addons/test_upstream_auth.py
@@ -9,7 +9,7 @@ from mitmproxy.addons import upstream_auth
def test_configure():
up = upstream_auth.UpstreamAuth()
- with taddons.context() as tctx:
+ with taddons.context(up) as tctx:
tctx.configure(up, upstream_auth="test:test")
assert up.auth == b"Basic" + b" " + base64.b64encode(b"test:test")
@@ -29,7 +29,7 @@ def test_configure():
def test_simple():
up = upstream_auth.UpstreamAuth()
- with taddons.context() as tctx:
+ with taddons.context(up) as tctx:
tctx.configure(up, upstream_auth="foo:bar")
f = tflow.tflow()
@@ -41,7 +41,7 @@ def test_simple():
up.requestheaders(f)
assert "proxy-authorization" not in f.request.headers
- tctx.configure(up, mode="reverse")
+ tctx.configure(up, mode="reverse:127.0.0.1")
f = tflow.tflow()
f.mode = "transparent"
up.requestheaders(f)
diff --git a/test/mitmproxy/contentviews/test_api.py b/test/mitmproxy/contentviews/test_api.py
index c072c86f..3fc06d7c 100644
--- a/test/mitmproxy/contentviews/test_api.py
+++ b/test/mitmproxy/contentviews/test_api.py
@@ -9,7 +9,6 @@ from mitmproxy.test import tutils
class TestContentView(contentviews.View):
name = "test"
- prompt = ("test", "t")
content_types = ["test/123"]
@@ -22,13 +21,6 @@ def test_add_remove():
with pytest.raises(ContentViewException, match="Duplicate view"):
contentviews.add(tcv)
- tcv2 = TestContentView()
- tcv2.name = "test2"
- tcv2.prompt = ("test2", "t")
- # Same shortcut doesn't work either.
- with pytest.raises(ContentViewException, match="Duplicate view shortcut"):
- contentviews.add(tcv2)
-
contentviews.remove(tcv)
assert tcv not in contentviews.views
@@ -86,8 +78,3 @@ def test_get_message_content_view():
r.content = None
desc, lines, err = contentviews.get_message_content_view("raw", r)
assert list(lines) == [[("error", "content missing")]]
-
-
-def test_get_by_shortcut():
- assert contentviews.get_by_shortcut("s")
- assert not contentviews.get_by_shortcut("b")
diff --git a/test/mitmproxy/net/http/test_cookies.py b/test/mitmproxy/net/http/test_cookies.py
index e12b0f00..74233cca 100644
--- a/test/mitmproxy/net/http/test_cookies.py
+++ b/test/mitmproxy/net/http/test_cookies.py
@@ -143,6 +143,27 @@ def test_cookie_roundtrips():
def test_parse_set_cookie_pairs():
pairs = [
[
+ "=",
+ [[
+ ["", ""]
+ ]]
+ ],
+ [
+ "=;foo=bar",
+ [[
+ ["", ""],
+ ["foo", "bar"]
+ ]]
+ ],
+ [
+ "=;=;foo=bar",
+ [[
+ ["", ""],
+ ["", ""],
+ ["foo", "bar"]
+ ]]
+ ],
+ [
"=uno",
[[
["", "uno"]
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/proxy/protocol/test_http2.py b/test/mitmproxy/proxy/protocol/test_http2.py
index 194a57c9..d9aa03b4 100644
--- a/test/mitmproxy/proxy/protocol/test_http2.py
+++ b/test/mitmproxy/proxy/protocol/test_http2.py
@@ -10,6 +10,7 @@ import h2
from mitmproxy import options
import mitmproxy.net
+from mitmproxy.addons import core
from ...net import tservers as net_tservers
from mitmproxy import exceptions
from mitmproxy.net.http import http1, http2
@@ -90,6 +91,7 @@ class _Http2TestBase:
def setup_class(cls):
cls.options = cls.get_options()
tmaster = tservers.TestMaster(cls.options)
+ tmaster.addons.add(core.Core())
cls.proxy = tservers.ProxyThread(tmaster)
cls.proxy.start()
diff --git a/test/mitmproxy/proxy/protocol/test_websocket.py b/test/mitmproxy/proxy/protocol/test_websocket.py
index 5cd9601c..661605b7 100644
--- a/test/mitmproxy/proxy/protocol/test_websocket.py
+++ b/test/mitmproxy/proxy/protocol/test_websocket.py
@@ -6,6 +6,7 @@ import traceback
from mitmproxy import options
from mitmproxy import exceptions
+from mitmproxy.addons import core
from mitmproxy.http import HTTPFlow
from mitmproxy.websocket import WebSocketFlow
@@ -52,6 +53,7 @@ class _WebSocketTestBase:
def setup_class(cls):
cls.options = cls.get_options()
tmaster = tservers.TestMaster(cls.options)
+ tmaster.addons.add(core.Core())
cls.proxy = tservers.ProxyThread(tmaster)
cls.proxy.start()
diff --git a/test/mitmproxy/proxy/test_config.py b/test/mitmproxy/proxy/test_config.py
index a7da980b..60a0deb5 100644
--- a/test/mitmproxy/proxy/test_config.py
+++ b/test/mitmproxy/proxy/test_config.py
@@ -7,30 +7,12 @@ from mitmproxy.test import tutils
class TestProxyConfig:
- def test_upstream_cert_insecure(self):
- opts = options.Options()
- opts.add_upstream_certs_to_client_chain = True
- with pytest.raises(exceptions.OptionsError, match="verify-upstream-cert"):
- ProxyConfig(opts)
-
def test_invalid_cadir(self):
opts = options.Options()
opts.cadir = "foo"
with pytest.raises(exceptions.OptionsError, match="parent directory does not exist"):
ProxyConfig(opts)
- def test_invalid_client_certs(self):
- opts = options.Options()
- opts.client_certs = "foo"
- with pytest.raises(exceptions.OptionsError, match="certificate path does not exist"):
- ProxyConfig(opts)
-
- def test_valid_client_certs(self):
- opts = options.Options()
- opts.client_certs = tutils.test_data.path("mitmproxy/data/clientcert/")
- p = ProxyConfig(opts)
- assert p.client_certs
-
def test_invalid_certificate(self):
opts = options.Options()
opts.certs = [tutils.test_data.path("mitmproxy/data/dumpfile-011")]
diff --git a/test/mitmproxy/proxy/test_server.py b/test/mitmproxy/proxy/test_server.py
index 87ec443a..986dfb39 100644
--- a/test/mitmproxy/proxy/test_server.py
+++ b/test/mitmproxy/proxy/test_server.py
@@ -10,7 +10,6 @@ from mitmproxy import certs
from mitmproxy import exceptions
from mitmproxy import http
from mitmproxy import options
-from mitmproxy.addons import proxyauth
from mitmproxy.addons import script
from mitmproxy.net import socks
from mitmproxy.net import tcp
@@ -306,46 +305,6 @@ class TestHTTP(tservers.HTTPProxyTest, CommonMixin):
assert self.server.last_log()["request"]["first_line_format"] == "relative"
-class TestHTTPAuth(tservers.HTTPProxyTest):
- def test_auth(self):
- self.master.addons.add(proxyauth.ProxyAuth())
- self.master.addons.trigger(
- "configure", self.master.options.keys()
- )
- self.master.options.proxyauth = "test:test"
- assert self.pathod("202").status_code == 407
- p = self.pathoc()
- with p.connect():
- ret = p.request("""
- get
- 'http://localhost:%s/p/202'
- h'%s'='%s'
- """ % (
- self.server.port,
- "Proxy-Authorization",
- proxyauth.mkauth("test", "test")
- ))
- assert ret.status_code == 202
-
-
-class TestHTTPReverseAuth(tservers.ReverseProxyTest):
- def test_auth(self):
- self.master.addons.add(proxyauth.ProxyAuth())
- self.master.options.proxyauth = "test:test"
- assert self.pathod("202").status_code == 401
- p = self.pathoc()
- with p.connect():
- ret = p.request("""
- get
- '/p/202'
- h'%s'='%s'
- """ % (
- "Authorization",
- proxyauth.mkauth("test", "test")
- ))
- assert ret.status_code == 202
-
-
class TestHTTPS(tservers.HTTPProxyTest, CommonMixin, TcpMixin):
ssl = True
ssloptions = pathod.SSLOptions(request_client_cert=True)
diff --git a/test/mitmproxy/test_addonmanager.py b/test/mitmproxy/test_addonmanager.py
index 274d2d90..ad56cb22 100644
--- a/test/mitmproxy/test_addonmanager.py
+++ b/test/mitmproxy/test_addonmanager.py
@@ -107,7 +107,7 @@ def test_loader():
def test_simple():
- with taddons.context() as tctx:
+ with taddons.context(loadcore=False) as tctx:
a = tctx.master.addons
assert len(a) == 0
diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py
index c777192d..e2b80753 100644
--- a/test/mitmproxy/test_command.py
+++ b/test/mitmproxy/test_command.py
@@ -211,6 +211,22 @@ class TestCommand:
],
[]
],
+ [
+ "flow \"one two",
+ [
+ command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True),
+ command.ParseResult(value = "\"one two", type = flow.Flow, valid = False),
+ ],
+ ["str"]
+ ],
+ [
+ "flow \"one two\"",
+ [
+ command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True),
+ command.ParseResult(value = "one two", type = flow.Flow, valid = False),
+ ],
+ ["str"]
+ ],
]
with taddons.context() as tctx:
tctx.master.addons.add(TAddon())
diff --git a/test/mitmproxy/test_optmanager.py b/test/mitmproxy/test_optmanager.py
index d9b93227..1c49c0b8 100644
--- a/test/mitmproxy/test_optmanager.py
+++ b/test/mitmproxy/test_optmanager.py
@@ -351,7 +351,7 @@ def test_dump_defaults():
def test_dump_dicts():
o = options.Options()
assert optmanager.dump_dicts(o)
- assert optmanager.dump_dicts(o, ['http2', 'anticomp'])
+ assert optmanager.dump_dicts(o, ['http2', 'listen_port'])
class TTypes(optmanager.OptManager):
@@ -375,9 +375,13 @@ def test_make_parser():
opts.make_parser(parser, "int", short="c")
opts.make_parser(parser, "seqstr", short="d")
opts.make_parser(parser, "bool_on", short="e")
+
with pytest.raises(ValueError):
opts.make_parser(parser, "unknown")
+ # Nonexistent options ignore
+ opts.make_parser(parser, "nonexistentxxx")
+
def test_set():
opts = TTypes()
diff --git a/test/mitmproxy/test_proxy.py b/test/mitmproxy/test_proxy.py
index 299abab3..75d4cdf0 100644
--- a/test/mitmproxy/test_proxy.py
+++ b/test/mitmproxy/test_proxy.py
@@ -1,6 +1,5 @@
import argparse
from unittest import mock
-from OpenSSL import SSL
import pytest
from mitmproxy.tools import cmdline
@@ -50,10 +49,6 @@ class TestProcessProxyOptions:
with pytest.raises(Exception, match="does not exist"):
self.p("--cert", "nonexistent")
- def test_insecure(self):
- p = self.assert_noerr("--ssl-insecure")
- assert p.openssl_verification_mode_server == SSL.VERIFY_NONE
-
class TestProxyServer:
diff --git a/test/mitmproxy/tools/console/test_master.py b/test/mitmproxy/tools/console/test_master.py
index 9779a482..2879170d 100644
--- a/test/mitmproxy/tools/console/test_master.py
+++ b/test/mitmproxy/tools/console/test_master.py
@@ -1,20 +1,12 @@
import urwid
from mitmproxy import options
-from mitmproxy.test import tflow
-from mitmproxy.test import tutils
from mitmproxy.tools import console
from ... import tservers
-def test_options():
- assert options.Options(replay_kill_extra=True)
-
-
class TestMaster(tservers.MasterTest):
def mkmaster(self, **opts):
- if "verbosity" not in opts:
- opts["verbosity"] = 'warn'
o = options.Options(**opts)
m = console.master.ConsoleMaster(o)
m.addons.trigger("configure", o.keys())
@@ -28,16 +20,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 b131a5d3..db8a63a7 100644
--- a/test/mitmproxy/tools/console/test_statusbar.py
+++ b/test/mitmproxy/tools/console/test_statusbar.py
@@ -3,7 +3,9 @@ from mitmproxy.tools.console import statusbar, master
def test_statusbar(monkeypatch):
- o = options.Options(
+ o = options.Options()
+ m = master.ConsoleMaster(o)
+ m.options.update(
setheaders=[":~q:foo:bar"],
replacements=[":~q:foo:bar"],
ignore_hosts=["example.com", "example.org"],
@@ -12,19 +14,17 @@ 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,
- refresh_server_playback=False,
- replay_kill_extra=True,
+ server_replay_refresh=False,
+ server_replay_kill_extra=True,
upstream_cert=False,
stream_large_bodies="3m",
mode="transparent",
- scripts=["nonexistent"],
- save_stream_file="foo",
)
- m = master.ConsoleMaster(o)
+
m.options.update(view_order='url', console_focus_follow=True)
monkeypatch.setattr(m.addons.get("clientplayback"), "count", lambda: 42)
monkeypatch.setattr(m.addons.get("serverplayback"), "count", lambda: 42)
diff --git a/test/mitmproxy/tools/test_dump.py b/test/mitmproxy/tools/test_dump.py
index 952c3f4f..f950d719 100644
--- a/test/mitmproxy/tools/test_dump.py
+++ b/test/mitmproxy/tools/test_dump.py
@@ -10,13 +10,13 @@ from .. import tservers
class TestDumpMaster(tservers.MasterTest):
- def mkmaster(self, flt, **opts):
- o = options.Options(view_filter=flt, verbosity='error', flow_detail=0, **opts)
+ def mkmaster(self, **opts):
+ o = options.Options(**opts)
m = dump.DumpMaster(o, with_termlog=False, with_dumper=False)
return m
def test_has_error(self):
- m = self.mkmaster(None)
+ m = self.mkmaster()
ent = log.LogEntry("foo", "error")
ent.reply = controller.DummyReply()
m.addons.trigger("log", ent)
diff --git a/test/mitmproxy/tools/web/test_static_viewer.py b/test/mitmproxy/tools/web/test_static_viewer.py
index cfe6cd7f..dfc45bc2 100644
--- a/test/mitmproxy/tools/web/test_static_viewer.py
+++ b/test/mitmproxy/tools/web/test_static_viewer.py
@@ -8,7 +8,7 @@ from mitmproxy import flowfilter
from mitmproxy.tools.web.app import flow_to_json
from mitmproxy.tools.web import static_viewer
-from mitmproxy.addons import save
+from mitmproxy.addons import save, readfile
def test_save_static(tmpdir):
@@ -59,8 +59,9 @@ def test_save_flows_content(ctx, tmpdir):
def test_static_viewer(tmpdir):
s = static_viewer.StaticViewer()
+ rf = readfile.ReadFile()
sa = save.Save()
- with taddons.context() as tctx:
+ with taddons.context(rf) as tctx:
sa.save([tflow.tflow(resp=True)], str(tmpdir.join('foo')))
tctx.master.addons.add(s)
tctx.configure(s, web_static_viewer=str(tmpdir), rfile=str(tmpdir.join('foo')))
diff --git a/test/mitmproxy/tservers.py b/test/mitmproxy/tservers.py
index dd5bb327..0040b023 100644
--- a/test/mitmproxy/tservers.py
+++ b/test/mitmproxy/tservers.py
@@ -5,6 +5,7 @@ import sys
from unittest import mock
import mitmproxy.platform
+from mitmproxy.addons import core
from mitmproxy.proxy.config import ProxyConfig
from mitmproxy.proxy.server import ProxyServer
from mitmproxy import controller
@@ -132,6 +133,7 @@ class ProxyTestBase:
cls.options = cls.get_options()
tmaster = cls.masterclass(cls.options)
+ tmaster.addons.add(core.Core())
cls.proxy = ProxyThread(tmaster)
cls.proxy.start()
@@ -222,12 +224,12 @@ class HTTPProxyTest(ProxyTestBase):
p = pathod.pathoc.Pathoc(
("127.0.0.1", self.proxy.port), True, fp=None
)
- with p.connect((options.APP_HOST, options.APP_PORT)):
+ with p.connect((self.master.options.onboarding_host, self.master.options.onbarding_port)):
return p.request("get:'%s'" % page)
else:
p = self.pathoc()
with p.connect():
- return p.request("get:'http://%s%s'" % (options.APP_HOST, page))
+ return p.request("get:'http://%s%s'" % (self.master.options.onboarding_host, page))
class TransparentProxyTest(ProxyTestBase):
@@ -343,6 +345,7 @@ class ChainProxyTest(ProxyTestBase):
for _ in range(cls.n):
opts = cls.get_options()
tmaster = cls.masterclass(opts)
+ tmaster.addons.add(core.Core())
proxy = ProxyThread(tmaster)
proxy.start()
cls.chain.insert(0, proxy)