aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-09-08 23:34:43 +0200
committerMaximilian Hils <git@maximilianhils.com>2014-09-08 23:34:43 +0200
commitfbc4bb38df48447f846ae0ff4f87062c827bd632 (patch)
tree3955afbe79f9e9e6497565c1e2a34d9c66234ed9 /test
parent7ea8d3ff357e278ba047a18a0dcc4bd434017c79 (diff)
downloadmitmproxy-fbc4bb38df48447f846ae0ff4f87062c827bd632.tar.gz
mitmproxy-fbc4bb38df48447f846ae0ff4f87062c827bd632.tar.bz2
mitmproxy-fbc4bb38df48447f846ae0ff4f87062c827bd632.zip
mitmproxy -> libmproxy.main. do some leanup on the way
Diffstat (limited to 'test')
-rw-r--r--test/test_dump.py20
-rw-r--r--test/test_proxy.py20
-rw-r--r--test/tservers.py3
3 files changed, 22 insertions, 21 deletions
diff --git a/test/test_dump.py b/test/test_dump.py
index fd93cc03..2e58e073 100644
--- a/test/test_dump.py
+++ b/test/test_dump.py
@@ -35,8 +35,8 @@ class TestDumpMaster:
def _dummy_cycle(self, n, filt, content, **options):
cs = StringIO()
- o = dump.Options(**options)
- m = dump.DumpMaster(None, o, filt, outfile=cs)
+ o = dump.Options(filtstr=filt, **options)
+ m = dump.DumpMaster(None, o, outfile=cs)
for i in range(n):
self._cycle(m, content)
m.shutdown()
@@ -52,7 +52,7 @@ class TestDumpMaster:
def test_error(self):
cs = StringIO()
o = dump.Options(flow_detail=1)
- m = dump.DumpMaster(None, o, None, outfile=cs)
+ m = dump.DumpMaster(None, o, outfile=cs)
f = tutils.tflow(err=True)
m.handle_request(f)
assert m.handle_error(f)
@@ -62,24 +62,24 @@ class TestDumpMaster:
cs = StringIO()
o = dump.Options(server_replay="nonexistent", kill=True)
- tutils.raises(dump.DumpError, dump.DumpMaster, None, o, None, outfile=cs)
+ tutils.raises(dump.DumpError, dump.DumpMaster, None, o, outfile=cs)
with tutils.tmpdir() as t:
p = os.path.join(t, "rep")
self._flowfile(p)
o = dump.Options(server_replay=p, kill=True)
- m = dump.DumpMaster(None, o, None, outfile=cs)
+ m = dump.DumpMaster(None, o, outfile=cs)
self._cycle(m, "content")
self._cycle(m, "content")
o = dump.Options(server_replay=p, kill=False)
- m = dump.DumpMaster(None, o, None, outfile=cs)
+ m = dump.DumpMaster(None, o, outfile=cs)
self._cycle(m, "nonexistent")
o = dump.Options(client_replay=p, kill=False)
- m = dump.DumpMaster(None, o, None, outfile=cs)
+ m = dump.DumpMaster(None, o, outfile=cs)
def test_read(self):
with tutils.tmpdir() as t:
@@ -105,18 +105,18 @@ class TestDumpMaster:
def test_app(self):
o = dump.Options(app=True)
s = mock.MagicMock()
- m = dump.DumpMaster(s, o, None)
+ m = dump.DumpMaster(s, o)
assert len(m.apps.apps) == 1
def test_replacements(self):
o = dump.Options(replacements=[(".*", "content", "foo")])
- m = dump.DumpMaster(None, o, None)
+ m = dump.DumpMaster(None, o)
f = self._cycle(m, "content")
assert f.request.content == "foo"
def test_setheader(self):
o = dump.Options(setheaders=[(".*", "one", "two")])
- m = dump.DumpMaster(None, o, None)
+ m = dump.DumpMaster(None, o)
f = self._cycle(m, "content")
assert f.request.headers["one"] == ["two"]
diff --git a/test/test_proxy.py b/test/test_proxy.py
index 5f1b83f6..c396183b 100644
--- a/test/test_proxy.py
+++ b/test/test_proxy.py
@@ -1,6 +1,6 @@
import argparse
from libmproxy import cmdline
-from libmproxy.proxy.config import process_proxy_options
+from libmproxy.proxy import ProxyConfig, process_proxy_options
from libmproxy.proxy.connection import ServerConnection
from libmproxy.proxy.primitives import ProxyError
from libmproxy.proxy.server import DummyServer, ProxyServer, ConnectionHandler
@@ -119,16 +119,16 @@ class TestProcessProxyOptions:
class TestProxyServer:
@tutils.SkipWindows # binding to 0.0.0.0:1 works without special permissions on Windows
def test_err(self):
- parser = argparse.ArgumentParser()
- cmdline.common_options(parser)
- opts = parser.parse_args(args=[])
- tutils.raises("error starting proxy server", ProxyServer, opts, 1)
+ conf = ProxyConfig(
+ port=1
+ )
+ tutils.raises("error starting proxy server", ProxyServer, conf)
def test_err_2(self):
- parser = argparse.ArgumentParser()
- cmdline.common_options(parser)
- opts = parser.parse_args(args=[])
- tutils.raises("error starting proxy server", ProxyServer, opts, 8080, "invalidhost")
+ conf = ProxyConfig(
+ host="invalidhost"
+ )
+ tutils.raises("error starting proxy server", ProxyServer, conf)
class TestDummyServer:
@@ -142,6 +142,6 @@ class TestConnectionHandler:
def test_fatal_error(self):
config = mock.Mock()
config.mode.get_upstream_server.side_effect = RuntimeError
- c = ConnectionHandler(config, mock.MagicMock(), ("127.0.0.1", 8080), None, mock.MagicMock(), None)
+ c = ConnectionHandler(config, mock.MagicMock(), ("127.0.0.1", 8080), None, mock.MagicMock())
with tutils.capture_stderr(c.handle) as output:
assert "mitmproxy has crashed" in output
diff --git a/test/tservers.py b/test/tservers.py
index 009a3c92..2097631e 100644
--- a/test/tservers.py
+++ b/test/tservers.py
@@ -29,7 +29,8 @@ def errapp(environ, start_response):
class TestMaster(flow.FlowMaster):
def __init__(self, config):
- s = ProxyServer(config, 0)
+ config.port = 0
+ s = ProxyServer(config)
state = flow.State()
flow.FlowMaster.__init__(self, s, state)
self.apps.add(testapp, "testapp", 80)