Exemplo n.º 1
0
def test_resume():
    sa = core.Core()
    with taddons.context():
        f = tflow.tflow()
        assert not sa.resume([f])
        f.intercept()
        sa.resume([f])
        assert not f.reply.state == "taken"
Exemplo n.º 2
0
def test_set():
    sa = core.Core()
    with taddons.context(loadcore=False) as tctx:
        assert tctx.master.options.server
        tctx.command(sa.set, "server", "false")
        assert not tctx.master.options.server

        with pytest.raises(exceptions.CommandError):
            tctx.command(sa.set, "nonexistent")
def test_revert():
    sa = core.Core()
    with taddons.context():
        f = tflow.tflow()
        f.backup()
        f.request.content = b"bar"
        assert f.modified()
        sa.revert([f])
        assert not f.modified()
def start_proxy(port):
    options = Options(listen_port=port, )
    config = ProxyConfig(options=options, )
    server = ProxyServer(config)
    print('Intercepting Proxy listening on {0}'.format(port))
    m = TestInterceptor(options, server)
    m.addons.add(core.Core())
    m.addons.add(Counter())
    m.run()
Exemplo n.º 5
0
def test_client_certs(tdata):
    sa = core.Core()
    with taddons.context() as tctx:
        # Folders should work.
        tctx.configure(sa, client_certs = tdata.path("mitmproxy/data/clientcert"))
        # Files, too.
        tctx.configure(sa, client_certs = tdata.path("mitmproxy/data/clientcert/client.pem"))

        with pytest.raises(exceptions.OptionsError, match="certificate path does not exist"):
            tctx.configure(sa, client_certs = "invalid")
Exemplo n.º 6
0
    def setup_class(cls):
        cls.server = pathod.test.Daemon(ssl=cls.ssl, ssloptions=cls.ssloptions)
        cls.server2 = pathod.test.Daemon(ssl=cls.ssl,
                                         ssloptions=cls.ssloptions)

        cls.options = cls.get_options()
        tmaster = cls.masterclass(cls.options)
        tmaster.addons.add(core.Core())
        cls.proxy = ProxyThread(tmaster)
        cls.proxy.start()
Exemplo n.º 7
0
    def __init__(self, *addons, options=None, loadcore=True):
        options = options or mitmproxy.options.Options()
        self.master = RecordingMaster(options)
        self.options = self.master.options

        if loadcore:
            self.master.addons.add(core.Core())

        for a in addons:
            self.master.addons.add(a)
def test_set():
    sa = core.Core()
    with taddons.context() as tctx:
        tctx.master.addons.add(sa)

        assert not tctx.master.options.anticomp
        tctx.command(sa.set, "anticomp")
        assert tctx.master.options.anticomp

        with pytest.raises(exceptions.CommandError):
            tctx.command(sa.set, "nonexistent")
Exemplo n.º 9
0
def test_validation_simple():
    sa = core.Core()
    with taddons.context() as tctx:
        with pytest.raises(
                exceptions.OptionsError,
                match="requires the upstream_cert option to be enabled"):
            tctx.configure(sa,
                           add_upstream_certs_to_client_chain=True,
                           upstream_cert=False)
        with pytest.raises(exceptions.OptionsError, match="Invalid mode"):
            tctx.configure(sa, mode="Flibble")
Exemplo n.º 10
0
    def setup_class(cls):
        # We need to initialize the chain first so that the normal server gets a correct config.
        cls.chain = []
        for _ in range(cls.n):
            opts = cls.get_options()
            tmaster = cls.masterclass(opts)
            tmaster.addons.add(core.Core())
            proxy = ProxyThread(tmaster)
            proxy.start()
            cls.chain.insert(0, proxy)

        super().setup_class()
Exemplo n.º 11
0
def test_mark():
    sa = core.Core()
    with taddons.context():
        f = tflow.tflow()
        assert not f.marked
        sa.mark([f], True)
        assert f.marked

        sa.mark_toggle([f])
        assert not f.marked
        sa.mark_toggle([f])
        assert f.marked
Exemplo n.º 12
0
def test_mark():
    sa = core.Core()
    with taddons.context(loadcore=False):
        f = tflow.tflow()
        assert not f.marked
        sa.mark([f], ":default:")
        assert f.marked

        with pytest.raises(exceptions.CommandError):
            sa.mark([f], "invalid")

        sa.mark_toggle([f])
        assert not f.marked
        sa.mark_toggle([f])
        assert f.marked
Exemplo n.º 13
0
def test_validation_simple():
    sa = core.Core()
    with taddons.context() as tctx:
        with pytest.raises(exceptions.OptionsError):
            tctx.configure(sa, body_size_limit="invalid")
        tctx.configure(sa, body_size_limit="1m")

        with pytest.raises(exceptions.OptionsError,
                           match="mutually exclusive"):
            tctx.configure(sa,
                           add_upstream_certs_to_client_chain=True,
                           upstream_cert=False)
        with pytest.raises(
                exceptions.OptionsError,
                match="requires certificate verification to be disabled"):
            tctx.configure(sa,
                           add_upstream_certs_to_client_chain=True,
                           ssl_insecure=False)
        with pytest.raises(exceptions.OptionsError, match="Invalid mode"):
            tctx.configure(sa, mode="Flibble")
