mirror of
https://github.com/vee1e/mitmproxy.git
synced 2026-09-01 18:27:18 +00:00
intercept: tests++
This commit is contained in:
parent
28f04c93fd
commit
327e933faf
2 changed files with 24 additions and 4 deletions
|
|
@ -30,7 +30,7 @@ class Intercept:
|
|||
ctx.options.intercept_active = False
|
||||
|
||||
def should_intercept(self, f: flow.Flow) -> bool:
|
||||
return (
|
||||
return bool(
|
||||
ctx.options.intercept_active
|
||||
and self.filt
|
||||
and self.filt(f)
|
||||
|
|
@ -39,6 +39,7 @@ class Intercept:
|
|||
|
||||
def process_flow(self, f: flow.Flow) -> None:
|
||||
if self.should_intercept(f):
|
||||
assert f.reply
|
||||
if f.reply.state != "start":
|
||||
return ctx.log.debug("Cannot intercept request that is already taken by another addon.")
|
||||
f.intercept()
|
||||
|
|
|
|||
|
|
@ -43,12 +43,31 @@ def test_simple():
|
|||
tctx.cycle(r, f)
|
||||
assert f.intercepted
|
||||
|
||||
|
||||
def test_tcp():
|
||||
r = intercept.Intercept()
|
||||
with taddons.context(r) as tctx:
|
||||
tctx.configure(r, intercept="~tcp")
|
||||
f = tflow.ttcpflow()
|
||||
tctx.cycle(r, f)
|
||||
assert f.intercepted
|
||||
|
||||
tctx.configure(r, intercept_active=False)
|
||||
f = tflow.ttcpflow()
|
||||
tctx.cycle(r, f)
|
||||
assert not f.intercepted
|
||||
|
||||
tctx.configure(r, intercept_active=True)
|
||||
f = tflow.ttcpflow()
|
||||
tctx.cycle(r, f)
|
||||
|
||||
def test_already_taken():
|
||||
r = intercept.Intercept()
|
||||
with taddons.context(r) as tctx:
|
||||
tctx.configure(r, intercept="~q")
|
||||
|
||||
f = tflow.tflow()
|
||||
tctx.invoke(r, "request", f)
|
||||
assert f.intercepted
|
||||
|
||||
f = tflow.tflow()
|
||||
f.reply.take()
|
||||
tctx.invoke(r, "request", f)
|
||||
assert not f.intercepted
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue