aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/addons/test_core.py18
-rw-r--r--test/mitmproxy/proxy/test_server.py4
-rw-r--r--test/mitmproxy/test_flow.py3
-rw-r--r--test/mitmproxy/test_proxy.py37
-rw-r--r--test/mitmproxy/tservers.py8
5 files changed, 30 insertions, 40 deletions
diff --git a/test/mitmproxy/addons/test_core.py b/test/mitmproxy/addons/test_core.py
index 95272716..533eb58e 100644
--- a/test/mitmproxy/addons/test_core.py
+++ b/test/mitmproxy/addons/test_core.py
@@ -2,6 +2,7 @@ from mitmproxy import exceptions
from mitmproxy.addons import core
from mitmproxy.test import taddons
import pytest
+from unittest import mock
def test_simple():
@@ -11,3 +12,20 @@ def test_simple():
tctx.configure(sa, body_size_limit = "invalid")
tctx.configure(sa, body_size_limit = "1m")
assert tctx.options._processed["body_size_limit"]
+
+
+@mock.patch("mitmproxy.platform.original_addr", None)
+def test_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_modes(m):
+ sa = core.Core()
+ with taddons.context() as tctx:
+ tctx.configure(sa, mode = "reverse:http://localhost")
+ with pytest.raises(Exception, match="Invalid mode"):
+ tctx.configure(sa, mode = "reverse:")
diff --git a/test/mitmproxy/proxy/test_server.py b/test/mitmproxy/proxy/test_server.py
index bcfecf6f..b90840ab 100644
--- a/test/mitmproxy/proxy/test_server.py
+++ b/test/mitmproxy/proxy/test_server.py
@@ -10,7 +10,7 @@ from mitmproxy import options
from mitmproxy.addons import script
from mitmproxy.addons import proxyauth
from mitmproxy import http
-from mitmproxy.proxy.config import HostMatcher, parse_server_spec
+from mitmproxy.proxy.config import HostMatcher
import mitmproxy.net.http
from mitmproxy.net import tcp
from mitmproxy.net import socks
@@ -579,8 +579,6 @@ class TestHttps2Http(tservers.ReverseProxyTest):
@classmethod
def get_options(cls):
opts = super().get_options()
- s = parse_server_spec(opts.upstream_server)
- opts.upstream_server = "http://{}:{}".format(s.address[0], s.address[1])
return opts
def pathoc(self, ssl, sni=None):
diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py
index 0ac3bfd6..f4d32cbb 100644
--- a/test/mitmproxy/test_flow.py
+++ b/test/mitmproxy/test_flow.py
@@ -63,8 +63,7 @@ class TestSerialize:
r = self._treader()
s = tservers.TestState()
opts = options.Options(
- mode="reverse",
- upstream_server="https://use-this-domain"
+ mode="reverse:https://use-this-domain"
)
conf = ProxyConfig(opts)
fm = master.Master(opts, DummyServer(conf))
diff --git a/test/mitmproxy/test_proxy.py b/test/mitmproxy/test_proxy.py
index 5dd4a9e3..784a7d84 100644
--- a/test/mitmproxy/test_proxy.py
+++ b/test/mitmproxy/test_proxy.py
@@ -49,31 +49,6 @@ class TestProcessProxyOptions:
with tutils.tmpdir() as cadir:
self.assert_noerr("--cadir", cadir)
- @mock.patch("mitmproxy.platform.original_addr", None)
- def test_no_transparent(self):
- with pytest.raises(Exception, match="Transparent mode not supported"):
- self.p("-T")
-
- @mock.patch("mitmproxy.platform.original_addr")
- def test_modes(self, _):
- self.assert_noerr("-R", "http://localhost")
- with pytest.raises(Exception, match="expected one argument"):
- self.p("-R")
- with pytest.raises(Exception, match="Invalid server specification"):
- self.p("-R", "reverse")
-
- self.assert_noerr("-T")
-
- self.assert_noerr("-U", "http://localhost")
- with pytest.raises(Exception, match="Invalid server specification"):
- self.p("-U", "upstream")
-
- self.assert_noerr("--upstream-auth", "test:test")
- with pytest.raises(Exception, match="expected one argument"):
- self.p("--upstream-auth")
- with pytest.raises(Exception, match="mutually exclusive"):
- self.p("-R", "http://localhost", "-T")
-
def test_client_certs(self):
with tutils.tmpdir() as cadir:
self.assert_noerr("--client-certs", cadir)
@@ -131,19 +106,19 @@ class TestDummyServer:
class TestConnectionHandler:
def test_fatal_error(self, capsys):
- config = mock.Mock()
- root_layer = mock.Mock()
- root_layer.side_effect = RuntimeError
- config.options.mode.return_value = root_layer
+ opts = options.Options()
+ pconf = config.ProxyConfig(opts)
+
channel = mock.Mock()
def ask(_, x):
- return x
+ raise RuntimeError
+
channel.ask = ask
c = ConnectionHandler(
mock.MagicMock(),
("127.0.0.1", 8080),
- config,
+ pconf,
channel
)
c.handle()
diff --git a/test/mitmproxy/tservers.py b/test/mitmproxy/tservers.py
index 9a289ae5..a8aaa358 100644
--- a/test/mitmproxy/tservers.py
+++ b/test/mitmproxy/tservers.py
@@ -288,7 +288,7 @@ class ReverseProxyTest(ProxyTestBase):
@classmethod
def get_options(cls):
opts = ProxyTestBase.get_options()
- opts.upstream_server = "".join(
+ s = "".join(
[
"https" if cls.ssl else "http",
"://",
@@ -296,7 +296,7 @@ class ReverseProxyTest(ProxyTestBase):
str(cls.server.port)
]
)
- opts.mode = "reverse"
+ opts.mode = "reverse:" + s
return opts
def pathoc(self, sni=None):
@@ -373,9 +373,9 @@ class ChainProxyTest(ProxyTestBase):
def get_options(cls):
opts = super().get_options()
if cls.chain: # First proxy is in normal mode.
+ s = "http://127.0.0.1:%s" % cls.chain[0].port
opts.update(
- mode="upstream",
- upstream_server="http://127.0.0.1:%s" % cls.chain[0].port
+ mode="upstream:" + s,
)
return opts