コード例 #1
0
ファイル: __init__.py プロジェクト: scrapfly/mitmproxy
def default_addons():
    return [
        core.Core(),
        browser.Browser(),
        block.Block(),
        blocklist.BlockList(),
        anticache.AntiCache(),
        anticomp.AntiComp(),
        clientplayback.ClientPlayback(),
        command_history.CommandHistory(),
        comment.Comment(),
        cut.Cut(),
        disable_h2c.DisableH2C(),
        export.Export(),
        onboarding.Onboarding(),
        proxyauth.ProxyAuth(),
        proxyserver.Proxyserver(),
        script.ScriptLoader(),
        next_layer.NextLayer(),
        serverplayback.ServerPlayback(),
        mapremote.MapRemote(),
        maplocal.MapLocal(),
        modifybody.ModifyBody(),
        modifyheaders.ModifyHeaders(),
        stickyauth.StickyAuth(),
        stickycookie.StickyCookie(),
        save.Save(),
        tlsconfig.TlsConfig(),
        upstream_auth.UpstreamAuth(),
    ]
コード例 #2
0
def default_addons():
    return [
        core.Core(),
        browser.Browser(),
        block.Block(),
        anticache.AntiCache(),
        anticomp.AntiComp(),
        check_ca.CheckCA(),
        clientplayback.ClientPlayback(),
        command_history.CommandHistory(),
        cut.Cut(),
        disable_h2c.DisableH2C(),
        export.Export(),
        onboarding.Onboarding(),
        proxyauth.ProxyAuth(),
        script.ScriptLoader(),
        serverplayback.ServerPlayback(),
        mapremote.MapRemote(),
        modifybody.ModifyBody(),
        modifyheaders.ModifyHeaders(),
        stickyauth.StickyAuth(),
        stickycookie.StickyCookie(),
        streambodies.StreamBodies(),
        save.Save(),
        upstream_auth.UpstreamAuth(),
    ]
コード例 #3
0
 def test_configure(self):
     mb = modifybody.ModifyBody()
     with taddons.context(mb) as tctx:
         tctx.configure(mb, modify_body=["one/two/three"])
         with pytest.raises(Exception, match="Cannot parse modify_body"):
             tctx.configure(mb, modify_body=["/"])
         tctx.configure(mb, modify_body=["/a/b/c/"])
コード例 #4
0
 def test_simple(self, tmpdir):
     mb = modifybody.ModifyBody()
     with taddons.context(mb) as tctx:
         tmpfile = tmpdir.join("replacement")
         tmpfile.write("bar")
         tctx.configure(mb, modify_body=["/~q/foo/@" + str(tmpfile)])
         f = tflow.tflow()
         f.request.content = b"foo"
         mb.request(f)
         assert f.request.content == b"bar"
コード例 #5
0
    async def test_nonexistent(self, tmpdir):
        mb = modifybody.ModifyBody()
        with taddons.context(mb) as tctx:
            with pytest.raises(Exception, match="Invalid file path"):
                tctx.configure(mb, modify_body=["/~q/foo/@nonexistent"])

            tmpfile = tmpdir.join("replacement")
            tmpfile.write("bar")
            tctx.configure(mb, modify_body=["/~q/foo/@" + str(tmpfile)])
            tmpfile.remove()
            f = tflow.tflow()
            f.request.content = b"foo"
            mb.request(f)
            assert await tctx.master.await_log("could not read")
コード例 #6
0
 def test_order(self):
     mb = modifybody.ModifyBody()
     with taddons.context(mb) as tctx:
         tctx.configure(mb,
                        modify_body=[
                            "/foo/bar",
                            "/bar/baz",
                            "/foo/oh noes!",
                            "/bar/oh noes!",
                        ])
         f = tflow.tflow()
         f.request.content = b"foo"
         mb.request(f)
         assert f.request.content == b"baz"
コード例 #7
0
    def test_simple(self):
        mb = modifybody.ModifyBody()
        with taddons.context(mb) as tctx:
            tctx.configure(mb, modify_body=[
                "/~q/foo/bar",
                "/~s/foo/bar",
            ])
            f = tflow.tflow()
            f.request.content = b"foo"
            mb.request(f)
            assert f.request.content == b"bar"

            f = tflow.tflow(resp=True)
            f.response.content = b"foo"
            mb.response(f)
            assert f.response.content == b"bar"
コード例 #8
0
    def test_taken(self, take):
        mb = modifybody.ModifyBody()
        with taddons.context(mb) as tctx:
            tctx.configure(mb, modify_body=["/foo/bar"])
            f = tflow.tflow()
            f.request.content = b"foo"
            if take:
                f.response = tresp()
            mb.request(f)
            assert (f.request.content == b"bar") ^ take

            f = tflow.tflow(resp=True)
            f.response.content = b"foo"
            if take:
                f.kill()
            mb.response(f)
            assert (f.response.content == b"bar") ^ take
コード例 #9
0
 def test_configure(self):
     mb = modifybody.ModifyBody()
     with taddons.context(mb) as tctx:
         tctx.configure(mb, modify_body=["one/two/three"])
         with pytest.raises(
                 Exception,
                 match="Cannot parse modify_body .* Invalid number"):
             tctx.configure(mb, modify_body=["/"])
         with pytest.raises(
                 Exception,
                 match="Cannot parse modify_body .* Invalid filter"):
             tctx.configure(mb, modify_body=["/~b/two/three"])
         with pytest.raises(
                 Exception,
                 match=
                 "Cannot parse modify_body .* Invalid regular expression"):
             tctx.configure(mb, modify_body=["/foo/+/three"])
         tctx.configure(mb, modify_body=["/a/b/c/"])