2011-03-06 03:02:28 +00:00
|
|
|
import Queue
|
2011-02-16 01:33:04 +00:00
|
|
|
from cStringIO import StringIO
|
2011-01-30 22:48:53 +00:00
|
|
|
from libmproxy import console, proxy, filt, flow
|
2011-03-05 02:58:48 +00:00
|
|
|
import tutils
|
2011-01-30 22:48:53 +00:00
|
|
|
import libpry
|
|
|
|
|
2011-02-20 19:47:19 +00:00
|
|
|
|
2011-02-23 21:33:39 +00:00
|
|
|
class uStickyCookieState(libpry.AutoTree):
|
2011-02-24 02:15:51 +00:00
|
|
|
def _response(self, cookie, host):
|
|
|
|
s = flow.StickyCookieState(filt.parse(".*"))
|
2011-03-05 02:58:48 +00:00
|
|
|
f = tutils.tflow_full()
|
2011-02-24 02:15:51 +00:00
|
|
|
f.request.host = host
|
|
|
|
f.response.headers["Set-Cookie"] = [cookie]
|
|
|
|
s.handle_response(f)
|
|
|
|
return s, f
|
|
|
|
|
|
|
|
def test_handle_response(self):
|
|
|
|
c = "SSID=mooo, FOO=bar; Domain=.google.com; Path=/; "\
|
|
|
|
"Expires=Wed, 13-Jan-2021 22:23:01 GMT; Secure; "
|
|
|
|
|
|
|
|
s, f = self._response(c, "host")
|
|
|
|
assert not s.jar.keys()
|
|
|
|
|
|
|
|
s, f = self._response(c, "www.google.com")
|
|
|
|
assert s.jar.keys()
|
|
|
|
|
|
|
|
s, f = self._response("SSID=mooo", "www.google.com")
|
|
|
|
assert s.jar.keys()[0] == ('www.google.com', 80, '/')
|
|
|
|
|
|
|
|
def test_handle_request(self):
|
|
|
|
s, f = self._response("SSID=mooo", "www.google.com")
|
|
|
|
assert "cookie" not in f.request.headers
|
|
|
|
s.handle_request(f)
|
|
|
|
assert "cookie" in f.request.headers
|
|
|
|
|
2011-02-23 21:33:39 +00:00
|
|
|
|
2011-03-04 00:08:43 +00:00
|
|
|
class uClientPlaybackState(libpry.AutoTree):
|
|
|
|
def test_tick(self):
|
2011-03-05 02:58:48 +00:00
|
|
|
first = tutils.tflow()
|
2011-03-04 00:08:43 +00:00
|
|
|
s = flow.State()
|
|
|
|
fm = flow.FlowMaster(None, s)
|
2011-03-06 03:54:49 +00:00
|
|
|
fm.start_client_playback([first, tutils.tflow()], True)
|
|
|
|
c = fm.client_playback
|
|
|
|
|
|
|
|
assert not c.done()
|
2011-03-06 03:11:45 +00:00
|
|
|
assert not s.flow_count()
|
2011-03-04 00:08:43 +00:00
|
|
|
assert c.count() == 2
|
|
|
|
c.tick(fm, testing=True)
|
2011-03-06 03:11:45 +00:00
|
|
|
assert s.flow_count()
|
2011-03-04 00:08:43 +00:00
|
|
|
assert c.count() == 1
|
|
|
|
|
|
|
|
c.tick(fm, testing=True)
|
|
|
|
assert c.count() == 1
|
|
|
|
|
2011-03-05 22:21:31 +00:00
|
|
|
c.clear(c.current)
|
2011-03-04 00:08:43 +00:00
|
|
|
c.tick(fm, testing=True)
|
|
|
|
assert c.count() == 0
|
2011-03-06 03:54:49 +00:00
|
|
|
c.clear(c.current)
|
|
|
|
assert c.done()
|
2011-03-04 00:08:43 +00:00
|
|
|
|
2011-03-06 03:54:49 +00:00
|
|
|
q = Queue.Queue()
|
|
|
|
fm.state.clear()
|
|
|
|
fm.tick(q)
|
2011-03-04 00:08:43 +00:00
|
|
|
|
2011-02-23 21:33:39 +00:00
|
|
|
|
2011-02-20 19:47:19 +00:00
|
|
|
class uServerPlaybackState(libpry.AutoTree):
|
|
|
|
def test_hash(self):
|
2011-03-06 04:08:56 +00:00
|
|
|
s = flow.ServerPlaybackState(None, [], False)
|
2011-03-05 02:58:48 +00:00
|
|
|
r = tutils.tflow()
|
|
|
|
r2 = tutils.tflow()
|
2011-02-20 19:47:19 +00:00
|
|
|
|
|
|
|
assert s._hash(r)
|
|
|
|
assert s._hash(r) == s._hash(r2)
|
|
|
|
r.request.headers["foo"] = ["bar"]
|
|
|
|
assert s._hash(r) == s._hash(r2)
|
|
|
|
r.request.path = "voing"
|
|
|
|
assert s._hash(r) != s._hash(r2)
|
|
|
|
|
2011-02-22 21:54:51 +00:00
|
|
|
def test_headers(self):
|
2011-03-06 04:08:56 +00:00
|
|
|
s = flow.ServerPlaybackState(["foo"], [], False)
|
2011-03-05 02:58:48 +00:00
|
|
|
r = tutils.tflow_full()
|
2011-02-22 21:54:51 +00:00
|
|
|
r.request.headers["foo"] = ["bar"]
|
2011-03-05 02:58:48 +00:00
|
|
|
r2 = tutils.tflow_full()
|
2011-02-22 21:54:51 +00:00
|
|
|
assert not s._hash(r) == s._hash(r2)
|
|
|
|
r2.request.headers["foo"] = ["bar"]
|
|
|
|
assert s._hash(r) == s._hash(r2)
|
|
|
|
r2.request.headers["oink"] = ["bar"]
|
|
|
|
assert s._hash(r) == s._hash(r2)
|
|
|
|
|
2011-03-05 02:58:48 +00:00
|
|
|
r = tutils.tflow_full()
|
|
|
|
r2 = tutils.tflow_full()
|
2011-02-22 21:54:51 +00:00
|
|
|
assert s._hash(r) == s._hash(r2)
|
|
|
|
|
2011-02-20 19:47:19 +00:00
|
|
|
def test_load(self):
|
2011-03-05 02:58:48 +00:00
|
|
|
r = tutils.tflow_full()
|
2011-02-20 19:47:19 +00:00
|
|
|
r.request.headers["key"] = ["one"]
|
|
|
|
|
2011-03-05 02:58:48 +00:00
|
|
|
r2 = tutils.tflow_full()
|
2011-02-20 19:47:19 +00:00
|
|
|
r2.request.headers["key"] = ["two"]
|
|
|
|
|
2011-03-06 04:08:56 +00:00
|
|
|
s = flow.ServerPlaybackState(None, [r, r2], False)
|
2011-02-20 22:40:49 +00:00
|
|
|
assert s.count() == 2
|
2011-02-20 19:47:19 +00:00
|
|
|
assert len(s.fmap.keys()) == 1
|
|
|
|
|
|
|
|
n = s.next_flow(r)
|
|
|
|
assert n.request.headers["key"] == ["one"]
|
2011-02-20 22:40:49 +00:00
|
|
|
assert s.count() == 1
|
2011-02-20 19:47:19 +00:00
|
|
|
|
|
|
|
n = s.next_flow(r)
|
|
|
|
assert n.request.headers["key"] == ["two"]
|
2011-02-20 22:40:49 +00:00
|
|
|
assert s.count() == 0
|
2011-02-20 19:47:19 +00:00
|
|
|
|
|
|
|
assert not s.next_flow(r)
|
|
|
|
|
|
|
|
|
2011-01-30 22:48:53 +00:00
|
|
|
class uFlow(libpry.AutoTree):
|
2011-01-31 00:26:56 +00:00
|
|
|
def test_run_script(self):
|
2011-03-05 02:58:48 +00:00
|
|
|
f = tutils.tflow()
|
|
|
|
f.response = tutils.tresp()
|
2011-01-31 00:26:56 +00:00
|
|
|
f.request = f.response.request
|
2011-02-17 23:40:45 +00:00
|
|
|
se = f.run_script("scripts/a")
|
2011-02-01 21:08:24 +00:00
|
|
|
assert "DEBUG" == se.strip()
|
2011-01-31 00:26:56 +00:00
|
|
|
assert f.request.host == "TESTOK"
|
|
|
|
|
|
|
|
def test_run_script_err(self):
|
2011-03-05 02:58:48 +00:00
|
|
|
f = tutils.tflow()
|
|
|
|
f.response = tutils.tresp()
|
2011-01-31 00:26:56 +00:00
|
|
|
f.request = f.response.request
|
|
|
|
libpry.raises("returned error", f.run_script,"scripts/err_return")
|
|
|
|
libpry.raises("invalid response", f.run_script,"scripts/err_data")
|
|
|
|
libpry.raises("no such file", f.run_script,"nonexistent")
|
|
|
|
libpry.raises("permission denied", f.run_script,"scripts/nonexecutable")
|
|
|
|
|
2011-01-30 22:48:53 +00:00
|
|
|
def test_match(self):
|
2011-03-05 02:58:48 +00:00
|
|
|
f = tutils.tflow()
|
|
|
|
f.response = tutils.tresp()
|
2011-01-30 22:48:53 +00:00
|
|
|
f.request = f.response.request
|
|
|
|
assert not f.match(filt.parse("~b test"))
|
2011-02-19 04:21:08 +00:00
|
|
|
assert not f.match(None)
|
2011-01-30 22:48:53 +00:00
|
|
|
|
|
|
|
def test_backup(self):
|
2011-03-05 02:58:48 +00:00
|
|
|
f = tutils.tflow()
|
|
|
|
f.response = tutils.tresp()
|
2011-02-05 21:28:43 +00:00
|
|
|
f.request = f.response.request
|
|
|
|
f.request.content = "foo"
|
2011-02-01 22:44:28 +00:00
|
|
|
assert not f.modified()
|
2011-01-30 22:48:53 +00:00
|
|
|
f.backup()
|
2011-02-05 21:28:43 +00:00
|
|
|
f.request.content = "bar"
|
2011-02-01 22:44:28 +00:00
|
|
|
assert f.modified()
|
2011-01-30 22:48:53 +00:00
|
|
|
f.revert()
|
2011-02-05 21:28:43 +00:00
|
|
|
assert f.request.content == "foo"
|
2011-01-30 22:48:53 +00:00
|
|
|
|
|
|
|
def test_getset_state(self):
|
2011-03-05 02:58:48 +00:00
|
|
|
f = tutils.tflow()
|
|
|
|
f.response = tutils.tresp(f.request)
|
2011-02-19 04:21:08 +00:00
|
|
|
state = f.get_state()
|
|
|
|
assert f == flow.Flow.from_state(state)
|
|
|
|
|
|
|
|
f.response = None
|
2011-02-20 00:29:41 +00:00
|
|
|
f.error = proxy.Error(f.request, "error")
|
2011-01-30 22:48:53 +00:00
|
|
|
state = f.get_state()
|
|
|
|
assert f == flow.Flow.from_state(state)
|
|
|
|
|
2011-03-05 02:58:48 +00:00
|
|
|
f2 = tutils.tflow()
|
2011-02-20 00:29:41 +00:00
|
|
|
f2.error = proxy.Error(f.request, "e2")
|
2011-02-19 20:55:42 +00:00
|
|
|
assert not f == f2
|
|
|
|
f.load_state(f2.get_state())
|
|
|
|
assert f == f2
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-30 22:48:53 +00:00
|
|
|
def test_kill(self):
|
2011-03-05 02:58:48 +00:00
|
|
|
f = tutils.tflow()
|
|
|
|
f.request = tutils.treq()
|
2011-01-30 22:48:53 +00:00
|
|
|
f.intercept()
|
|
|
|
assert not f.request.acked
|
|
|
|
f.kill()
|
|
|
|
assert f.request.acked
|
|
|
|
f.intercept()
|
2011-03-05 02:58:48 +00:00
|
|
|
f.response = tutils.tresp()
|
2011-01-30 22:48:53 +00:00
|
|
|
f.request = f.response.request
|
|
|
|
f.request.ack()
|
|
|
|
assert not f.response.acked
|
|
|
|
f.kill()
|
|
|
|
assert f.response.acked
|
|
|
|
|
|
|
|
def test_accept_intercept(self):
|
2011-03-05 02:58:48 +00:00
|
|
|
f = tutils.tflow()
|
|
|
|
f.request = tutils.treq()
|
2011-01-30 22:48:53 +00:00
|
|
|
f.intercept()
|
|
|
|
assert not f.request.acked
|
|
|
|
f.accept_intercept()
|
|
|
|
assert f.request.acked
|
2011-03-05 02:58:48 +00:00
|
|
|
f.response = tutils.tresp()
|
2011-01-30 22:48:53 +00:00
|
|
|
f.request = f.response.request
|
|
|
|
f.intercept()
|
|
|
|
f.request.ack()
|
|
|
|
assert not f.response.acked
|
|
|
|
f.accept_intercept()
|
|
|
|
assert f.response.acked
|
|
|
|
|
|
|
|
def test_serialization(self):
|
|
|
|
f = flow.Flow(None)
|
2011-03-05 02:58:48 +00:00
|
|
|
f.request = tutils.treq()
|
2011-01-30 22:48:53 +00:00
|
|
|
|
|
|
|
|
2011-02-02 23:16:03 +00:00
|
|
|
class uState(libpry.AutoTree):
|
|
|
|
def test_backup(self):
|
2011-02-19 04:00:24 +00:00
|
|
|
bc = proxy.ClientConnect(("address", 22))
|
2011-02-02 23:16:03 +00:00
|
|
|
c = flow.State()
|
2011-03-05 02:58:48 +00:00
|
|
|
req = tutils.treq()
|
2011-02-19 04:00:24 +00:00
|
|
|
f = c.add_request(req)
|
2011-02-02 23:16:03 +00:00
|
|
|
|
|
|
|
f.backup()
|
|
|
|
c.revert(f)
|
|
|
|
|
|
|
|
def test_flow(self):
|
|
|
|
"""
|
|
|
|
normal flow:
|
|
|
|
|
|
|
|
connect -> request -> response
|
|
|
|
"""
|
2011-02-19 04:00:24 +00:00
|
|
|
bc = proxy.ClientConnect(("address", 22))
|
2011-02-02 23:16:03 +00:00
|
|
|
c = flow.State()
|
2011-02-19 04:00:24 +00:00
|
|
|
c.clientconnect(bc)
|
|
|
|
assert len(c.client_connections) == 1
|
2011-02-02 23:16:03 +00:00
|
|
|
|
2011-03-05 02:58:48 +00:00
|
|
|
req = tutils.treq(bc)
|
2011-02-19 04:00:24 +00:00
|
|
|
f = c.add_request(req)
|
|
|
|
assert f
|
2011-03-06 03:11:45 +00:00
|
|
|
assert c.flow_count() == 1
|
2011-02-19 04:00:24 +00:00
|
|
|
assert c.flow_map.get(req)
|
2011-03-06 03:11:45 +00:00
|
|
|
assert c.active_flow_count() == 1
|
2011-02-02 23:16:03 +00:00
|
|
|
|
2011-03-05 02:58:48 +00:00
|
|
|
newreq = tutils.treq()
|
2011-02-16 21:18:38 +00:00
|
|
|
assert c.add_request(newreq)
|
2011-02-19 04:00:24 +00:00
|
|
|
assert c.flow_map.get(newreq)
|
2011-03-06 03:11:45 +00:00
|
|
|
assert c.active_flow_count() == 2
|
2011-02-02 23:16:03 +00:00
|
|
|
|
2011-03-05 02:58:48 +00:00
|
|
|
resp = tutils.tresp(req)
|
2011-02-02 23:16:03 +00:00
|
|
|
assert c.add_response(resp)
|
2011-03-06 03:11:45 +00:00
|
|
|
assert c.flow_count() == 2
|
2011-02-19 04:00:24 +00:00
|
|
|
assert c.flow_map.get(resp.request)
|
2011-03-06 03:11:45 +00:00
|
|
|
assert c.active_flow_count() == 1
|
2011-02-02 23:16:03 +00:00
|
|
|
|
2011-03-06 03:11:45 +00:00
|
|
|
unseen_resp = tutils.tresp()
|
|
|
|
assert not c.add_response(unseen_resp)
|
|
|
|
assert not c.flow_map.get(unseen_resp.request)
|
|
|
|
assert c.active_flow_count() == 1
|
|
|
|
|
|
|
|
resp = tutils.tresp(newreq)
|
|
|
|
assert c.add_response(resp)
|
|
|
|
assert c.active_flow_count() == 0
|
2011-02-19 04:00:24 +00:00
|
|
|
|
|
|
|
dc = proxy.ClientDisconnect(bc)
|
|
|
|
c.clientdisconnect(dc)
|
|
|
|
assert not c.client_connections
|
2011-02-02 23:16:03 +00:00
|
|
|
|
|
|
|
def test_err(self):
|
2011-02-19 04:00:24 +00:00
|
|
|
bc = proxy.ClientConnect(("address", 22))
|
2011-02-02 23:16:03 +00:00
|
|
|
c = flow.State()
|
2011-03-05 02:58:48 +00:00
|
|
|
req = tutils.treq()
|
2011-02-19 04:00:24 +00:00
|
|
|
f = c.add_request(req)
|
2011-02-20 00:29:41 +00:00
|
|
|
e = proxy.Error(f.request, "message")
|
2011-02-02 23:16:03 +00:00
|
|
|
assert c.add_error(e)
|
|
|
|
|
2011-03-05 02:58:48 +00:00
|
|
|
e = proxy.Error(tutils.tflow().request, "message")
|
2011-02-02 23:16:03 +00:00
|
|
|
assert not c.add_error(e)
|
|
|
|
|
|
|
|
def test_view(self):
|
|
|
|
c = flow.State()
|
|
|
|
|
2011-03-05 02:58:48 +00:00
|
|
|
req = tutils.treq()
|
2011-02-19 04:00:24 +00:00
|
|
|
c.clientconnect(req.client_conn)
|
|
|
|
assert len(c.view) == 0
|
|
|
|
|
|
|
|
f = c.add_request(req)
|
2011-02-02 23:16:03 +00:00
|
|
|
assert len(c.view) == 1
|
2011-02-19 04:00:24 +00:00
|
|
|
|
|
|
|
c.set_limit(filt.parse("~s"))
|
2011-02-02 23:16:03 +00:00
|
|
|
assert len(c.view) == 0
|
2011-03-05 02:58:48 +00:00
|
|
|
resp = tutils.tresp(req)
|
2011-02-19 04:00:24 +00:00
|
|
|
c.add_response(resp)
|
|
|
|
assert len(c.view) == 1
|
2011-02-02 23:16:03 +00:00
|
|
|
c.set_limit(None)
|
2011-02-19 04:00:24 +00:00
|
|
|
assert len(c.view) == 1
|
2011-02-02 23:16:03 +00:00
|
|
|
|
2011-03-05 02:58:48 +00:00
|
|
|
req = tutils.treq()
|
2011-02-19 04:00:24 +00:00
|
|
|
c.clientconnect(req.client_conn)
|
2011-02-02 23:16:03 +00:00
|
|
|
c.add_request(req)
|
|
|
|
assert len(c.view) == 2
|
|
|
|
c.set_limit(filt.parse("~q"))
|
|
|
|
assert len(c.view) == 1
|
|
|
|
c.set_limit(filt.parse("~s"))
|
2011-02-19 04:00:24 +00:00
|
|
|
assert len(c.view) == 1
|
2011-02-02 23:16:03 +00:00
|
|
|
|
|
|
|
def _add_request(self, state):
|
2011-03-05 02:58:48 +00:00
|
|
|
req = tutils.treq()
|
2011-02-19 04:00:24 +00:00
|
|
|
f = state.add_request(req)
|
2011-02-02 23:16:03 +00:00
|
|
|
return f
|
|
|
|
|
|
|
|
def _add_response(self, state):
|
2011-03-05 02:58:48 +00:00
|
|
|
req = tutils.treq()
|
2011-02-19 04:00:24 +00:00
|
|
|
f = state.add_request(req)
|
2011-03-05 02:58:48 +00:00
|
|
|
resp = tutils.tresp(req)
|
2011-02-19 04:00:24 +00:00
|
|
|
state.add_response(resp)
|
2011-02-02 23:16:03 +00:00
|
|
|
|
|
|
|
def _add_error(self, state):
|
2011-03-05 02:58:48 +00:00
|
|
|
req = tutils.treq()
|
2011-02-19 04:00:24 +00:00
|
|
|
f = state.add_request(req)
|
2011-02-20 00:29:41 +00:00
|
|
|
f.error = proxy.Error(f.request, "msg")
|
2011-02-02 23:16:03 +00:00
|
|
|
|
|
|
|
def test_kill_flow(self):
|
|
|
|
c = flow.State()
|
2011-03-05 02:58:48 +00:00
|
|
|
req = tutils.treq()
|
2011-02-19 04:00:24 +00:00
|
|
|
f = c.add_request(req)
|
2011-02-02 23:16:03 +00:00
|
|
|
c.kill_flow(f)
|
2011-03-06 03:11:45 +00:00
|
|
|
assert not c.flow_count()
|
2011-02-02 23:16:03 +00:00
|
|
|
|
|
|
|
def test_clear(self):
|
|
|
|
c = flow.State()
|
2011-02-19 04:00:24 +00:00
|
|
|
f = self._add_request(c)
|
2011-02-02 23:16:03 +00:00
|
|
|
f.intercepting = True
|
|
|
|
|
|
|
|
c.clear()
|
2011-03-06 03:11:45 +00:00
|
|
|
assert c.flow_count() == 1
|
2011-02-02 23:16:03 +00:00
|
|
|
f.intercepting = False
|
|
|
|
c.clear()
|
2011-03-06 03:11:45 +00:00
|
|
|
assert c.flow_count() == 0
|
2011-02-02 23:16:03 +00:00
|
|
|
|
|
|
|
def test_dump_flows(self):
|
|
|
|
c = flow.State()
|
|
|
|
self._add_request(c)
|
|
|
|
self._add_response(c)
|
|
|
|
self._add_request(c)
|
|
|
|
self._add_response(c)
|
|
|
|
self._add_request(c)
|
|
|
|
self._add_response(c)
|
|
|
|
self._add_error(c)
|
|
|
|
|
2011-02-16 02:10:00 +00:00
|
|
|
flows = c.view[:]
|
2011-02-02 23:16:03 +00:00
|
|
|
c.clear()
|
2011-02-16 02:10:00 +00:00
|
|
|
|
|
|
|
c.load_flows(flows)
|
2011-02-02 23:16:03 +00:00
|
|
|
assert isinstance(c.flow_list[0], flow.Flow)
|
|
|
|
|
|
|
|
def test_accept_all(self):
|
|
|
|
c = flow.State()
|
|
|
|
self._add_request(c)
|
|
|
|
self._add_response(c)
|
|
|
|
self._add_request(c)
|
|
|
|
c.accept_all()
|
|
|
|
|
|
|
|
|
2011-02-16 01:33:04 +00:00
|
|
|
class uSerialize(libpry.AutoTree):
|
|
|
|
def test_roundtrip(self):
|
|
|
|
sio = StringIO()
|
2011-03-05 02:58:48 +00:00
|
|
|
f = tutils.tflow()
|
2011-02-16 01:33:04 +00:00
|
|
|
w = flow.FlowWriter(sio)
|
|
|
|
w.add(f)
|
|
|
|
|
|
|
|
sio.seek(0)
|
|
|
|
r = flow.FlowReader(sio)
|
|
|
|
l = list(r.stream())
|
|
|
|
assert len(l) == 1
|
|
|
|
assert l[0] == f
|
|
|
|
|
|
|
|
|
2011-02-16 03:43:35 +00:00
|
|
|
class uFlowMaster(libpry.AutoTree):
|
2011-02-19 04:21:08 +00:00
|
|
|
def test_all(self):
|
2011-02-16 03:43:35 +00:00
|
|
|
s = flow.State()
|
2011-02-19 04:21:08 +00:00
|
|
|
fm = flow.FlowMaster(None, s)
|
2011-03-05 02:58:48 +00:00
|
|
|
req = tutils.treq()
|
2011-02-19 04:00:24 +00:00
|
|
|
|
2011-02-19 04:21:08 +00:00
|
|
|
fm.handle_clientconnect(req.client_conn)
|
|
|
|
|
|
|
|
f = fm.handle_request(req)
|
2011-03-06 03:11:45 +00:00
|
|
|
assert s.flow_count() == 1
|
2011-02-19 04:00:24 +00:00
|
|
|
|
2011-03-05 02:58:48 +00:00
|
|
|
resp = tutils.tresp(req)
|
2011-02-19 04:21:08 +00:00
|
|
|
fm.handle_response(resp)
|
2011-03-06 03:11:45 +00:00
|
|
|
assert s.flow_count() == 1
|
2011-02-19 04:21:08 +00:00
|
|
|
|
2011-03-05 02:58:48 +00:00
|
|
|
rx = tutils.tresp()
|
2011-02-19 04:21:08 +00:00
|
|
|
assert not fm.handle_response(rx)
|
2011-02-16 03:43:35 +00:00
|
|
|
|
2011-02-19 04:21:08 +00:00
|
|
|
dc = proxy.ClientDisconnect(req.client_conn)
|
|
|
|
fm.handle_clientdisconnect(dc)
|
|
|
|
|
2011-02-20 00:29:41 +00:00
|
|
|
err = proxy.Error(f.request, "msg")
|
2011-02-19 04:21:08 +00:00
|
|
|
fm.handle_error(err)
|
|
|
|
|
2011-03-06 03:02:28 +00:00
|
|
|
def test_client_playback(self):
|
|
|
|
s = flow.State()
|
|
|
|
|
|
|
|
f = tutils.tflow_full()
|
|
|
|
pb = [tutils.tflow_full(), f]
|
|
|
|
fm = flow.FlowMaster(None, s)
|
2011-03-06 04:08:56 +00:00
|
|
|
assert not fm.start_server_playback(pb, False, [], False)
|
2011-03-06 03:54:49 +00:00
|
|
|
assert not fm.start_client_playback(pb, False)
|
2011-03-06 03:02:28 +00:00
|
|
|
|
|
|
|
q = Queue.Queue()
|
2011-03-06 03:11:45 +00:00
|
|
|
assert not fm.state.flow_count()
|
2011-03-06 03:02:28 +00:00
|
|
|
fm.tick(q)
|
2011-03-06 03:11:45 +00:00
|
|
|
assert fm.state.flow_count()
|
2011-03-06 03:02:28 +00:00
|
|
|
|
|
|
|
fm.handle_error(proxy.Error(f.request, "error"))
|
|
|
|
|
|
|
|
|
2011-03-05 00:03:26 +00:00
|
|
|
def test_server_playback(self):
|
2011-02-20 20:54:39 +00:00
|
|
|
s = flow.State()
|
|
|
|
|
2011-03-05 02:58:48 +00:00
|
|
|
f = tutils.tflow()
|
|
|
|
f.response = tutils.tresp(f.request)
|
2011-02-20 20:54:39 +00:00
|
|
|
pb = [f]
|
|
|
|
|
|
|
|
fm = flow.FlowMaster(None, s)
|
2011-03-05 02:58:48 +00:00
|
|
|
assert not fm.do_server_playback(tutils.tflow())
|
2011-02-20 20:54:39 +00:00
|
|
|
|
2011-03-06 04:08:56 +00:00
|
|
|
fm.start_server_playback(pb, False, [], False)
|
2011-03-05 02:58:48 +00:00
|
|
|
assert fm.do_server_playback(tutils.tflow())
|
2011-02-20 20:54:39 +00:00
|
|
|
|
2011-03-06 04:08:56 +00:00
|
|
|
fm.start_server_playback(pb, False, [], True)
|
2011-03-05 02:58:48 +00:00
|
|
|
r = tutils.tflow()
|
2011-02-20 20:54:39 +00:00
|
|
|
r.request.content = "gibble"
|
2011-03-05 00:03:26 +00:00
|
|
|
assert not fm.do_server_playback(r)
|
|
|
|
|
2011-03-06 04:08:56 +00:00
|
|
|
assert fm.do_server_playback(tutils.tflow())
|
|
|
|
q = Queue.Queue()
|
|
|
|
fm.tick(q)
|
|
|
|
assert fm._shutdown
|
|
|
|
|
2011-02-24 02:15:51 +00:00
|
|
|
def test_stickycookie(self):
|
|
|
|
s = flow.State()
|
|
|
|
fm = flow.FlowMaster(None, s)
|
|
|
|
assert "Invalid" in fm.set_stickycookie("~h")
|
|
|
|
fm.set_stickycookie(".*")
|
|
|
|
assert fm.stickycookie_state
|
|
|
|
fm.set_stickycookie(None)
|
|
|
|
assert not fm.stickycookie_state
|
|
|
|
|
|
|
|
fm.set_stickycookie(".*")
|
2011-03-05 02:58:48 +00:00
|
|
|
tf = tutils.tflow_full()
|
2011-02-24 02:15:51 +00:00
|
|
|
tf.response.headers["set-cookie"] = ["foo=bar"]
|
|
|
|
fm.handle_request(tf.request)
|
|
|
|
f = fm.handle_response(tf.response)
|
|
|
|
assert fm.stickycookie_state.jar
|
|
|
|
assert not "cookie" in tf.request.headers
|
|
|
|
fm.handle_request(tf.request)
|
|
|
|
assert tf.request.headers["cookie"] == ["foo=bar"]
|
|
|
|
|
|
|
|
|
2011-01-30 22:48:53 +00:00
|
|
|
tests = [
|
2011-02-23 21:33:39 +00:00
|
|
|
uStickyCookieState(),
|
2011-02-20 19:47:19 +00:00
|
|
|
uServerPlaybackState(),
|
2011-03-04 00:08:43 +00:00
|
|
|
uClientPlaybackState(),
|
2011-02-02 23:16:03 +00:00
|
|
|
uFlow(),
|
|
|
|
uState(),
|
2011-02-16 03:43:35 +00:00
|
|
|
uSerialize(),
|
2011-03-05 22:21:31 +00:00
|
|
|
uFlowMaster(),
|
2011-01-30 22:48:53 +00:00
|
|
|
]
|