コード例 #1
0
    def test_script(self):
        s = flow.State()
        fm = flow.FlowMaster(None, s)
        assert not fm.load_script(tutils.test_data.path("scripts/all.py"))
        req = tutils.treq()
        fm.handle_clientconnect(req.flow.client_conn)
        assert fm.scripts[0].ns["log"][-1] == "clientconnect"
        sc = ServerConnection((req.get_host(), req.get_port()), None)
        sc.reply = controller.DummyReply()
        fm.handle_serverconnection(sc)
        assert fm.scripts[0].ns["log"][-1] == "serverconnect"
        f = fm.handle_request(req)
        assert fm.scripts[0].ns["log"][-1] == "request"
        resp = tutils.tresp(req)
        fm.handle_response(resp)
        assert fm.scripts[0].ns["log"][-1] == "response"
        #load second script
        assert not fm.load_script(tutils.test_data.path("scripts/all.py"))
        assert len(fm.scripts) == 2
        fm.handle_clientdisconnect(sc)
        assert fm.scripts[0].ns["log"][-1] == "clientdisconnect"
        assert fm.scripts[1].ns["log"][-1] == "clientdisconnect"


        #unload first script
        fm.unload_scripts()
        assert len(fm.scripts) == 0

        assert not fm.load_script(tutils.test_data.path("scripts/all.py"))
        err = tutils.terr()
        err.reply = controller.DummyReply()
        fm.handle_error(err)
        assert fm.scripts[0].ns["log"][-1] == "error"
コード例 #2
0
    def test_script(self):
        s = flow.State()
        fm = flow.FlowMaster(None, s)
        assert not fm.load_script(tutils.test_data.path("scripts/all.py"))
        req = tutils.treq()
        fm.handle_clientconnect(req.flow.client_conn)
        assert fm.scripts[0].ns["log"][-1] == "clientconnect"
        sc = ServerConnection((req.get_host(), req.get_port()), None)
        sc.reply = controller.DummyReply()
        fm.handle_serverconnection(sc)
        assert fm.scripts[0].ns["log"][-1] == "serverconnect"
        f = fm.handle_request(req)
        assert fm.scripts[0].ns["log"][-1] == "request"
        resp = tutils.tresp(req)
        fm.handle_response(resp)
        assert fm.scripts[0].ns["log"][-1] == "response"
        #load second script
        assert not fm.load_script(tutils.test_data.path("scripts/all.py"))
        assert len(fm.scripts) == 2
        fm.handle_clientdisconnect(sc)
        assert fm.scripts[0].ns["log"][-1] == "clientdisconnect"
        assert fm.scripts[1].ns["log"][-1] == "clientdisconnect"

        #unload first script
        fm.unload_scripts()
        assert len(fm.scripts) == 0

        assert not fm.load_script(tutils.test_data.path("scripts/all.py"))
        err = tutils.terr()
        err.reply = controller.DummyReply()
        fm.handle_error(err)
        assert fm.scripts[0].ns["log"][-1] == "error"
コード例 #3
0
def tserver_conn():
    c = ServerConnection._from_state(
        dict(address=dict(address=("address", 22), use_ipv6=True),
             source_address=dict(address=("address", 22), use_ipv6=True),
             cert=None))
    c.reply = controller.DummyReply()
    return c
コード例 #4
0
ファイル: tutils.py プロジェクト: Akdeniz/mitmproxy
def tserver_conn():
    c = ServerConnection._from_state(dict(
        address=dict(address=("address", 22), use_ipv6=True),
        source_address=dict(address=("address", 22), use_ipv6=True),
        cert=None
    ))
    c.reply = controller.DummyReply()
    return c
コード例 #5
0
ファイル: test_proxy.py プロジェクト: ch0psticks/mitmproxy
 def test_terminate_error(self):
     sc = ServerConnection((self.d.IFACE, self.d.port), None)
     sc.connect()
     sc.connection = mock.Mock()
     sc.connection.recv = mock.Mock(return_value=False)
     sc.connection.flush = mock.Mock(side_effect=tcp.NetLibDisconnect)
     sc.finish()
コード例 #6
0
ファイル: test_proxy.py プロジェクト: ch0psticks/mitmproxy
    def test_simple(self):
        sc = ServerConnection((self.d.IFACE, self.d.port), None)
        sc.connect()
        r = tutils.treq()
        r.flow.server_conn = sc
        r.path = "/p/200:da"
        sc.send(r._assemble())
        assert http.read_response(sc.rfile, r.method, 1000)
        assert self.d.last_log()

        sc.finish()
コード例 #7
0
    def test_simple(self):
        sc = ServerConnection((self.d.IFACE, self.d.port))
        sc.connect()
        f = tutils.tflow()
        f.server_conn = sc
        f.request.path = "/p/200:da"
        sc.send(f.request.assemble())
        assert http.read_response(sc.rfile, f.request.method, 1000)
        assert self.d.last_log()

        sc.finish()
