aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mitmproxy/addons/intercept.py5
-rw-r--r--mitmproxy/controller.py8
-rw-r--r--mitmproxy/test/taddons.py14
-rw-r--r--test/mitmproxy/addons/test_intercept.py11
4 files changed, 31 insertions, 7 deletions
diff --git a/mitmproxy/addons/intercept.py b/mitmproxy/addons/intercept.py
index 14ef7410..a016025f 100644
--- a/mitmproxy/addons/intercept.py
+++ b/mitmproxy/addons/intercept.py
@@ -19,11 +19,10 @@ class Intercept:
def process_flow(self, f):
if self.filt:
- should_intercept = all(
+ should_intercept = all([
self.filt(f),
not f.request.is_replay,
- f.reply.state == "handled"
- )
+ ])
if should_intercept:
f.intercept(ctx.master)
diff --git a/mitmproxy/controller.py b/mitmproxy/controller.py
index c5e125ce..868d5841 100644
--- a/mitmproxy/controller.py
+++ b/mitmproxy/controller.py
@@ -174,10 +174,10 @@ class Reply:
class DummyReply(Reply):
"""
- A reply object that is not connected to anything. In contrast to regular Reply objects,
- DummyReply objects are reset to "unhandled" at the end of an handler so that they can be used
- multiple times. Useful when we need an object to seem like it has a channel,
- and during testing.
+ A reply object that is not connected to anything. In contrast to regular
+ Reply objects, DummyReply objects are reset to "unhandled" at the end of an
+ handler so that they can be used multiple times. Useful when we need an
+ object to seem like it has a channel, and during testing.
"""
def __init__(self):
super().__init__(None)
diff --git a/mitmproxy/test/taddons.py b/mitmproxy/test/taddons.py
index a22fd5e2..819d58ab 100644
--- a/mitmproxy/test/taddons.py
+++ b/mitmproxy/test/taddons.py
@@ -1,6 +1,7 @@
import mitmproxy.master
import mitmproxy.options
from mitmproxy import proxy
+from mitmproxy import events
class context:
@@ -26,6 +27,19 @@ class context:
self.wrapped = None
return False
+ def cycle(self, addon, f):
+ """
+ Cycles the flow through the events for the flow. Stops if a reply
+ is taken (as in flow interception).
+ """
+ f.reply._state = "handled"
+ for evt, arg in events.event_sequence(f):
+ h = getattr(addon, evt, None)
+ if h:
+ h(arg)
+ if f.reply.state == "taken":
+ return
+
def configure(self, addon, **kwargs):
"""
A helper for testing configure methods. Modifies the registered
diff --git a/test/mitmproxy/addons/test_intercept.py b/test/mitmproxy/addons/test_intercept.py
index 19828a62..f389ff8e 100644
--- a/test/mitmproxy/addons/test_intercept.py
+++ b/test/mitmproxy/addons/test_intercept.py
@@ -3,6 +3,7 @@ from mitmproxy import options
from mitmproxy import exceptions
from mitmproxy.test import taddons
from mitmproxy.test import tutils
+from mitmproxy.test import tflow
class Options(options.Options):
@@ -23,3 +24,13 @@ def test_simple():
r,
intercept="~~"
)
+
+ tctx.configure(r, intercept="~s")
+
+ f = tflow.tflow(resp=True)
+ tctx.cycle(r, f)
+ assert f.intercepted
+
+ f = tflow.tflow(resp=False)
+ tctx.cycle(r, f)
+ assert not f.intercepted