aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mitmproxy/addons/keepserving.py10
-rw-r--r--mitmproxy/addons/onboarding.py20
-rw-r--r--mitmproxy/options.py29
-rw-r--r--test/mitmproxy/addons/test_keepserving.py3
-rw-r--r--test/mitmproxy/addons/test_onboarding.py18
-rw-r--r--test/mitmproxy/tservers.py4
6 files changed, 43 insertions, 41 deletions
diff --git a/mitmproxy/addons/keepserving.py b/mitmproxy/addons/keepserving.py
index 9c975a7b..6413299d 100644
--- a/mitmproxy/addons/keepserving.py
+++ b/mitmproxy/addons/keepserving.py
@@ -2,6 +2,16 @@ from mitmproxy import ctx
class KeepServing:
+ def load(self, loader):
+ loader.add_option(
+ "keepserving", bool, False,
+ """
+ Continue serving after client playback, server playback or file
+ read. This option is ignored by interactive tools, which always keep
+ serving.
+ """
+ )
+
def event_processing_complete(self):
if not ctx.master.options.keepserving:
ctx.master.shutdown()
diff --git a/mitmproxy/addons/onboarding.py b/mitmproxy/addons/onboarding.py
index 07536c34..900acb08 100644
--- a/mitmproxy/addons/onboarding.py
+++ b/mitmproxy/addons/onboarding.py
@@ -2,6 +2,9 @@ from mitmproxy.addons import wsgiapp
from mitmproxy.addons.onboardingapp import app
from mitmproxy import ctx
+APP_HOST = "mitm.it"
+APP_PORT = 80
+
class Onboarding(wsgiapp.WSGIApp):
name = "onboarding"
@@ -9,6 +12,23 @@ class Onboarding(wsgiapp.WSGIApp):
def __init__(self):
super().__init__(app.Adapter(app.application), None, None)
+ def load(self, loader):
+ loader.add_option(
+ "onboarding", bool, True,
+ "Toggle the mitmproxy onboarding app."
+ )
+ loader.add_option(
+ "onboarding_host", str, APP_HOST,
+ """
+ Onboarding app domain. For transparent mode, use an IP when a DNS
+ entry for the app domain is not present.
+ """
+ )
+ loader.add_option(
+ "onboarding_port", int, APP_PORT,
+ "Port to serve the onboarding app from."
+ )
+
def configure(self, updated):
self.host = ctx.options.onboarding_host
self.port = ctx.options.onboarding_port
diff --git a/mitmproxy/options.py b/mitmproxy/options.py
index ff13c385..31845858 100644
--- a/mitmproxy/options.py
+++ b/mitmproxy/options.py
@@ -12,8 +12,6 @@ log_verbosity = [
"debug",
]
-APP_HOST = "mitm.it"
-APP_PORT = 80
CA_DIR = "~/.mitmproxy"
LISTEN_PORT = 8080
@@ -69,10 +67,6 @@ class Options(optmanager.OptManager):
view_filter = None # type: Optional[str]
# FIXME: Options that should be uncomplicated to migrate to addons
- keepserving = None # type: bool
- onboarding = None # type: bool
- onboarding_host = None # type: str
- onboarding_port = None # type: int
server_replay_refresh = None # type: bool
replacements = None # type: Sequence[str]
rfile = None # type: Optional[str]
@@ -103,33 +97,10 @@ class Options(optmanager.OptManager):
def __init__(self, **kwargs) -> None:
super().__init__()
self.add_option(
- "onboarding", bool, True,
- "Toggle the mitmproxy onboarding app."
- )
- self.add_option(
- "onboarding_host", str, APP_HOST,
- """
- Onboarding app domain. For transparent mode, use an IP when a DNS
- entry for the app domain is not present.
- """
- )
- self.add_option(
- "onboarding_port", int, APP_PORT,
- "Port to serve the onboarding app from."
- )
- self.add_option(
"server_replay_kill_extra", bool, False,
"Kill extra requests during replay."
)
self.add_option(
- "keepserving", bool, False,
- """
- Continue serving after client playback, server playback or file
- read. This option is ignored by interactive tools, which always keep
- serving.
- """
- )
- self.add_option(
"server", bool, True,
"Start a proxy server. Enabled by default."
)
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/tservers.py b/test/mitmproxy/tservers.py
index dd5bb327..4363931f 100644
--- a/test/mitmproxy/tservers.py
+++ b/test/mitmproxy/tservers.py
@@ -222,12 +222,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):