diff options
| author | Shadab Zafar <dufferzafar0@gmail.com> | 2016-03-07 10:10:29 +0530 | 
|---|---|---|
| committer | Shadab Zafar <dufferzafar0@gmail.com> | 2016-03-11 17:57:57 +0530 | 
| commit | 2cd5392657d29179e9ddae9f43a849276df030f9 (patch) | |
| tree | c144bd260aa930f1718b64955f819a73d4cf42e8 | |
| parent | ba1cf18f4255cf7e59ce51d48521852fb876dbd9 (diff) | |
| download | mitmproxy-2cd5392657d29179e9ddae9f43a849276df030f9.tar.gz mitmproxy-2cd5392657d29179e9ddae9f43a849276df030f9.tar.bz2 mitmproxy-2cd5392657d29179e9ddae9f43a849276df030f9.zip  | |
Add test for iframe_injector example
| -rw-r--r-- | examples/iframe_injector.py | 2 | ||||
| -rw-r--r-- | test/mitmproxy/test_examples.py | 17 | 
2 files changed, 17 insertions, 2 deletions
diff --git a/examples/iframe_injector.py b/examples/iframe_injector.py index fc38b136..ad844f19 100644 --- a/examples/iframe_injector.py +++ b/examples/iframe_injector.py @@ -14,7 +14,7 @@ def response(context, flow):      if flow.request.host in context.iframe_url:          return      with decoded(flow.response):  # Remove content encoding (gzip, ...) -        html = BeautifulSoup(flow.response.content) +        html = BeautifulSoup(flow.response.content, "lxml")          if html.body:              iframe = html.new_tag(                  "iframe", diff --git a/test/mitmproxy/test_examples.py b/test/mitmproxy/test_examples.py index 5d1a18ed..c134ec30 100644 --- a/test/mitmproxy/test_examples.py +++ b/test/mitmproxy/test_examples.py @@ -9,6 +9,7 @@ from . import tservers, tutils  from examples import (      add_header,      custom_contentviews, +    iframe_injector,      modify_form,      modify_querystring,      modify_response_body, @@ -16,7 +17,9 @@ from examples import (  class DummyContext(object): -    pass + +    def log(self, *args, **kwargs): +        pass  def test_load_scripts(): @@ -81,3 +84,15 @@ def test_custom_contentviews():      _, fmt = pig("<html>test!</html>")      assert any('esttay!' in val[0][1] for val in fmt)      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  | 
