From e5cdc20eb8cd8ebf5ab0ab8bd5ae9889054821df Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Mon, 26 Feb 2018 09:43:15 +1300 Subject: [PATCH] Split dumper_filter off from view_filter These don't even do the same thing. --- mitmproxy/addons/dumper.py | 12 ++++++++---- mitmproxy/addons/view.py | 4 ++++ mitmproxy/options.py | 10 ---------- test/mitmproxy/addons/test_dumper.py | 6 +++--- test/mitmproxy/tools/test_dump.py | 6 +++--- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/mitmproxy/addons/dumper.py b/mitmproxy/addons/dumper.py index 0df2d3395..aaad8aa29 100644 --- a/mitmproxy/addons/dumper.py +++ b/mitmproxy/addons/dumper.py @@ -47,14 +47,18 @@ class Dumper: "The default content view mode.", choices = [i.name.lower() for i in contentviews.views] ) + loader.add_option( + "dumper_filter", typing.Optional[str], None, + "Limit which flows are dumped." + ) def configure(self, updated): - if "view_filter" in updated: - if ctx.options.view_filter: - self.filter = flowfilter.parse(ctx.options.view_filter) + if "dumper_filter" in updated: + if ctx.options.dumper_filter: + self.filter = flowfilter.parse(ctx.options.dumper_filter) if not self.filter: raise exceptions.OptionsError( - "Invalid filter expression: %s" % ctx.options.view_filter + "Invalid filter expression: %s" % ctx.options.dumper_filter ) else: self.filter = None diff --git a/mitmproxy/addons/view.py b/mitmproxy/addons/view.py index c0f7e7b44..598cb66d4 100644 --- a/mitmproxy/addons/view.py +++ b/mitmproxy/addons/view.py @@ -146,6 +146,10 @@ class View(collections.Sequence): self.settings = Settings(self) def load(self, loader): + loader.add_option( + "view_filter", typing.Optional[str], None, + "Limit the view to matching flows." + ) loader.add_option( "view_order", str, "time", "Flow sort order.", diff --git a/mitmproxy/options.py b/mitmproxy/options.py index 0ada5306b..b6f3398b4 100644 --- a/mitmproxy/options.py +++ b/mitmproxy/options.py @@ -41,11 +41,6 @@ class Options(optmanager.OptManager): upstream_cert = None # type: bool websocket = None # type: bool - # FIXME: Options that must be migrated to addons, but are complicated - # because they're used by more than one addon, or because they're - # embedded in the core code somehow. - view_filter = None # type: Optional[str] - def __init__(self, **kwargs) -> None: super().__init__() self.add_option( @@ -212,9 +207,4 @@ class Options(optmanager.OptManager): """ ) - self.add_option( - "view_filter", Optional[str], None, - "Limit which flows are displayed." - ) - self.update(**kwargs) diff --git a/test/mitmproxy/addons/test_dumper.py b/test/mitmproxy/addons/test_dumper.py index 7c54ab88a..228bacf8b 100644 --- a/test/mitmproxy/addons/test_dumper.py +++ b/test/mitmproxy/addons/test_dumper.py @@ -15,7 +15,7 @@ from mitmproxy import http def test_configure(): d = dumper.Dumper() with taddons.context(d) as ctx: - ctx.configure(d, view_filter="~b foo") + ctx.configure(d, dumper_filter="~b foo") assert d.filter f = tflow.tflow(resp=True) @@ -23,10 +23,10 @@ def test_configure(): f.response.content = b"foo" assert d.match(f) - ctx.configure(d, view_filter=None) + ctx.configure(d, dumper_filter=None) assert not d.filter with pytest.raises(exceptions.OptionsError): - ctx.configure(d, view_filter="~~") + ctx.configure(d, dumper_filter="~~") assert not d.filter diff --git a/test/mitmproxy/tools/test_dump.py b/test/mitmproxy/tools/test_dump.py index 9e67f420f..f950d7191 100644 --- a/test/mitmproxy/tools/test_dump.py +++ b/test/mitmproxy/tools/test_dump.py @@ -10,13 +10,13 @@ from .. import tservers class TestDumpMaster(tservers.MasterTest): - def mkmaster(self, flt, **opts): - o = options.Options(view_filter=flt, **opts) + def mkmaster(self, **opts): + o = options.Options(**opts) m = dump.DumpMaster(o, with_termlog=False, with_dumper=False) return m def test_has_error(self): - m = self.mkmaster(None) + m = self.mkmaster() ent = log.LogEntry("foo", "error") ent.reply = controller.DummyReply() m.addons.trigger("log", ent)