Пример #1
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(),
        replace.Replace(),
        script.ScriptLoader(),
        serverplayback.ServerPlayback(),
        setheaders.SetHeaders(),
        stickyauth.StickyAuth(),
        stickycookie.StickyCookie(),
        streambodies.StreamBodies(),
        save.Save(),
        upstream_auth.UpstreamAuth(),
    ]
Пример #2
0
def default_addons():
    return [
        core.Core(),
        core_option_validation.CoreOptionValidation(),
        allowremote.AllowRemote(),
        anticache.AntiCache(),
        anticomp.AntiComp(),
        check_alpn.CheckALPN(),
        check_ca.CheckCA(),
        clientplayback.ClientPlayback(),
        cut.Cut(),
        disable_h2c.DisableH2C(),
        export.Export(),
        onboarding.Onboarding(),
        proxyauth.ProxyAuth(),
        replace.Replace(),
        script.ScriptLoader(),
        serverplayback.ServerPlayback(),
        setheaders.SetHeaders(),
        stickyauth.StickyAuth(),
        stickycookie.StickyCookie(),
        streambodies.StreamBodies(),
        save.Save(),
        upstream_auth.UpstreamAuth(),
    ]
Пример #3
0
 def test_configure(self):
     r = replace.Replace()
     with taddons.context() as tctx:
         tctx.configure(r, replacements=["one/two/three"])
         with pytest.raises(Exception, match="Invalid filter pattern"):
             tctx.configure(r, replacements=["/~b/two/three"])
         with pytest.raises(Exception, match="Invalid regular expression"):
             tctx.configure(r, replacements=["/foo/+/three"])
         tctx.configure(r, replacements=["/a/b/c/"])
Пример #4
0
 def test_configure(self):
     r = replace.Replace()
     with taddons.context() as tctx:
         tctx.configure(r, replacements=[("one", "two", "three")])
         with pytest.raises("invalid filter pattern"):
             tctx.configure(r, replacements=[("~b", "two", "three")])
         with pytest.raises("invalid regular expression"):
             tctx.configure(r, replacements=[("foo", "+", "three")])
         tctx.configure(r, replacements=["/a/b/c/"])
Пример #5
0
 def test_simple(self, tmpdir):
     r = replace.Replace()
     with taddons.context(r) as tctx:
         tmpfile = tmpdir.join("replacement")
         tmpfile.write("bar")
         tctx.configure(r, replacements=["/~q/foo/@" + str(tmpfile)])
         f = tflow.tflow()
         f.request.content = b"foo"
         r.request(f)
         assert f.request.content == b"bar"
Пример #6
0
 def test_configure(self):
     r = replace.Replace()
     updated = set(["replacements"])
     r.configure(options.Options(replacements=[("one", "two", "three")]),
                 updated)
     tutils.raises("invalid filter pattern", r.configure,
                   options.Options(replacements=[("~b", "two", "three")]),
                   updated)
     tutils.raises("invalid regular expression", r.configure,
                   options.Options(replacements=[("foo", "+", "three")]),
                   updated)
Пример #7
0
    def test_order(self):
        sa = replace.Replace()
        self.proxy.tmaster.addons.add(sa)

        self.proxy.tmaster.options.replacements = [("~q", "foo", "bar"),
                                                   ("~q", "bar", "baz"),
                                                   ("~q", "foo", "oh noes!"),
                                                   ("~s", "baz", "ORLY")]
        p = self.pathoc()
        with p.connect():
            req = p.request("get:'%s/p/418:b\"foo\"'" % self.server.urlbase)
        assert req.content == b"ORLY"
        assert req.status_code == 418
Пример #8
0
 def test_order(self):
     r = replace.Replace()
     with taddons.context(r) as tctx:
         tctx.configure(r,
                        replacements=[
                            "/foo/bar",
                            "/bar/baz",
                            "/foo/oh noes!",
                            "/bar/oh noes!",
                        ])
         f = tflow.tflow()
         f.request.content = b"foo"
         r.request(f)
         assert f.request.content == b"baz"
Пример #9
0
    async def test_nonexistent(self, tmpdir):
        r = replace.Replace()
        with taddons.context(r) as tctx:
            with pytest.raises(Exception, match="Invalid file path"):
                tctx.configure(r, replacements=["/~q/foo/@nonexistent"])

            tmpfile = tmpdir.join("replacement")
            tmpfile.write("bar")
            tctx.configure(r, replacements=["/~q/foo/@" + str(tmpfile)])
            tmpfile.remove()
            f = tflow.tflow()
            f.request.content = b"foo"
            r.request(f)
            assert await tctx.master.await_log("could not read")
Пример #10
0
def default_addons():
    return [
        onboarding.Onboarding(),
        anticache.AntiCache(),
        anticomp.AntiComp(),
        stickyauth.StickyAuth(),
        stickycookie.StickyCookie(),
        script.ScriptLoader(),
        filestreamer.FileStreamer(),
        streambodies.StreamBodies(),
        replace.Replace(),
        setheaders.SetHeaders(),
        serverplayback.ServerPlayback(),
        clientplayback.ClientPlayback(),
    ]
Пример #11
0
    def test_simple(self):
        r = replace.Replace()
        with taddons.context(r) as tctx:
            tctx.configure(r, replacements=[
                "/~q/foo/bar",
                "/~s/foo/bar",
            ])
            f = tflow.tflow()
            f.request.content = b"foo"
            r.request(f)
            assert f.request.content == b"bar"

            f = tflow.tflow(resp=True)
            f.response.content = b"foo"
            r.response(f)
            assert f.response.content == b"bar"
Пример #12
0
    def test_simple(self):
        o = options.Options(replacements=[
            ("~q", "foo", "bar"),
            ("~s", "foo", "bar"),
        ])
        m = master.Master(o, proxy.DummyServer())
        sa = replace.Replace()
        m.addons.add(sa)

        f = tutils.tflow()
        f.request.content = b"foo"
        m.request(f)
        assert f.request.content == b"bar"

        f = tutils.tflow(resp=True)
        f.response.content = b"foo"
        m.response(f)
        assert f.response.content == b"bar"
Пример #13
0
def default_addons():
    return [
        onboarding.Onboarding(),
        proxyauth.ProxyAuth(),
        anticache.AntiCache(),
        anticomp.AntiComp(),
        stickyauth.StickyAuth(),
        stickycookie.StickyCookie(),
        script.ScriptLoader(),
        streamfile.StreamFile(),
        streambodies.StreamBodies(),
        replace.Replace(),
        setheaders.SetHeaders(),
        serverplayback.ServerPlayback(),
        clientplayback.ClientPlayback(),
        upstream_auth.UpstreamAuth(),
        disable_h2c_upgrade.DisableH2CleartextUpgrade(),
    ]