Ejemplo n.º 1
0
def test_load_script():
    ns = script.load_script(
        tutils.test_data.path(
            "mitmproxy/data/addonscripts/recorder/recorder.py"))
    assert ns.addons

    with pytest.raises(FileNotFoundError):
        script.load_script("nonexistent")
Ejemplo n.º 2
0
def test_load_script():
    with taddons.context() as tctx:
        ns = script.load_script(
            tctx.ctx(),
            tutils.test_data.path(
                "mitmproxy/data/addonscripts/recorder/recorder.py"))
        assert ns.addons

        ns = script.load_script(tctx.ctx(), "nonexistent")
        assert not ns
Ejemplo n.º 3
0
def test_load_fullname(tdata):
    """
    Test that loading two scripts at locations a/foo.py and b/foo.py works.
    This only succeeds if they get assigned different basenames.

    """
    ns = script.load_script(tdata.path("mitmproxy/data/addonscripts/addon.py"))
    assert ns.addons
    ns2 = script.load_script(
        tdata.path("mitmproxy/data/addonscripts/same_filename/addon.py"))
    assert ns.name != ns2.name
    assert not hasattr(ns2, "addons")
Ejemplo n.º 4
0
async def test_load_script(tdata):
    with taddons.context() as tctx:
        ns = script.load_script(
            tdata.path("mitmproxy/data/addonscripts/recorder/recorder.py"))
        assert ns.addons

        script.load_script("nonexistent")
        await tctx.master.await_log("No such file or directory")

        script.load_script(
            tdata.path("mitmproxy/data/addonscripts/recorder/error.py"))
        await tctx.master.await_log("invalid syntax")
Ejemplo n.º 5
0
def test_load_script():
    ns = script.load_script(
        tutils.test_data.path(
            "mitmproxy/data/addonscripts/recorder/recorder.py"
        )
    )
    assert ns.addons

    with pytest.raises(FileNotFoundError):
        script.load_script(
            "nonexistent"
        )
Ejemplo n.º 6
0
def test_load_script():
    with taddons.context() as tctx:
        ns = script.load_script(
            tctx.ctx(),
            tutils.test_data.path(
                "mitmproxy/data/addonscripts/recorder/recorder.py"
            )
        )
        assert ns.addons

        ns = script.load_script(
            tctx.ctx(),
            "nonexistent"
        )
        assert not ns
Ejemplo n.º 7
0
async def test_script_print_stdout():
    with taddons.context() as tctx:
        with addonmanager.safecall():
            ns = script.load_script(
                tutils.test_data.path("mitmproxy/data/addonscripts/print.py"))
            ns.load(addonmanager.Loader(tctx.master))
        assert await tctx.master.await_log("stdoutprint")
Ejemplo n.º 8
0
def test_load_script():
    ns = script.load_script(
        tutils.test_data.path(
            "mitmproxy/data/addonscripts/recorder.py"
        ), []
    )
    assert ns.start
Ejemplo n.º 9
0
def test_load_script():
    ns = script.load_script(
        tutils.test_data.path(
            "mitmproxy/data/addonscripts/recorder.py"
        ), []
    )
    assert ns.start
Ejemplo n.º 10
0
async def test_script_print_stdout(tdata):
    with taddons.context() as tctx:
        with addonmanager.safecall():
            ns = script.load_script(
                tdata.path("mitmproxy/data/addonscripts/print.py")
            )
            ns.load(addonmanager.Loader(tctx.master))
        assert await tctx.master.await_log("stdoutprint")
Ejemplo n.º 11
0
def test_script_print_stdout():
    with taddons.context() as tctx:
        with mock.patch('mitmproxy.ctx.log.warn') as mock_warn:
            with script.scriptenv("path", []):
                ns = script.load_script(
                    tutils.test_data.path(
                        "mitmproxy/data/addonscripts/print.py"), [])
                ns.load(addonmanager.Loader(tctx.master))
        mock_warn.assert_called_once_with("stdoutprint")
Ejemplo n.º 12
0
def test_load_fullname(tdata):
    """
    Test that loading two scripts at locations a/foo.py and b/foo.py works.
    This only succeeds if they get assigned different basenames.

    """
    ns = script.load_script(
        tdata.path(
            "mitmproxy/data/addonscripts/addon.py"
        )
    )
    assert ns.addons
    ns2 = script.load_script(
        tdata.path(
            "mitmproxy/data/addonscripts/same_filename/addon.py"
        )
    )
    assert ns.name != ns2.name
    assert not hasattr(ns2, "addons")
Ejemplo n.º 13
0
def test_script_print_stdout():
    with taddons.context() as tctx:
        with mock.patch('mitmproxy.ctx.master.tell') as mock_warn:
            with addonmanager.safecall():
                ns = script.load_script(
                    tutils.test_data.path(
                        "mitmproxy/data/addonscripts/print.py"))
                ns.load(addonmanager.Loader(tctx.master))
        mock_warn.assert_called_once_with("log",
                                          log.LogEntry("stdoutprint", "warn"))
Ejemplo n.º 14
0
async def test_load_script(tdata):
    with taddons.context() as tctx:
        ns = script.load_script(
            tdata.path(
                "mitmproxy/data/addonscripts/recorder/recorder.py"
            )
        )
        assert ns.addons

        script.load_script(
            "nonexistent"
        )
        assert await tctx.master.await_log("No such file or directory")

        script.load_script(
            tdata.path(
                "mitmproxy/data/addonscripts/recorder/error.py"
            )
        )
        assert await tctx.master.await_log("invalid syntax")
Ejemplo n.º 15
0
def test_script_print_stdout():
    with taddons.context() as tctx:
        with mock.patch('mitmproxy.ctx.master.tell') as mock_warn:
            with addonmanager.safecall():
                ns = script.load_script(
                    tutils.test_data.path(
                        "mitmproxy/data/addonscripts/print.py"
                    )
                )
                ns.load(addonmanager.Loader(tctx.master))
        mock_warn.assert_called_once_with("log", log.LogEntry("stdoutprint", "warn"))