mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
addon options: shift keepserving and onboarding options
This commit is contained in:
parent
a12d149230
commit
74a0230788
@ -2,6 +2,16 @@ from mitmproxy import ctx
|
|||||||
|
|
||||||
|
|
||||||
class KeepServing:
|
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):
|
def event_processing_complete(self):
|
||||||
if not ctx.master.options.keepserving:
|
if not ctx.master.options.keepserving:
|
||||||
ctx.master.shutdown()
|
ctx.master.shutdown()
|
||||||
|
@ -2,6 +2,9 @@ from mitmproxy.addons import wsgiapp
|
|||||||
from mitmproxy.addons.onboardingapp import app
|
from mitmproxy.addons.onboardingapp import app
|
||||||
from mitmproxy import ctx
|
from mitmproxy import ctx
|
||||||
|
|
||||||
|
APP_HOST = "mitm.it"
|
||||||
|
APP_PORT = 80
|
||||||
|
|
||||||
|
|
||||||
class Onboarding(wsgiapp.WSGIApp):
|
class Onboarding(wsgiapp.WSGIApp):
|
||||||
name = "onboarding"
|
name = "onboarding"
|
||||||
@ -9,6 +12,23 @@ class Onboarding(wsgiapp.WSGIApp):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(app.Adapter(app.application), None, None)
|
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):
|
def configure(self, updated):
|
||||||
self.host = ctx.options.onboarding_host
|
self.host = ctx.options.onboarding_host
|
||||||
self.port = ctx.options.onboarding_port
|
self.port = ctx.options.onboarding_port
|
||||||
|
@ -12,8 +12,6 @@ log_verbosity = [
|
|||||||
"debug",
|
"debug",
|
||||||
]
|
]
|
||||||
|
|
||||||
APP_HOST = "mitm.it"
|
|
||||||
APP_PORT = 80
|
|
||||||
CA_DIR = "~/.mitmproxy"
|
CA_DIR = "~/.mitmproxy"
|
||||||
LISTEN_PORT = 8080
|
LISTEN_PORT = 8080
|
||||||
|
|
||||||
@ -69,10 +67,6 @@ class Options(optmanager.OptManager):
|
|||||||
view_filter = None # type: Optional[str]
|
view_filter = None # type: Optional[str]
|
||||||
|
|
||||||
# FIXME: Options that should be uncomplicated to migrate to addons
|
# 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
|
server_replay_refresh = None # type: bool
|
||||||
replacements = None # type: Sequence[str]
|
replacements = None # type: Sequence[str]
|
||||||
rfile = None # type: Optional[str]
|
rfile = None # type: Optional[str]
|
||||||
@ -102,33 +96,10 @@ class Options(optmanager.OptManager):
|
|||||||
|
|
||||||
def __init__(self, **kwargs) -> None:
|
def __init__(self, **kwargs) -> None:
|
||||||
super().__init__()
|
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(
|
self.add_option(
|
||||||
"server_replay_kill_extra", bool, False,
|
"server_replay_kill_extra", bool, False,
|
||||||
"Kill extra requests during replay."
|
"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(
|
self.add_option(
|
||||||
"server", bool, True,
|
"server", bool, True,
|
||||||
"Start a proxy server. Enabled by default."
|
"Start a proxy server. Enabled by default."
|
||||||
|
@ -4,7 +4,6 @@ from mitmproxy.test import taddons
|
|||||||
|
|
||||||
def test_keepserving():
|
def test_keepserving():
|
||||||
ks = keepserving.KeepServing()
|
ks = keepserving.KeepServing()
|
||||||
|
with taddons.context(ks) as tctx:
|
||||||
with taddons.context() as tctx:
|
|
||||||
ks.event_processing_complete()
|
ks.event_processing_complete()
|
||||||
assert tctx.master.should_exit.is_set()
|
assert tctx.master.should_exit.is_set()
|
||||||
|
@ -2,7 +2,6 @@ import pytest
|
|||||||
|
|
||||||
from mitmproxy.addons import onboarding
|
from mitmproxy.addons import onboarding
|
||||||
from mitmproxy.test import taddons
|
from mitmproxy.test import taddons
|
||||||
from mitmproxy import options
|
|
||||||
from .. import tservers
|
from .. import tservers
|
||||||
|
|
||||||
|
|
||||||
@ -11,25 +10,28 @@ class TestApp(tservers.HTTPProxyTest):
|
|||||||
return [onboarding.Onboarding()]
|
return [onboarding.Onboarding()]
|
||||||
|
|
||||||
def test_basic(self):
|
def test_basic(self):
|
||||||
with taddons.context() as tctx:
|
ob = onboarding.Onboarding()
|
||||||
tctx.configure(self.addons()[0])
|
with taddons.context(ob) as tctx:
|
||||||
|
tctx.configure(ob)
|
||||||
assert self.app("/").status_code == 200
|
assert self.app("/").status_code == 200
|
||||||
|
|
||||||
@pytest.mark.parametrize("ext", ["pem", "p12"])
|
@pytest.mark.parametrize("ext", ["pem", "p12"])
|
||||||
def test_cert(self, ext):
|
def test_cert(self, ext):
|
||||||
with taddons.context() as tctx:
|
ob = onboarding.Onboarding()
|
||||||
tctx.configure(self.addons()[0])
|
with taddons.context(ob) as tctx:
|
||||||
|
tctx.configure(ob)
|
||||||
resp = self.app("/cert/%s" % ext)
|
resp = self.app("/cert/%s" % ext)
|
||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
assert resp.content
|
assert resp.content
|
||||||
|
|
||||||
@pytest.mark.parametrize("ext", ["pem", "p12"])
|
@pytest.mark.parametrize("ext", ["pem", "p12"])
|
||||||
def test_head(self, ext):
|
def test_head(self, ext):
|
||||||
with taddons.context() as tctx:
|
ob = onboarding.Onboarding()
|
||||||
tctx.configure(self.addons()[0])
|
with taddons.context(ob) as tctx:
|
||||||
|
tctx.configure(ob)
|
||||||
p = self.pathoc()
|
p = self.pathoc()
|
||||||
with p.connect():
|
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 resp.status_code == 200
|
||||||
assert "Content-Length" in resp.headers
|
assert "Content-Length" in resp.headers
|
||||||
assert not resp.content
|
assert not resp.content
|
||||||
|
@ -222,12 +222,12 @@ class HTTPProxyTest(ProxyTestBase):
|
|||||||
p = pathod.pathoc.Pathoc(
|
p = pathod.pathoc.Pathoc(
|
||||||
("127.0.0.1", self.proxy.port), True, fp=None
|
("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)
|
return p.request("get:'%s'" % page)
|
||||||
else:
|
else:
|
||||||
p = self.pathoc()
|
p = self.pathoc()
|
||||||
with p.connect():
|
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):
|
class TransparentProxyTest(ProxyTestBase):
|
||||||
|
Loading…
Reference in New Issue
Block a user