def test_cut(): v = view.View() c = cut.Cut() with taddons.context() as tctx: v.add([tflow.tflow(resp=True)]) tctx.master.addons.add(v, c) assert c.cut("q.method|@all") == [["GET"]] assert c.cut("q.scheme|@all") == [["http"]] assert c.cut("q.host|@all") == [["address"]] assert c.cut("q.port|@all") == [["22"]] assert c.cut("q.path|@all") == [["/path"]] assert c.cut("q.url|@all") == [["http://*****:*****@all") == [[b"content"]] assert c.cut("q.header[header]|@all") == [["qvalue"]] assert c.cut("q.header[unknown]|@all") == [[""]] assert c.cut("s.status_code|@all") == [["200"]] assert c.cut("s.reason|@all") == [["OK"]] assert c.cut("s.content|@all") == [[b"message"]] assert c.cut("s.header[header-response]|@all") == [["svalue"]] assert c.cut("moo") == [[""]] with pytest.raises(exceptions.CommandError): assert c.cut("__dict__") == [[""]] v = view.View() c = cut.Cut() with taddons.context() as tctx: tctx.master.addons.add(v, c) v.add([tflow.ttcpflow()]) assert c.cut("q.method|@all") == [[""]] assert c.cut("s.status|@all") == [[""]]
def test_cut(): c = cut.Cut() with taddons.context(): tflows = [tflow.tflow(resp=True)] assert c.cut(tflows, ["request.method"]) == [["GET"]] assert c.cut(tflows, ["request.scheme"]) == [["http"]] assert c.cut(tflows, ["request.host"]) == [["address"]] assert c.cut(tflows, ["request.port"]) == [["22"]] assert c.cut(tflows, ["request.path"]) == [["/path"]] assert c.cut(tflows, ["request.url"]) == [["http://address:22/path"]] assert c.cut(tflows, ["request.content"]) == [[b"content"]] assert c.cut(tflows, ["request.header[header]"]) == [["qvalue"]] assert c.cut(tflows, ["request.header[unknown]"]) == [[""]] assert c.cut(tflows, ["response.status_code"]) == [["200"]] assert c.cut(tflows, ["response.reason"]) == [["OK"]] assert c.cut(tflows, ["response.content"]) == [[b"message"]] assert c.cut(tflows, ["response.header[header-response]"]) == [["svalue"]] assert c.cut(tflows, ["moo"]) == [[""]] with pytest.raises(exceptions.CommandError): assert c.cut(tflows, ["__dict__"]) == [[""]] with taddons.context(): tflows = [tflow.tflow(resp=False)] assert c.cut(tflows, ["response.reason"]) == [[""]] assert c.cut(tflows, ["response.header[key]"]) == [[""]] c = cut.Cut() with taddons.context(): tflows = [tflow.ttcpflow()] assert c.cut(tflows, ["request.method"]) == [[""]] assert c.cut(tflows, ["response.status"]) == [[""]]
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_cut_clip(): v = view.View() c = cut.Cut() with taddons.context() as tctx: tctx.master.addons.add(v, c) v.add([tflow.tflow(resp=True)]) with mock.patch('pyperclip.copy') as pc: tctx.command(c.clip, "@all", "request.method") assert pc.called with mock.patch('pyperclip.copy') as pc: tctx.command(c.clip, "@all", "request.content") assert pc.called with mock.patch('pyperclip.copy') as pc: tctx.command(c.clip, "@all", "request.method,request.content") assert pc.called with mock.patch('pyperclip.copy') as pc: log_message = "Pyperclip could not find a " \ "copy/paste mechanism for your system." pc.side_effect = pyperclip.PyperclipException(log_message) tctx.command(c.clip, "@all", "request.method") assert tctx.master.has_log(log_message, level="error")
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(), ]
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 test_cut_save_open(exception, log_message, tmpdir): f = str(tmpdir.join("path")) v = view.View() c = cut.Cut() with taddons.context() as tctx: tctx.master.addons.add(v, c) v.add([tflow.tflow(resp=True)]) with mock.patch("mitmproxy.addons.cut.open") as m: m.side_effect = exception(log_message) tctx.command(c.save, "@all", "request.method", f) assert tctx.master.has_log(log_message, level="error")
def test_cut_clip(): v = view.View() c = cut.Cut() with taddons.context() as tctx: tctx.master.addons.add(v, c) v.add([tflow.tflow(resp=True)]) with mock.patch('pyperclip.copy') as pc: tctx.command(c.clip, "@all", "request.method") assert pc.called with mock.patch('pyperclip.copy') as pc: tctx.command(c.clip, "@all", "request.content") assert pc.called with mock.patch('pyperclip.copy') as pc: tctx.command(c.clip, "@all", "request.method,request.content") assert pc.called
def test_cut_save(tmpdir): f = str(tmpdir.join("path")) v = view.View() c = cut.Cut() with taddons.context() as tctx: tctx.master.addons.add(v, c) v.add([tflow.tflow(resp=True)]) tctx.command(c.save, "@all", "request.method", f) assert qr(f) == b"GET" tctx.command(c.save, "@all", "request.content", f) assert qr(f) == b"content" tctx.command(c.save, "@all", "request.content", "+" + f) assert qr(f) == b"content\ncontent" v.add([tflow.tflow(resp=True)]) tctx.command(c.save, "@all", "request.method", f) assert qr(f).splitlines() == [b"GET", b"GET"] tctx.command(c.save, "@all", "request.method,request.content", f) assert qr(f).splitlines() == [b"GET,content", b"GET,content"]
def default_addons(): return [ core.Core(), browser.Browser(), block.Block(), anticache.AntiCache(), anticomp.AntiComp(), 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(), ]