flow_detail option to /addons/dumper

This commit is contained in:
Aldo Cortesi 2018-02-24 16:42:32 +13:00
parent 4fe83be63c
commit 93c49c47ae
4 changed files with 20 additions and 21 deletions

View File

@ -31,6 +31,18 @@ class Dumper:
self.filter = None # type: flowfilter.TFilter self.filter = None # type: flowfilter.TFilter
self.outfp = outfile # type: typing.io.TextIO self.outfp = outfile # type: typing.io.TextIO
def load(self, loader):
loader.add_option(
"flow_detail", int, 1,
"""
The display detail level for flows in mitmdump: 0 (almost quiet) to 3 (very verbose).
0: shortened request URL, response status code, WebSocket and TCP message notifications.
1: full request URL with response status code
2: 1 + HTTP headers
3: 2 + full response content, content of WebSocket and TCP messages.
"""
)
def configure(self, updated): def configure(self, updated):
if "view_filter" in updated: if "view_filter" in updated:
if ctx.options.view_filter: if ctx.options.view_filter:

View File

@ -58,7 +58,6 @@ class Options(optmanager.OptManager):
# because they're used by more than one addon, or because they're # because they're used by more than one addon, or because they're
# embedded in the core code somehow. # embedded in the core code somehow.
default_contentview = None # type: str default_contentview = None # type: str
flow_detail = None # type: int
intercept = None # type: Optional[str] intercept = None # type: Optional[str]
intercept_active = None # type: bool intercept_active = None # type: bool
proxyauth = None # type: Optional[str] proxyauth = None # type: Optional[str]
@ -267,16 +266,4 @@ class Options(optmanager.OptManager):
"Limit which flows are displayed." "Limit which flows are displayed."
) )
# Dump options
self.add_option(
"flow_detail", int, 1,
"""
The display detail level for flows in mitmdump: 0 (almost quiet) to 3 (very verbose).
0: shortened request URL, response status code, WebSocket and TCP message notifications.
1: full request URL with response status code
2: 1 + HTTP headers
3: 2 + full response content, content of WebSocket and TCP messages.
"""
)
self.update(**kwargs) self.update(**kwargs)

View File

@ -14,7 +14,7 @@ from mitmproxy import http
def test_configure(): def test_configure():
d = dumper.Dumper() d = dumper.Dumper()
with taddons.context() as ctx: with taddons.context(d) as ctx:
ctx.configure(d, view_filter="~b foo") ctx.configure(d, view_filter="~b foo")
assert d.filter assert d.filter
@ -33,7 +33,7 @@ def test_configure():
def test_simple(): def test_simple():
sio = io.StringIO() sio = io.StringIO()
d = dumper.Dumper(sio) d = dumper.Dumper(sio)
with taddons.context() as ctx: with taddons.context(d) as ctx:
ctx.configure(d, flow_detail=0) ctx.configure(d, flow_detail=0)
d.response(tflow.tflow(resp=True)) d.response(tflow.tflow(resp=True))
assert not sio.getvalue() assert not sio.getvalue()
@ -101,7 +101,7 @@ def test_echo_body():
sio = io.StringIO() sio = io.StringIO()
d = dumper.Dumper(sio) d = dumper.Dumper(sio)
with taddons.context() as ctx: with taddons.context(d) as ctx:
ctx.configure(d, flow_detail=3) ctx.configure(d, flow_detail=3)
d._echo_message(f.response) d._echo_message(f.response)
t = sio.getvalue() t = sio.getvalue()
@ -111,7 +111,7 @@ def test_echo_body():
def test_echo_request_line(): def test_echo_request_line():
sio = io.StringIO() sio = io.StringIO()
d = dumper.Dumper(sio) d = dumper.Dumper(sio)
with taddons.context() as ctx: with taddons.context(d) as ctx:
ctx.configure(d, flow_detail=3, showhost=True) ctx.configure(d, flow_detail=3, showhost=True)
f = tflow.tflow(client_conn=None, server_conn=True, resp=True) f = tflow.tflow(client_conn=None, server_conn=True, resp=True)
f.request.is_replay = True f.request.is_replay = True
@ -146,7 +146,7 @@ class TestContentView:
view_auto.side_effect = exceptions.ContentViewException("") view_auto.side_effect = exceptions.ContentViewException("")
sio = io.StringIO() sio = io.StringIO()
d = dumper.Dumper(sio) d = dumper.Dumper(sio)
with taddons.context() as ctx: with taddons.context(d) as ctx:
ctx.configure(d, flow_detail=4, verbosity='debug') ctx.configure(d, flow_detail=4, verbosity='debug')
d.response(tflow.tflow()) d.response(tflow.tflow())
assert ctx.master.has_log("content viewer failed") assert ctx.master.has_log("content viewer failed")
@ -155,7 +155,7 @@ class TestContentView:
def test_tcp(): def test_tcp():
sio = io.StringIO() sio = io.StringIO()
d = dumper.Dumper(sio) d = dumper.Dumper(sio)
with taddons.context() as ctx: with taddons.context(d) as ctx:
ctx.configure(d, flow_detail=3, showhost=True) ctx.configure(d, flow_detail=3, showhost=True)
f = tflow.ttcpflow() f = tflow.ttcpflow()
d.tcp_message(f) d.tcp_message(f)
@ -170,7 +170,7 @@ def test_tcp():
def test_websocket(): def test_websocket():
sio = io.StringIO() sio = io.StringIO()
d = dumper.Dumper(sio) d = dumper.Dumper(sio)
with taddons.context() as ctx: with taddons.context(d) as ctx:
ctx.configure(d, flow_detail=3, showhost=True) ctx.configure(d, flow_detail=3, showhost=True)
f = tflow.twebsocketflow() f = tflow.twebsocketflow()
d.websocket_message(f) d.websocket_message(f)

View File

@ -11,7 +11,7 @@ from .. import tservers
class TestDumpMaster(tservers.MasterTest): class TestDumpMaster(tservers.MasterTest):
def mkmaster(self, flt, **opts): def mkmaster(self, flt, **opts):
o = options.Options(view_filter=flt, verbosity='error', flow_detail=0, **opts) o = options.Options(view_filter=flt, verbosity='error', **opts)
m = dump.DumpMaster(o, with_termlog=False, with_dumper=False) m = dump.DumpMaster(o, with_termlog=False, with_dumper=False)
return m return m