コード例 #8
0
def tserver_conn():
    """
    @return: libmproxy.proxy.connection.ServerConnection
    """
    c = ServerConnection.from_state(
        dict(address=dict(address=("address", 22), use_ipv6=True),
             state=[],
             source_address=dict(address=("address", 22), use_ipv6=True),
             cert=None))
    c.reply = controller.DummyReply()
    return c
コード例 #9
0
ファイル: tutils.py プロジェクト: 0xr0ot/mitmproxy
def tserver_conn():
    """
    @return: libmproxy.proxy.connection.ServerConnection
    """
    c = ServerConnection.from_state(dict(
        address=dict(address=("address", 22), use_ipv6=True),
        state=[],
        source_address=dict(address=("address", 22), use_ipv6=True),
        cert=None
    ))
    c.reply = controller.DummyReply()
    return c
コード例 #10
0
ファイル: test_proxy.py プロジェクト: nanonyme/mitmproxy
 def test_terminate_error(self):
     sc = ServerConnection((self.d.IFACE, self.d.port), None)
     sc.connect()
     sc.connection = mock.Mock()
     sc.connection.recv = mock.Mock(return_value=False)
     sc.connection.flush = mock.Mock(side_effect=tcp.NetLibDisconnect)
     sc.finish()
コード例 #11
0
ファイル: test_proxy.py プロジェクト: nanonyme/mitmproxy
    def test_simple(self):
        sc = ServerConnection((self.d.IFACE, self.d.port), None)
        sc.connect()
        r = tutils.treq()
        r.flow.server_conn = sc
        r.path = "/p/200:da"
        sc.send(r._assemble())
        assert http.read_response(sc.rfile, r.method, 1000)
        assert self.d.last_log()

        sc.finish()
コード例 #12
0
ファイル: test_proxy.py プロジェクト: 2mia/mitmproxy
    def test_simple(self):
        sc = ServerConnection((self.d.IFACE, self.d.port))
        sc.connect()
        f = tutils.tflow()
        f.server_conn = sc
        f.request.path = "/p/200:da"
        sc.send(f.request.assemble())
        assert http.read_response(sc.rfile, f.request.method, 1000)
        assert self.d.last_log()

        sc.finish()
コード例 #13
0
ファイル: test_proxy.py プロジェクト: zhanglei/mitmproxy
    def test_simple(self):
        sc = ServerConnection((self.d.IFACE, self.d.port))
        sc.connect()
        f = tutils.tflow()
        f.server_conn = sc
        f.request.path = "/p/200:da"

        # use this protocol just to assemble - not for actual sending
        protocol = http.http1.HTTP1Protocol(rfile=sc.rfile)
        sc.send(protocol.assemble(f.request))

        protocol = http.http1.HTTP1Protocol(rfile=sc.rfile)
        assert protocol.read_response(f.request.method, 1000)
        assert self.d.last_log()

        sc.finish()
コード例 #14
0
ファイル: tutils.py プロジェクト: Akdeniz/mitmproxy
def tresp(req=None, content="message"):
    if not req:
        req = treq()
    f = req.flow

    headers = flow.ODictCaseless()
    headers["header_response"] = ["svalue"]
    cert = certutils.SSLCert.from_der(file(test_data.path("data/dercert"), "rb").read())
    f.server_conn = ServerConnection._from_state(dict(
        address=dict(address=("address", 22), use_ipv6=True),
        source_address=None,
        cert=cert.to_pem()))
    f.response = http.HTTPResponse((1, 1), 200, "OK", headers, content, time(), time())
    f.response.reply = controller.DummyReply()
    return f.response
コード例 #15
0
def tresp(req=None, content="message"):
    if not req:
        req = treq()
    f = req.flow

    headers = flow.ODictCaseless()
    headers["header_response"] = ["svalue"]
    cert = certutils.SSLCert.from_der(
        file(test_data.path("data/dercert"), "rb").read())
    f.server_conn = ServerConnection._from_state(
        dict(address=dict(address=("address", 22), use_ipv6=True),
             source_address=None,
             cert=cert.to_pem()))
    f.response = http.HTTPResponse((1, 1), 200, "OK", headers, content, time(),
                                   time())
    f.response.reply = controller.DummyReply()
    return f.response
コード例 #16
0
ファイル: test_proxy.py プロジェクト: nask0/mitmproxy
    def test_simple(self):
        sc = ServerConnection((self.d.IFACE, self.d.port))
        sc.connect()
        f = tutils.tflow()
        f.server_conn = sc
        f.request.path = "/p/200:da"

        # use this protocol just to assemble - not for actual sending
        protocol = http.http1.HTTP1Protocol(rfile=sc.rfile)
        sc.send(protocol.assemble(f.request))

        protocol = http.http1.HTTP1Protocol(rfile=sc.rfile)
        assert protocol.read_response(f.request.method, 1000)
        assert self.d.last_log()

        sc.finish()