Beispiel #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(),
        script.ScriptLoader(),
        serverplayback.ServerPlayback(),
        mapremote.MapRemote(),
        modifybody.ModifyBody(),
        modifyheaders.ModifyHeaders(),
        stickyauth.StickyAuth(),
        stickycookie.StickyCookie(),
        streambodies.StreamBodies(),
        save.Save(),
        upstream_auth.UpstreamAuth(),
    ]
Beispiel #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(),
    ]
Beispiel #3
0
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(),
    ]
Beispiel #4
0
    async def test_order(self, tdata):
        rec = tdata.path("mitmproxy/data/addonscripts/recorder")
        sc = script.ScriptLoader()
        sc.is_running = True
        with taddons.context(sc) as tctx:
            tctx.configure(sc,
                           scripts=[
                               "%s/a.py" % rec,
                               "%s/b.py" % rec,
                               "%s/c.py" % rec,
                           ])
            await tctx.master.await_log("configure")
            debug = [i.msg for i in tctx.master.logs if i.level == "debug"]
            assert debug == [
                'a load',
                'a configure',
                'a running',
                'b load',
                'b configure',
                'b running',
                'c load',
                'c configure',
                'c running',
            ]

            tctx.master.clear()
            tctx.configure(sc,
                           scripts=[
                               "%s/c.py" % rec,
                               "%s/a.py" % rec,
                               "%s/b.py" % rec,
                           ])

            await tctx.master.await_log("b configure")
            debug = [i.msg for i in tctx.master.logs if i.level == "debug"]
            assert debug == [
                'c configure',
                'a configure',
                'b configure',
            ]

            tctx.master.clear()
            tctx.configure(sc, scripts=[
                "%s/e.py" % rec,
                "%s/a.py" % rec,
            ])
            await tctx.master.await_log("e configure")
            debug = [i.msg for i in tctx.master.logs if i.level == "debug"]
            assert debug == [
                'c done',
                'b done',
                'a configure',
                'e load',
                'e configure',
                'e running',
            ]

            # stop reload tasks
            tctx.configure(sc, scripts=[])
Beispiel #5
0
 def test_dupes(self):
     sc = script.ScriptLoader()
     with taddons.context(sc) as tctx:
         with pytest.raises(exceptions.OptionsError):
             tctx.configure(
                 sc,
                 scripts = ["one", "one"]
             )
Beispiel #6
0
    def test_order(self):
        rec = tutils.test_data.path("mitmproxy/data/addonscripts/recorder.py")
        sc = script.ScriptLoader()
        with taddons.context() as tctx:
            tctx.master.addons.add(sc)
            sc.running()
            tctx.configure(
                sc,
                scripts = [
                    "%s %s" % (rec, "a"),
                    "%s %s" % (rec, "b"),
                    "%s %s" % (rec, "c"),
                ]
            )
            debug = [(i[0], i[1]) for i in tctx.master.event_log if i[0] == "debug"]
            assert debug == [
                ('debug', 'a start'),
                ('debug', 'a configure'),
                ('debug', 'a running'),

                ('debug', 'b start'),
                ('debug', 'b configure'),
                ('debug', 'b running'),

                ('debug', 'c start'),
                ('debug', 'c configure'),
                ('debug', 'c running'),
            ]
            tctx.master.event_log = []
            tctx.configure(
                sc,
                scripts = [
                    "%s %s" % (rec, "c"),
                    "%s %s" % (rec, "a"),
                    "%s %s" % (rec, "b"),
                ]
            )
            debug = [(i[0], i[1]) for i in tctx.master.event_log if i[0] == "debug"]
            # No events, only order has changed
            assert debug == []

            tctx.master.event_log = []
            tctx.configure(
                sc,
                scripts = [
                    "%s %s" % (rec, "x"),
                    "%s %s" % (rec, "a"),
                ]
            )
            debug = [(i[0], i[1]) for i in tctx.master.event_log if i[0] == "debug"]
            assert debug == [
                ('debug', 'c done'),
                ('debug', 'b done'),
                ('debug', 'x start'),
                ('debug', 'x configure'),
                ('debug', 'x running'),
            ]
Beispiel #7
0
 def test_nonexistent(self):
     sc = script.ScriptLoader()
     with taddons.context() as tctx:
         tctx.master.addons.add(sc)
         with pytest.raises(exceptions.OptionsError):
             tctx.configure(
                 sc,
                 scripts = ["nonexistent"]
             )
Beispiel #8
0
 def test_simple(self):
     o = options.Options(scripts=[])
     m = master.Master(o, proxy.DummyServer())
     sc = script.ScriptLoader()
     m.addons.add(sc)
     assert len(m.addons) == 1
     o.update(
         scripts=[tutils.test_data.path("data/addonscripts/recorder.py")])
     assert len(m.addons) == 2
     o.update(scripts=[])
     assert len(m.addons) == 1
