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(), ]
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(), ]
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/"])
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"
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")
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"
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"
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
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/"])