Exemplo n.º 1
0
 def test_terminate_error(self):
     sc = proxy.ServerConnection(proxy.ProxyConfig(), "http", self.d.IFACE,
                                 self.d.port, "host.com")
     sc.connect()
     sc.connection = mock.Mock()
     sc.connection.flush = mock.Mock(side_effect=tcp.NetLibDisconnect)
     sc.terminate()
Exemplo n.º 2
0
 def test_terminate_error(self):
     sc = proxy.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()
Exemplo n.º 3
0
 def test_terminate_error(self):
     sc = proxy.ServerConnection(proxy.ProxyConfig(), "http", self.d.IFACE,
                                 self.d.port, "host.com")
     sc.connect()
     sc.connection = mock.Mock()
     sc.connection.close = mock.Mock(side_effect=IOError)
     sc.terminate()
Exemplo n.º 4
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 = proxy.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"
Exemplo n.º 5
0
    def test_simple(self):
        sc = proxy.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()
Exemplo n.º 6
0
    def test_simple(self):
        sc = proxy.ServerConnection(proxy.ProxyConfig(), "http", self.d.IFACE,
                                    self.d.port, "host.com")
        sc.connect()
        r = tutils.treq()
        r.path = "/p/200:da"
        sc.send(r)
        assert http.read_response(sc.rfile, r.method, 1000)
        assert self.d.last_log()

        r.content = flow.CONTENT_MISSING
        tutils.raises("incomplete request", sc.send, r)

        sc.terminate()
Exemplo n.º 7
0
 def _cycle(self, m, content):
     req = tutils.treq(content=content)
     l = proxy.Log("connect")
     l.reply = mock.MagicMock()
     m.handle_log(l)
     cc = req.flow.client_conn
     cc.reply = mock.MagicMock()
     m.handle_clientconnect(cc)
     sc = proxy.ServerConnection((req.get_host(), req.get_port()), None)
     sc.reply = mock.MagicMock()
     m.handle_serverconnection(sc)
     m.handle_request(req)
     resp = tutils.tresp(req, content=content)
     f = m.handle_response(resp)
     m.handle_clientdisconnect(cc)
     return f