Beispiel #9
0
 async def test_script_run(self, tdata):
     rp = tdata.path("mitmproxy/data/addonscripts/recorder/recorder.py")
     sc = script.ScriptLoader()
     with taddons.context(sc) as tctx:
         sc.script_run([tflow.tflow(resp=True)], rp)
         await tctx.master.await_log("recorder response")
         debug = [i.msg for i in tctx.master.logs if i.level == "debug"]
         assert debug == [
             'recorder running', 'recorder configure',
             'recorder requestheaders', 'recorder request',
             'recorder responseheaders', 'recorder response'
         ]
Beispiel #10
0
 def test_script_run(self):
     rp = tutils.test_data.path(
         "mitmproxy/data/addonscripts/recorder/recorder.py")
     sc = script.ScriptLoader()
     with taddons.context() as tctx:
         sc.script_run([tflow.tflow(resp=True)], rp)
         debug = [i.msg for i in tctx.master.logs if i.level == "debug"]
         assert debug == [
             'recorder load', 'recorder running', 'recorder configure',
             'recorder tick', 'recorder requestheaders', 'recorder request',
             'recorder responseheaders', 'recorder response'
         ]
Beispiel #11
0
 def test_load_err(self, tdata):
     sc = script.ScriptLoader()
     with taddons.context(sc, loadcore=False) as tctx:
         tctx.configure(sc, scripts=[
             tdata.path("mitmproxy/data/addonscripts/load_error.py")
         ])
         try:
             tctx.invoke(sc, "tick")
         except ValueError:
             pass  # this is expected and normally guarded.
         # on the next tick we should not fail however.
         tctx.invoke(sc, "tick")
         assert len(tctx.master.addons) == 1
Beispiel #12
0
    def test_script_deletion(self):
        tdir = tutils.test_data.path("mitmproxy/data/addonscripts/")
        with open(tdir + "/dummy.py", 'w') as f:
            f.write("\n")
        with taddons.context() as tctx:
            sl = script.ScriptLoader()
            tctx.master.addons.add(sl)
            tctx.configure(sl, scripts=[tutils.test_data.path("mitmproxy/data/addonscripts/dummy.py")])

            os.remove(tutils.test_data.path("mitmproxy/data/addonscripts/dummy.py"))
            tctx.invoke(sl, "tick")
            assert not tctx.options.scripts
            assert not sl.addons
Beispiel #13
0
 def test_simple(self, tdata):
     sc = script.ScriptLoader()
     with taddons.context(loadcore=False) as tctx:
         tctx.master.addons.add(sc)
         sc.running()
         assert len(tctx.master.addons) == 1
         tctx.master.options.update(scripts=[
             tdata.path("mitmproxy/data/addonscripts/recorder/recorder.py")
         ])
         assert len(tctx.master.addons) == 1
         assert len(sc.addons) == 1
         tctx.master.options.update(scripts=[])
         assert len(tctx.master.addons) == 1
         assert len(sc.addons) == 0
Beispiel #14
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(),
    ]
Beispiel #15
0
    def test_order(self):
        rec = tutils.test_data.path("mitmproxy/data/addonscripts/recorder.py")
        sc = script.ScriptLoader()
        with taddons.context() as tctx:
            tctx.master.addons.add(sc)
            sc.running()
            tctx.configure(sc,
                           scripts=[
                               "%s %s" % (rec, "a"),
                               "%s %s" % (rec, "b"),
                               "%s %s" % (rec, "c"),
                           ])
            debug = [i.msg for i in tctx.master.logs if i.level == "debug"]
            assert debug == [
                'a load',
                'a configure',
                'a running',
                'b load',
                'b configure',
                'b running',
                'c load',
                'c configure',
                'c running',
            ]
            tctx.master.logs = []
            tctx.configure(sc,
                           scripts=[
                               "%s %s" % (rec, "c"),
                               "%s %s" % (rec, "a"),
                               "%s %s" % (rec, "b"),
                           ])
            debug = [i.msg for i in tctx.master.logs if i.level == "debug"]
            assert debug == []

            tctx.master.logs = []
            tctx.configure(sc,
                           scripts=[
                               "%s %s" % (rec, "x"),
                               "%s %s" % (rec, "a"),
                           ])
            debug = [i.msg for i in tctx.master.logs if i.level == "debug"]
            assert debug == [
                'c done',
                'b done',
                'x load',
                'x configure',
                'x running',
            ]
Beispiel #16
0
    async def test_script_deletion(self, tdata):
        tdir = tdata.path("mitmproxy/data/addonscripts/")
        with open(tdir + "/dummy.py", 'w') as f:
            f.write("\n")

        with taddons.context() as tctx:
            sl = script.ScriptLoader()
            tctx.master.addons.add(sl)
            tctx.configure(sl, scripts=[tdata.path("mitmproxy/data/addonscripts/dummy.py")])
            await tctx.master.await_log("Loading")

            os.remove(tdata.path("mitmproxy/data/addonscripts/dummy.py"))

            await tctx.master.await_log("Removing")
            assert not tctx.options.scripts
            assert not sl.addons
