Example #1
0
    def test_replay(self):
        opts = options.Options()
        conf = config.ProxyConfig(opts)
        fm = master.Master(opts, DummyServer(conf))
        f = tflow.tflow(resp=True)
        f.request.content = None
        with pytest.raises(ReplayException, match="missing"):
            fm.replay_request(f)

        f.request = None
        with pytest.raises(ReplayException, match="request"):
            fm.replay_request(f)

        f.intercepted = True
        with pytest.raises(ReplayException, match="intercepted"):
            fm.replay_request(f)

        f.live = True
        with pytest.raises(ReplayException, match="live"):
            fm.replay_request(f)

        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"
        with mock.patch(
                'mitmproxy.proxy.protocol.http_replay.RequestReplayThread.run'
        ):
            rt = fm.replay_request(f)
            assert rt.f.request.http_version == "HTTP/1.1"
            assert ":authority" not in rt.f.request.headers
Example #2
0
 def test_load_flows(self):
     r = self._treader()
     s = tservers.TestState()
     fm = master.Master(None, DummyServer())
     fm.addons.add(s)
     fm.load_flows(r)
     assert len(s.flows) == 6
Example #3
0
 def test_load_flows_reverse(self):
     r = self._treader()
     s = flow.State()
     conf = ProxyConfig(mode="reverse",
                        upstream_server=("https", ("use-this-domain", 80)))
     fm = flow.FlowMaster(DummyServer(conf), s)
     fm.load_flows(r)
     assert s.flows[0].request.host == "use-this-domain"
Example #4
0
 def test_load_flow_reverse(self):
     s = tservers.TestState()
     opts = options.Options(mode="reverse:https://use-this-domain")
     conf = config.ProxyConfig(opts)
     fm = master.Master(opts, DummyServer(conf))
     fm.addons.add(s)
     f = tflow.tflow(resp=True)
     fm.load_flow(f)
     assert s.flows[0].request.host == "use-this-domain"
Example #5
0
 def test_load_flows_reverse(self):
     r = self._treader()
     s = flow.State()
     opts = options.Options(mode="reverse",
                            upstream_server="https://use-this-domain")
     conf = ProxyConfig(opts)
     fm = flow.FlowMaster(opts, DummyServer(conf), s)
     fm.load_flows(r)
     assert s.flows[0].request.host == "use-this-domain"
Example #6
0
 def test_load_flows_reverse(self):
     r = self._treader()
     s = tservers.TestState()
     opts = options.Options(mode="reverse:https://use-this-domain")
     conf = ProxyConfig(opts)
     fm = master.Master(opts, DummyServer(conf))
     fm.addons.add(s)
     fm.load_flows(r)
     assert s.flows[0].request.host == "use-this-domain"
Example #7
0
    def test_replay(self):
        fm = master.Master(None, DummyServer())
        f = tflow.tflow(resp=True)
        f.request.content = None
        tutils.raises("missing", fm.replay_request, f)

        f.intercepted = True
        tutils.raises("intercepted", fm.replay_request, f)

        f.live = True
        tutils.raises("live", fm.replay_request, f)
Example #8
0
    def test_killall(self):
        srv = DummyServer(None)
        s = state.State()
        fm = master.Master(None, srv)
        fm.addons.add(s)

        f = tutils.tflow()
        f.reply.handle()
        f.intercept(fm)

        s.killall(fm)
        for i in s.view:
            assert "killed" in str(i.error)
Example #9
0
    def test_replay(self):
        fm = master.Master(None, DummyServer())
        f = tflow.tflow(resp=True)
        f.request.content = None
        with pytest.raises(Exception, match="missing"):
            fm.replay_request(f)

        f.intercepted = True
        with pytest.raises(Exception, match="intercepted"):
            fm.replay_request(f)

        f.live = True
        with pytest.raises(Exception, match="live"):
            fm.replay_request(f)
Example #10
0
def run_fuzzer(fuzzer_options):
    """Run Fuzzer"""
    rsp_server_opts = options.Options()
    rsp_server_opts.server = False
    if settings.UPSTREAM_PROXY:
        rsp_server_opts.mode = settings.UPSTREAM_PROXY_CONF
        rsp_server_opts.ssl_insecure = settings.UPSTREAM_PROXY_SSL_INSECURE
    reponse_server = ProxyHandler(rsp_server_opts, fuzzer_options["mode"],
                                  None)
    reponse_server.server = DummyServer()
    fuzzer = Fuzzer(reponse_server, fuzzer_options)
    fuzzer.generate()
    fuzzer.fuzz()
    reponse_server.run()
Example #11
0
    def test_client_playback(self):
        s = flow.State()

        f = tutils.tflow(resp=True)
        pb = [tutils.tflow(resp=True), f]
        fm = flow.FlowMaster(options.Options(),
                             DummyServer(ProxyConfig(options.Options())), s)
        assert not fm.start_client_playback(pb, False)
        fm.client_playback.testing = True

        assert not fm.state.flow_count()
        fm.tick(0)
        assert fm.state.flow_count()

        f.error = Error("error")
        fm.error(f)
Example #12
0
    def test_client_playback(self):
        s = flow.State()

        f = tutils.tflow(resp=True)
        pb = [tutils.tflow(resp=True), f]
        fm = flow.FlowMaster(DummyServer(ProxyConfig()), s)
        assert not fm.start_server_playback(pb, False, [], False, False, None,
                                            False, None, False)
        assert not fm.start_client_playback(pb, False)
        fm.client_playback.testing = True

        q = queue.Queue()
        assert not fm.state.flow_count()
        fm.tick(q, 0)
        assert fm.state.flow_count()

        f.error = Error("error")
        fm.handle_error(f)
Example #13
0
    def test_all(self):
        s = tservers.TestState()
        fm = master.Master(None, DummyServer())
        fm.addons.add(s)
        f = tflow.tflow(req=None)
        fm.clientconnect(f.client_conn)
        f.request = http.HTTPRequest.wrap(mitmproxy.test.tutils.treq())
        fm.request(f)
        assert s.flow_count() == 1

        f.response = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp())
        fm.response(f)
        assert s.flow_count() == 1

        fm.clientdisconnect(f.client_conn)

        f.error = flow.Error("msg")
        fm.error(f)

        fm.shutdown()
Example #14
0
    def test_all(self):
        s = tservers.TestState()
        fm = master.Master(None, DummyServer())
        fm.addons.add(s)
        f = tflow.tflow(req=None)
        fm.addons.handle_lifecycle("clientconnect", f.client_conn)
        f.request = http.HTTPRequest.wrap(mitmproxy.test.tutils.treq())
        fm.addons.handle_lifecycle("request", f)
        assert len(s.flows) == 1

        f.response = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp())
        fm.addons.handle_lifecycle("response", f)
        assert len(s.flows) == 1

        fm.addons.handle_lifecycle("clientdisconnect", f.client_conn)

        f.error = flow.Error("msg")
        fm.addons.handle_lifecycle("error", f)

        fm.shutdown()
Example #15
0
 def test_simple(self):
     d = DummyServer(None)
     d.set_channel(None)
     d.shutdown()
Example #16
0
 def test_simple(self):
     d = DummyServer(None)
     d.start_slave()
     d.shutdown()
Example #17
0
 def test_simple(self):
     d = DummyServer(None)
     d.start_slave()
     d.shutdown()
Example #18
0
 def test_simple(self):
     d = DummyServer(None)
     d.set_channel(None)
     d.shutdown()
Example #19
0
 def test_create_flow(self):
     fm = master.Master(None, DummyServer())
     assert fm.create_request("GET", "http", "example.com", 80, "/")