Exemplo n.º 14
0
def default_addons():
    return [
        core.Core(),
        anticache.AntiCache(),
        anticomp.AntiComp(),
        check_ca.CheckCA(),
        #clientplayback.ClientPlayback(),
        disable_h2c.DisableH2C(),
        #onboarding.Onboarding(),
        #proxyauth.ProxyAuth(),
        #replace.Replace(),
        #script.ScriptLoader(),
        #serverplayback.ServerPlayback(),
        #setheaders.SetHeaders(),
        #stickyauth.StickyAuth(),
        #stickycookie.StickyCookie(),
        #streambodies.StreamBodies(),
        #readfile.ReadFile(),
        #upstream_auth.UpstreamAuth(),
    ]
Exemplo n.º 15
0
def default_addons():
    return [
        core.Core(),
        core_option_validation.CoreOptionValidation(),
        allowremote.AllowRemote(),
        anticache.AntiCache(),
        anticomp.AntiComp(),
        check_ca.CheckCA(),
        cut.Cut(),
        disable_h2c.DisableH2C(),
        onboarding.Onboarding(),
        proxyauth.ProxyAuth(),
        replace.Replace(),
        script.ScriptLoader(),
        serverplayback.ServerPlayback(),
        setheaders.SetHeaders(),
        stickyauth.StickyAuth(),
        stickycookie.StickyCookie(),
        streambodies.StreamBodies(),
        save.Save(),
        upstream_auth.UpstreamAuth(),
    ]
Exemplo n.º 16
0
def test_encoding():
    sa = core.Core()
    with taddons.context(loadcore=False):
        f = tflow.tflow()
        assert sa.encode_options()
        sa.encode([f], "request", "deflate")
        assert f.request.headers["content-encoding"] == "deflate"

        sa.encode([f], "request", "br")
        assert f.request.headers["content-encoding"] == "deflate"

        sa.decode([f], "request")
        assert "content-encoding" not in f.request.headers

        sa.encode([f], "request", "br")
        assert f.request.headers["content-encoding"] == "br"

        sa.encode_toggle([f], "request")
        assert "content-encoding" not in f.request.headers
        sa.encode_toggle([f], "request")
        assert f.request.headers["content-encoding"] == "deflate"
        sa.encode_toggle([f], "request")
        assert "content-encoding" not in f.request.headers
Exemplo n.º 17
0
def test_flow_set():
    sa = core.Core()
    with taddons.context():
        f = tflow.tflow(resp=True)
        assert sa.flow_set_options()

        with pytest.raises(exceptions.CommandError):
            sa.flow_set([f], "flibble", "post")

        assert f.request.method != "post"
        sa.flow_set([f], "method", "post")
        assert f.request.method == "POST"

        assert f.request.host != "testhost"
        sa.flow_set([f], "host", "testhost")
        assert f.request.host == "testhost"

        assert f.request.path != "/test/path"
        sa.flow_set([f], "path", "/test/path")
        assert f.request.path == "/test/path"

        assert f.request.url != "http://foo.com/bar"
        sa.flow_set([f], "url", "http://foo.com/bar")
        assert f.request.url == "http://foo.com/bar"
        with pytest.raises(exceptions.CommandError):
            sa.flow_set([f], "url", "oink")

        assert f.response.status_code != 404
        sa.flow_set([f], "status_code", "404")
        assert f.response.status_code == 404
        assert f.response.reason == "Not Found"
        with pytest.raises(exceptions.CommandError):
            sa.flow_set([f], "status_code", "oink")

        assert f.response.reason != "foo"
        sa.flow_set([f], "reason", "foo")
        assert f.response.reason == "foo"
Exemplo n.º 18
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(),
    ]
Exemplo n.º 19
0
 def setup_class(cls):
     cls.options = cls.get_options()
     tmaster = tservers.TestMaster(cls.options)
     tmaster.addons.add(core.Core())
     cls.proxy = tservers.ProxyThread(tmaster)
     cls.proxy.start()
Exemplo n.º 20
0
def test_validation_modes(m):
    sa = core.Core()
    with taddons.context() as tctx:
        tctx.configure(sa, mode = "reverse:http://localhost")
        with pytest.raises(Exception, match="Invalid server specification"):
            tctx.configure(sa, mode = "reverse:")
Exemplo n.º 21
0
def test_validation_no_transparent():
    sa = core.Core()
    with taddons.context() as tctx:
        with pytest.raises(Exception, match="Transparent mode not supported"):
            tctx.configure(sa, mode = "transparent")
Exemplo n.º 22
0
 def __init__(self, options, server):
     Master.__init__(self, options)
     self.addons.add(core.Core())
     self.addons.add(ZjsnHelper())
     self.server = server