def test_playback(self): cp = clientplayback.ClientPlayback() with taddons.context() as tctx: assert cp.count() == 0 f = tflow.tflow(resp=True) cp.start_replay([f]) assert cp.count() == 1 RP = "mitmproxy.proxy.protocol.http_replay.RequestReplayThread" with mock.patch(RP) as rp: assert not cp.current_thread cp.tick() assert rp.called assert cp.current_thread cp.flows = None cp.current_thread = None cp.tick() assert tctx.master.has_event("processing_complete") cp.current_thread = MockThread() cp.tick() assert cp.current_thread is None cp.start_replay([f]) cp.stop_replay() assert not cp.flows
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_playback(self): cp = clientplayback.ClientPlayback() with taddons.context() as tctx: assert cp.count() == 0 f = tflow.tflow(resp=True) cp.start_replay([f]) assert cp.count() == 1 RP = "mitmproxy.proxy.protocol.http_replay.RequestReplayThread" with mock.patch(RP) as rp: assert not cp.current_thread cp.tick() assert rp.called assert cp.current_thread cp.flows = [] cp.current_thread.is_alive.return_value = False assert cp.count() == 1 cp.tick() assert cp.count() == 0 assert tctx.master.has_event("update") assert tctx.master.has_event("processing_complete") cp.current_thread = MockThread() cp.tick() assert cp.current_thread is None cp.start_replay([f]) cp.stop_replay() assert not cp.flows df = tflow.DummyFlow(tflow.tclient_conn(), tflow.tserver_conn(), True) with pytest.raises(exceptions.CommandError, match="Can't replay live flow."): cp.start_replay([df])
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 test_playback(self): cp = clientplayback.ClientPlayback() with taddons.context(): assert cp.count() == 0 f = tflow.tflow(resp=True) cp.load([f]) assert cp.count() == 1 RP = "mitmproxy.proxy.protocol.http_replay.RequestReplayThread" with mock.patch(RP) as rp: assert not cp.current_thread cp.tick() assert rp.called assert cp.current_thread cp.keepserving = False cp.flows = None cp.current_thread = None with mock.patch("mitmproxy.master.Master.shutdown") as sd: cp.tick() assert sd.called cp.current_thread = MockThread() with mock.patch("mitmproxy.master.Master.shutdown") as sd: cp.tick() assert cp.current_thread is None
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_load_file(self, tmpdir): cp = clientplayback.ClientPlayback() with taddons.context(cp): fpath = str(tmpdir.join("flows")) tdump(fpath, [tflow.tflow(resp=True)]) cp.load_file(fpath) assert cp.count() == 1 with pytest.raises(exceptions.CommandError): cp.load_file("/nonexistent")
def test_configure(self, tmpdir): cp = clientplayback.ClientPlayback() with taddons.context() as tctx: path = str(tmpdir.join("flows")) tdump(path, [tflow.tflow()]) tctx.configure(cp, client_replay=[path]) tctx.configure(cp, client_replay=[]) tctx.configure(cp) with pytest.raises(exceptions.OptionsError): tctx.configure(cp, client_replay=["nonexistent"])
def test_configure(self): cp = clientplayback.ClientPlayback() with taddons.context() as tctx: with tutils.tmpdir() as td: path = os.path.join(td, "flows") tdump(path, [tflow.tflow()]) tctx.configure(cp, client_replay=[path]) tctx.configure(cp, client_replay=[]) tctx.configure(cp) with pytest.raises(exceptions.OptionsError): tctx.configure(cp, client_replay=["nonexistent"])
def test_http2(self): cp = clientplayback.ClientPlayback() with taddons.context(cp): req = tutils.treq(headers=net_http.Headers(((b":authority", b"foo"), (b"header", b"qvalue"), (b"content-length", b"7")))) f = tflow.tflow(req=req) f.request.http_version = "HTTP/2.0" cp.start_replay([f]) assert f.request.http_version == "HTTP/1.1" assert ":authority" not in f.request.headers
async def test_playback(self): cp = clientplayback.ClientPlayback() with taddons.context(cp) as ctx: assert cp.count() == 0 f = tflow.tflow(resp=True) cp.start_replay([f]) assert cp.count() == 1 cp.stop_replay() assert cp.count() == 0 f.live = True cp.start_replay([f]) assert cp.count() == 0 await ctx.master.await_log("live")
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(), ]
def test_check(self): cp = clientplayback.ClientPlayback() with taddons.context(cp): f = tflow.tflow(resp=True) f.live = True assert "live flow" in cp.check(f) f = tflow.tflow(resp=True) f.intercepted = True assert "intercepted flow" in cp.check(f) f = tflow.tflow(resp=True) f.request = None assert "missing request" in cp.check(f) f = tflow.tflow(resp=True) f.request.raw_content = None assert "missing content" in cp.check(f)
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(), ]
def test_playback(self): cp = clientplayback.ClientPlayback() cp.configure(options.Options(), []) assert cp.count() == 0 f = tutils.tflow(resp=True) cp.load([f]) assert cp.count() == 1 RP = "mitmproxy.proxy.protocol.http_replay.RequestReplayThread" with mock.patch(RP) as rp: assert not cp.current with mastertest.mockctx(): cp.tick() rp.assert_called() assert cp.current cp.keepserving = False cp.flows = None cp.current = None with mock.patch("mitmproxy.master.Master.shutdown") as sd: with mastertest.mockctx(): cp.tick() sd.assert_called()
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(), ]
def test_configure(self): cp = clientplayback.ClientPlayback() cp.configure(options.Options(), [])
def addons(self): return [clientplayback.ClientPlayback()]