Beispiel #17
0
    def test_run_once(self):
        o = options.Options(scripts=[])
        m = master.Master(o, proxy.DummyServer())
        sl = script.ScriptLoader()
        m.addons.add(sl)

        f = tflow.tflow(resp=True)
        with m.handlecontext():
            sc = sl.run_once(
                tutils.test_data.path("data/addonscripts/recorder.py"), [f])
        evts = [i[1] for i in sc.ns.call_log]
        assert evts == [
            'start', 'requestheaders', 'request', 'responseheaders',
            'response', 'done'
        ]

        with m.handlecontext():
            tutils.raises("file not found", sl.run_once, "nonexistent", [f])
Beispiel #18
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(),
    ]
Beispiel #19
0
    def test_order(self):
        rec = tutils.test_data.path("data/addonscripts/recorder.py")

        o = options.Options(scripts=[
            "%s %s" % (rec, "a"),
            "%s %s" % (rec, "b"),
            "%s %s" % (rec, "c"),
        ])
        m = mastertest.RecordingMaster(o, proxy.DummyServer())
        sc = script.ScriptLoader()
        m.addons.add(sc)

        debug = [(i[0], i[1]) for i in m.event_log if i[0] == "debug"]
        assert debug == [('debug', 'a start'), ('debug', 'a configure'),
                         ('debug', 'b start'), ('debug', 'b configure'),
                         ('debug', 'c start'), ('debug', 'c configure')]
        m.event_log[:] = []

        o.scripts = [
            "%s %s" % (rec, "c"),
            "%s %s" % (rec, "a"),
            "%s %s" % (rec, "b"),
        ]
        debug = [(i[0], i[1]) for i in m.event_log if i[0] == "debug"]
        # No events, only order has changed
        assert debug == []

        o.scripts = [
            "%s %s" % (rec, "x"),
            "%s %s" % (rec, "a"),
        ]
        debug = [(i[0], i[1]) for i in m.event_log if i[0] == "debug"]
        assert debug == [
            ('debug', 'c done'),
            ('debug', 'b done'),
            ('debug', 'x start'),
            ('debug', 'x configure'),
            ('debug', 'a configure'),
        ]
Beispiel #20
0
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(),
    ]
Beispiel #21
0
 async def test_script_run_nonexistent(self):
     sc = script.ScriptLoader()
     with taddons.context(sc) as tctx:
         sc.script_run([tflow.tflow(resp=True)], "/")
         assert await tctx.master.await_log("/: No such script")
Beispiel #22
0
 def test_dupes(self):
     o = options.Options(scripts=["one", "one"])
     m = master.Master(o, proxy.DummyServer())
     sc = script.ScriptLoader()
     tutils.raises(exceptions.OptionsError, m.addons.add, o, sc)
Beispiel #23
0
 def test_nonexistent(self):
     o = options.Options(scripts=["nonexistent"])
     m = master.Master(o, proxy.DummyServer())
     sc = script.ScriptLoader()
     with pytest.raises(exceptions.OptionsError):
         m.addons.add(o, sc)
Beispiel #24
0
    def test_order(self):
        rec = tutils.test_data.path("mitmproxy/data/addonscripts/recorder")
        sc = script.ScriptLoader()
        sc.is_running = True
        with taddons.context() as tctx:
            tctx.configure(
                sc,
                scripts = [
                    "%s/a.py" % rec,
                    "%s/b.py" % rec,
                    "%s/c.py" % rec,
                ]
            )
            tctx.master.addons.invoke_addon(sc, "tick")
            debug = [i.msg for i in tctx.master.logs if i.level == "debug"]
            assert debug == [
                'a load',
                'a running',
                'a configure',
                'a tick',

                'b load',
                'b running',
                'b configure',
                'b tick',

                'c load',
                'c running',
                'c configure',
                'c tick',
            ]

            tctx.master.logs = []
            tctx.configure(
                sc,
                scripts = [
                    "%s/c.py" % rec,
                    "%s/a.py" % rec,
                    "%s/b.py" % rec,
                ]
            )

            debug = [i.msg for i in tctx.master.logs if i.level == "debug"]
            assert debug == [
                'c configure',
                'a configure',
                'b configure',
            ]

            tctx.master.logs = []
            tctx.configure(
                sc,
                scripts = [
                    "%s/e.py" % rec,
                    "%s/a.py" % rec,
                ]
            )
            tctx.master.addons.invoke_addon(sc, "tick")

            debug = [i.msg for i in tctx.master.logs if i.level == "debug"]
            assert debug == [
                'c done',
                'b done',
                'a configure',
                'e load',
                'e running',
                'e configure',
                'e tick',
                'a tick',
            ]
Beispiel #25
0
 def test_script_run_nonexistent(self):
     sc = script.ScriptLoader()
     with taddons.context():
         with pytest.raises(exceptions.CommandError):
             sc.script_run([tflow.tflow(resp=True)], "/")
Beispiel #26
0
 def test_nonexistent(self):
     sc = script.ScriptLoader()
     with taddons.context() as tctx:
         tctx.master.addons.add(sc)
         tctx.configure(sc, scripts=["nonexistent"])
         tctx.master.has_log("nonexistent: file not found")