From 36c04f1631c79ca79712873e151c7f5267cafd46 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Mon, 3 Oct 2016 12:04:17 +0200 Subject: [PATCH] fix flowfilter.match args --- mitmproxy/builtins/dumper.py | 2 +- mitmproxy/builtins/stickyauth.py | 2 +- mitmproxy/builtins/stickycookie.py | 2 +- mitmproxy/console/master.py | 10 +++++----- mitmproxy/flow/io.py | 10 +++++----- mitmproxy/flowfilter.py | 2 +- test/mitmproxy/test_flow.py | 20 ++++++++++---------- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/mitmproxy/builtins/dumper.py b/mitmproxy/builtins/dumper.py index addf6abcc..109059b85 100644 --- a/mitmproxy/builtins/dumper.py +++ b/mitmproxy/builtins/dumper.py @@ -220,7 +220,7 @@ class Dumper(object): return False if not self.filter: return True - elif flowfilter.match(f, self.filter): + elif flowfilter.match(self.filter, f): return True return False diff --git a/mitmproxy/builtins/stickyauth.py b/mitmproxy/builtins/stickyauth.py index 9e5a928f1..18b439673 100644 --- a/mitmproxy/builtins/stickyauth.py +++ b/mitmproxy/builtins/stickyauth.py @@ -22,6 +22,6 @@ class StickyAuth: host = flow.request.host if "authorization" in flow.request.headers: self.hosts[host] = flow.request.headers["authorization"] - elif flowfilter.match(flow, self.flt): + elif flowfilter.match(self.flt, flow): if host in self.hosts: flow.request.headers["authorization"] = self.hosts[host] diff --git a/mitmproxy/builtins/stickycookie.py b/mitmproxy/builtins/stickycookie.py index 23a5f062f..027e624fa 100644 --- a/mitmproxy/builtins/stickycookie.py +++ b/mitmproxy/builtins/stickycookie.py @@ -64,7 +64,7 @@ class StickyCookie: def request(self, flow): if self.flt: l = [] - if flowfilter.match(flow, self.flt): + if flowfilter.match(self.flt, flow): for domain, port, path in self.jar.keys(): match = [ domain_match(flow.request.host, domain), diff --git a/mitmproxy/console/master.py b/mitmproxy/console/master.py index 2f20c087a..257765124 100644 --- a/mitmproxy/console/master.py +++ b/mitmproxy/console/master.py @@ -126,7 +126,7 @@ class ConsoleState(flow.State): self.set_focus(self.focus) return ret - def get_nearest_matching_flow(self, flow, filt): + def get_nearest_matching_flow(self, flow, flt): fidx = self.view.index(flow) dist = 1 @@ -135,9 +135,9 @@ class ConsoleState(flow.State): fprev, _ = self.get_from_pos(fidx - dist) fnext, _ = self.get_from_pos(fidx + dist) - if fprev and flowfilter.match(fprev, filt): + if fprev and flowfilter.match(flt, fprev): return fprev - elif fnext and flowfilter.match(fnext, filt): + elif fnext and flowfilter.match(flt, fnext): return fnext dist += 1 @@ -670,14 +670,14 @@ class ConsoleMaster(flow.FlowMaster): def process_flow(self, f): should_intercept = any( [ - self.state.intercept and flowfilter.match(f, self.state.intercept) and not f.request.is_replay, + self.state.intercept and flowfilter.match(self.state.intercept, f) and not f.request.is_replay, f.intercepted, ] ) if should_intercept: f.intercept(self) signals.flowlist_change.send(self) - signals.flow_change.send(self, flow = f) + signals.flow_change.send(self, flow=f) def clear_events(self): self.logbuffer[:] = [] diff --git a/mitmproxy/flow/io.py b/mitmproxy/flow/io.py index c12ff0e5d..07d4357c5 100644 --- a/mitmproxy/flow/io.py +++ b/mitmproxy/flow/io.py @@ -56,14 +56,14 @@ class FlowReader: class FilteredFlowWriter: - def __init__(self, fo, filt): + def __init__(self, fo, flt): self.fo = fo - self.filt = filt + self.flt = flt - def add(self, f): - if self.filt and not flowfilter.match(f, self.filt): + def add(self, flow): + if self.flt and not flowfilter.match(self.flt, flow): return - d = f.get_state() + d = flow.get_state() tnetstring.dump(d, self.fo) diff --git a/mitmproxy/flowfilter.py b/mitmproxy/flowfilter.py index 6ca74b686..27a3212ca 100644 --- a/mitmproxy/flowfilter.py +++ b/mitmproxy/flowfilter.py @@ -502,7 +502,7 @@ def parse(s): return None -def match(flow, flt): +def match(flt, flow): """ Matches a flow against a compiled filter expression. Returns True if matched, False if not. diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index a5a302a5b..cc9d26919 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -68,14 +68,14 @@ class TestHTTPFlow(object): def test_match(self): f = tutils.tflow(resp=True) - assert not flowfilter.match(f, "~b test") - assert flowfilter.match(f, None) - assert not flowfilter.match(f, "~b test") + assert not flowfilter.match("~b test", f) + assert flowfilter.match(None, f) + assert not flowfilter.match("~b test", f) f = tutils.tflow(err=True) - assert flowfilter.match(f, "~e") + assert flowfilter.match("~e", f) - tutils.raises(ValueError, flowfilter.match, f, "~") + tutils.raises(ValueError, flowfilter.match, "~", f) def test_backup(self): f = tutils.tflow() @@ -195,14 +195,14 @@ class TestTCPFlow: def test_match(self): f = tutils.ttcpflow() - assert not flowfilter.match(f, "~b nonexistent") - assert flowfilter.match(f, None) - assert not flowfilter.match(f, "~b nonexistent") + assert not flowfilter.match("~b nonexistent", f) + assert flowfilter.match(None, f) + assert not flowfilter.match("~b nonexistent", f) f = tutils.ttcpflow(err=True) - assert flowfilter.match(f, "~e") + assert flowfilter.match("~e", f) - tutils.raises(ValueError, flowfilter.match, f, "~") + tutils.raises(ValueError, flowfilter.match, "~", f) class TestState: