Ejemplo n.º 1
0
def test_mitm_check_proxy(*args):
    # test setup
    pageset_name = os.path.join(here, "files", "mitm5-linux-firefox-amazon.manifest")

    config = {
        "playback_tool": "mitmproxy",
        "playback_files": [os.path.join(here, "files", pageset_name)],
        "playback_version": "5.1.1",
        "platform": mozinfo.os,
        "run_local": "MOZ_AUTOMATION" not in os.environ,
        "binary": "firefox",
        "app": "firefox",
        "host": "127.0.0.1",
    }

    with tempdir() as obj_path:
        config["obj_path"] = obj_path
        playback = get_playback(config)
        assert playback is not None

        try:
            playback.start()

            url = "https://m.media-amazon.com/images/G/01/csm/showads.v2.js"
            assert get_status_code(url, playback) == 200

            url = "http://mozproxy/checkProxy"
            assert get_status_code(url, playback) == 404
        finally:
            playback.stop()
Ejemplo n.º 2
0
def test_mitm(*args):
    bin_name = "mitmproxy-rel-bin-4.0.4-{platform}.manifest"
    pageset_name = "mitm4-linux-firefox-amazon.manifest"

    config = {
        "playback_tool": "mitmproxy",
        "playback_binary_manifest": bin_name,
        "playback_pageset_manifest": pageset_name,
        "playback_version": '4.0.4',
        "platform": mozinfo.os,
        "playback_recordings": os.path.join(here, "paypal.mp"),
        "run_local": True,
        "binary": "firefox",
        "app": "firefox",
        "host": "example.com",
    }

    with tempdir() as obj_path:
        config["obj_path"] = obj_path
        playback = get_playback(config)
        playback.config['playback_files'] = config['playback_recordings']
    assert playback is not None
    try:
        playback.start()
    finally:
        playback.stop()
Ejemplo n.º 3
0
def test_mitm_check_proxy(*args):
    # test setup
    bin_name = "mitmproxy-rel-bin-4.0.4-{platform}.manifest"
    pageset_name = "mitm4-linux-firefox-amazon.manifest"
    playback_recordings = "amazon.mp"

    config = {
        "playback_tool": "mitmproxy",
        "playback_binary_manifest": bin_name,
        "playback_pageset_manifest": os.path.join(here, "files", pageset_name),
        "playback_version": '4.0.4',
        "platform": mozinfo.os,
        "run_local": "MOZ_AUTOMATION" not in os.environ,
        "binary": "firefox",
        "app": "firefox",
        "host": "127.0.0.1",
    }

    with tempdir() as obj_path:
        config["obj_path"] = obj_path
        playback = get_playback(config)
        playback.config['playback_files'] = [
            os.path.join(obj_path, "testing", "mozproxy", playback_recordings)]
        assert playback is not None

        try:
            playback.start()

            url = "https://m.media-amazon.com/images/G/01/csm/showads.v2.js"
            assert get_status_code(url, playback) == 200

            url = "http://mozproxy/checkProxy"
            assert get_status_code(url, playback) == 404
        finally:
            playback.stop()
Ejemplo n.º 4
0
def test_record_and_replay(*args):
    # test setup
    recording_file = os.path.join(here, "files", "new_recoding.zip")

    # Record part
    config = {
        "playback_tool": "mitmproxy",
        "recording_file": recording_file,
        "playback_version": "5.1.1",
        "platform": mozinfo.os,
        "run_local": "MOZ_AUTOMATION" not in os.environ,
        "binary": "firefox",
        "app": "firefox",
        "host": "127.0.0.1",
        "record": True,
    }

    with tempdir() as obj_path:
        config["obj_path"] = obj_path
        record = get_playback(config)
        assert record is not None

        try:
            record.start()

            url = "https://m.media-amazon.com/images/G/01/csm/showads.v2.js"
            assert get_status_code(url, record) == 200
        finally:
            record.stop()

        # playback part
        config["record"] = False
        config["recording_file"] = None
        config["playback_files"] = [recording_file]
        playback = get_playback(config)
        assert playback is not None
        try:
            playback.start()

            url = "https://m.media-amazon.com/images/G/01/csm/showads.v2.js"
            assert get_status_code(url, playback) == 200
        finally:
            playback.stop()
Ejemplo n.º 5
0
def test_playback_setup_failed(*args):
    class SetupFailed(Exception):
        pass

    def setup(*args, **kw):
        def _s(self):
            raise SetupFailed("Failed")

        return _s

    bin_name = "mitmproxy-rel-bin-4.0.4-{platform}.manifest"
    pageset_name = "mitm4-linux-firefox-amazon.manifest"

    config = {
        "playback_tool": "mitmproxy",
        "playback_binary_manifest": bin_name,
        "playback_pageset_manifest": pageset_name,
        "playback_version": '4.0.4',
        "platform": mozinfo.os,
        "playback_recordings": os.path.join(here, "paypal.mp"),
        "run_local": True,
        "binary": "firefox",
        "app": "firefox",
        "host": "example.com",
    }

    prefix = "mozproxy.backends.mitm.MitmproxyDesktop."

    with tempdir() as obj_path:
        config["obj_path"] = obj_path
        with mock.patch(prefix + "setup", new_callable=setup):
            with mock.patch(prefix + "stop_mitmproxy_playback") as p:
                try:
                    pb = get_playback(config)
                    pb.config['playback_files'] = config['playback_recordings']
                    pb.start()
                except SetupFailed:
                    assert p.call_count == 1
                except Exception:
                    raise
Ejemplo n.º 6
0
def test_mitm_with_retry(*args):
    pageset_name = os.path.join(here, "files", "mitm5-linux-firefox-amazon.manifest")

    config = {
        "playback_tool": "mitmproxy",
        "playback_files": [pageset_name],
        "playback_version": "5.1.1",
        "platform": mozinfo.os,
        "run_local": True,
        "binary": "firefox",
        "app": "firefox",
        "host": "example.com",
    }

    with tempdir() as obj_path:
        config["obj_path"] = obj_path
        playback = get_playback(config)
    assert playback is not None
    try:
        playback.start()
    finally:
        playback.stop()
Ejemplo n.º 7
0
def test_playback_setup_failed(*args):
    class SetupFailed(Exception):
        pass

    def setup(*args, **kw):
        def _s(self):
            raise SetupFailed("Failed")

        return _s

    pageset_name = os.path.join(here, "files",
                                "mitm5-linux-firefox-amazon.manifest")

    config = {
        "playback_tool": "mitmproxy",
        "playback_files": [pageset_name],
        "playback_version": "4.0.4",
        "platform": mozinfo.os,
        "run_local": True,
        "binary": "firefox",
        "app": "firefox",
        "host": "example.com",
    }

    prefix = "mozproxy.backends.mitm.desktop.MitmproxyDesktop."

    with tempdir() as obj_path:
        config["obj_path"] = obj_path
        with mock.patch(prefix + "setup", new_callable=setup):
            with mock.patch(prefix + "stop_mitmproxy_playback") as p:
                try:
                    pb = get_playback(config)
                    pb.start()
                except SetupFailed:
                    assert p.call_count == 1
                except Exception:
                    raise
Ejemplo n.º 8
0
def test_download_file(*args):
    with tempdir() as dest_dir:
        dest = os.path.join(dest_dir, "archive.tar.gz")
        download_file_from_url("http://example.com/archive.tar.gz", dest, extract=True)
        # archive.tar.gz contains hey.txt, if it worked we should see it
        assert os.path.exists(os.path.join(dest_dir, "hey.txt"))