mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Add test for iframe_injector example
This commit is contained in:
parent
ba1cf18f42
commit
2cd5392657
@ -14,7 +14,7 @@ def response(context, flow):
|
|||||||
if flow.request.host in context.iframe_url:
|
if flow.request.host in context.iframe_url:
|
||||||
return
|
return
|
||||||
with decoded(flow.response): # Remove content encoding (gzip, ...)
|
with decoded(flow.response): # Remove content encoding (gzip, ...)
|
||||||
html = BeautifulSoup(flow.response.content)
|
html = BeautifulSoup(flow.response.content, "lxml")
|
||||||
if html.body:
|
if html.body:
|
||||||
iframe = html.new_tag(
|
iframe = html.new_tag(
|
||||||
"iframe",
|
"iframe",
|
||||||
|
@ -9,6 +9,7 @@ from . import tservers, tutils
|
|||||||
from examples import (
|
from examples import (
|
||||||
add_header,
|
add_header,
|
||||||
custom_contentviews,
|
custom_contentviews,
|
||||||
|
iframe_injector,
|
||||||
modify_form,
|
modify_form,
|
||||||
modify_querystring,
|
modify_querystring,
|
||||||
modify_response_body,
|
modify_response_body,
|
||||||
@ -16,7 +17,9 @@ from examples import (
|
|||||||
|
|
||||||
|
|
||||||
class DummyContext(object):
|
class DummyContext(object):
|
||||||
pass
|
|
||||||
|
def log(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def test_load_scripts():
|
def test_load_scripts():
|
||||||
@ -81,3 +84,15 @@ def test_custom_contentviews():
|
|||||||
_, fmt = pig("<html>test!</html>")
|
_, fmt = pig("<html>test!</html>")
|
||||||
assert any('esttay!' in val[0][1] for val in fmt)
|
assert any('esttay!' in val[0][1] for val in fmt)
|
||||||
assert not pig("gobbledygook")
|
assert not pig("gobbledygook")
|
||||||
|
|
||||||
|
|
||||||
|
def test_iframe_injector():
|
||||||
|
ctx = DummyContext()
|
||||||
|
tutils.raises(ValueError, iframe_injector.start, ctx, [])
|
||||||
|
|
||||||
|
flow = tutils.tflow(resp=netutils.tresp(content="<html>Kungfu Panda 3</html>"))
|
||||||
|
ctx.iframe_url = "http://example.org/evil_iframe"
|
||||||
|
iframe_injector.response(ctx, flow)
|
||||||
|
|
||||||
|
content = flow.response.content
|
||||||
|
assert 'iframe' in content and ctx.iframe_url in content
|
||||||
|
Loading…
Reference in New Issue
Block a user