2011-02-16 21:18:38 +00:00
|
|
|
import os
|
2011-02-16 09:10:24 +00:00
|
|
|
from cStringIO import StringIO
|
|
|
|
import libpry
|
2011-02-16 21:18:38 +00:00
|
|
|
from libmproxy import dump, flow
|
2011-02-16 09:10:24 +00:00
|
|
|
import utils
|
|
|
|
|
|
|
|
|
|
|
|
class uDumpMaster(libpry.AutoTree):
|
|
|
|
def _dummy_cycle(self, m):
|
|
|
|
req = utils.treq()
|
|
|
|
cc = req.client_conn
|
|
|
|
resp = utils.tresp(req)
|
|
|
|
m.handle_clientconnection(cc)
|
|
|
|
m.handle_request(req)
|
|
|
|
m.handle_response(resp)
|
|
|
|
|
2011-02-16 10:03:46 +00:00
|
|
|
def test_options(self):
|
|
|
|
o = dump.Options(verbosity = 2)
|
|
|
|
assert o.verbosity == 2
|
|
|
|
libpry.raises(AttributeError, dump.Options, nonexistent = 2)
|
|
|
|
|
2011-02-16 21:44:08 +00:00
|
|
|
def test_filter(self):
|
|
|
|
cs = StringIO()
|
|
|
|
o = dump.Options(
|
|
|
|
verbosity = 1
|
|
|
|
)
|
|
|
|
m = dump.DumpMaster(None, o, "~u foo", outfile=cs)
|
|
|
|
self._dummy_cycle(m)
|
|
|
|
assert not "GET" in cs.getvalue()
|
|
|
|
|
|
|
|
def test_basic(self):
|
2011-02-16 09:10:24 +00:00
|
|
|
for i in (1, 2, 3):
|
|
|
|
cs = StringIO()
|
2011-02-16 10:03:46 +00:00
|
|
|
o = dump.Options(
|
|
|
|
verbosity = i
|
|
|
|
)
|
2011-02-16 21:44:08 +00:00
|
|
|
m = dump.DumpMaster(None, o, "~s", outfile=cs)
|
2011-02-16 09:10:24 +00:00
|
|
|
self._dummy_cycle(m)
|
|
|
|
assert "GET" in cs.getvalue()
|
|
|
|
|
2011-02-16 21:18:38 +00:00
|
|
|
def test_write(self):
|
|
|
|
d = self.tmpdir()
|
|
|
|
p = os.path.join(d, "a")
|
|
|
|
o = dump.Options(
|
|
|
|
wfile = p,
|
|
|
|
verbosity = 0
|
|
|
|
)
|
|
|
|
cs = StringIO()
|
2011-02-16 21:44:08 +00:00
|
|
|
m = dump.DumpMaster(None, o, None, outfile=cs)
|
2011-02-16 21:18:38 +00:00
|
|
|
self._dummy_cycle(m)
|
|
|
|
del m
|
|
|
|
assert len(list(flow.FlowReader(open(p)).stream())) == 1
|
|
|
|
|
|
|
|
def test_write_err(self):
|
|
|
|
o = dump.Options(
|
|
|
|
wfile = "nonexistentdir/foo",
|
|
|
|
verbosity = 0
|
|
|
|
)
|
|
|
|
cs = StringIO()
|
2011-02-16 21:44:08 +00:00
|
|
|
libpry.raises(dump.DumpError, dump.DumpMaster, None, o, None)
|
2011-02-16 21:18:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-02-16 09:10:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
tests = [
|
|
|
|
uDumpMaster()
|
|
|
|
]
|
|
|
|
|
|
|
|
|