aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-02-10 15:04:20 +1300
committerAldo Cortesi <aldo@nullcube.com>2012-02-10 15:04:20 +1300
commitb14c29b25c4c5754edf568bcbb6bbf5b70b6c310 (patch)
tree21cf7e00219ee4a1a79c368a3abcd64caa947d0a /test
parent5326b7610a365d57ff06c0e72c739d2853b695f9 (diff)
downloadmitmproxy-b14c29b25c4c5754edf568bcbb6bbf5b70b6c310.tar.gz
mitmproxy-b14c29b25c4c5754edf568bcbb6bbf5b70b6c310.tar.bz2
mitmproxy-b14c29b25c4c5754edf568bcbb6bbf5b70b6c310.zip
Expand test coverage.
Diffstat (limited to 'test')
-rw-r--r--test/test_dump.py9
-rw-r--r--test/test_encoding.py1
-rw-r--r--test/test_filt.py2
-rw-r--r--test/test_flow.py44
-rw-r--r--test/test_utils.py12
5 files changed, 65 insertions, 3 deletions
diff --git a/test/test_dump.py b/test/test_dump.py
index c5efed62..317d628a 100644
--- a/test/test_dump.py
+++ b/test/test_dump.py
@@ -58,7 +58,7 @@ class uDumpMaster(libpry.AutoTree):
o = dump.Options(server_replay=p, kill=True)
m = dump.DumpMaster(None, o, None, outfile=cs)
-
+
self._cycle(m, "content")
self._cycle(m, "content")
@@ -80,6 +80,11 @@ class uDumpMaster(libpry.AutoTree):
0, None, "", verbosity=1, rfile="/nonexistent"
)
+ libpry.raises(
+ dump.DumpError, self._dummy_cycle,
+ 0, None, "", verbosity=1, rfile="test_dump.py"
+ )
+
def test_options(self):
o = dump.Options(verbosity = 2)
assert o.verbosity == 2
@@ -106,7 +111,7 @@ class uDumpMaster(libpry.AutoTree):
self._dummy_cycle,
1,
None,
- "",
+ "",
wfile = "nonexistentdir/foo"
)
diff --git a/test/test_encoding.py b/test/test_encoding.py
index fe338da1..6ebe7172 100644
--- a/test/test_encoding.py
+++ b/test/test_encoding.py
@@ -7,6 +7,7 @@ class uidentity(libpry.AutoTree):
def test_simple(self):
assert "string" == encoding.decode("identity", "string")
assert "string" == encoding.encode("identity", "string")
+ assert not encoding.encode("nonexistent", "string")
def test_fallthrough(self):
assert None == encoding.decode("nonexistent encoding", "string")
diff --git a/test/test_filt.py b/test/test_filt.py
index 6c11938e..4ff7e90e 100644
--- a/test/test_filt.py
+++ b/test/test_filt.py
@@ -178,6 +178,8 @@ class uMatching(libpry.AutoTree):
assert self.q("~m get", q)
assert not self.q("~m post", q)
assert not self.q("~m get", s)
+ q.method = ""
+ assert not self.q("~m get", q)
def test_url(self):
q = self.req()
diff --git a/test/test_flow.py b/test/test_flow.py
index e4cd6da2..088a180f 100644
--- a/test/test_flow.py
+++ b/test/test_flow.py
@@ -15,6 +15,11 @@ class uStickyCookieState(libpry.AutoTree):
s.handle_response(f)
return s, f
+ def test_domain_match(self):
+ s = flow.StickyCookieState(filt.parse(".*"))
+ assert s.domain_match("www.google.com", ".google.com")
+ assert s.domain_match("google.com", ".google.com")
+
def test_handle_response(self):
c = "SSID=mooo, FOO=bar; Domain=.google.com; Path=/; "\
"Expires=Wed, 13-Jan-2021 22:23:01 GMT; Secure; "
@@ -295,6 +300,15 @@ class uState(libpry.AutoTree):
e = flow.Error(tutils.tflow().request, "message")
assert not c.add_error(e)
+ c = flow.State()
+ req = tutils.treq()
+ f = c.add_request(req)
+ e = flow.Error(f.request, "message")
+ c.set_limit("~bs message")
+ assert not c.view
+ assert c.add_error(e)
+ #assert c.view
+
def test_set_limit(self):
c = flow.State()
@@ -577,6 +591,14 @@ class uRequest(libpry.AutoTree):
r2 = r.copy()
assert r == r2
+ r.content = None
+ assert r._assemble()
+
+ r.close = True
+ assert "connection: close" in r._assemble()
+
+ assert r._assemble(True)
+
def test_getset_form_urlencoded(self):
h = flow.Headers()
h["content-type"] = [flow.HDR_FORM_URLENCODED]
@@ -588,6 +610,8 @@ class uRequest(libpry.AutoTree):
r.set_form_urlencoded(d)
assert r.get_form_urlencoded() == d
+ r.headers["content-type"] = ["foo"]
+ assert not r.get_form_urlencoded()
def test_getset_query(self):
h = flow.Headers()
@@ -652,6 +676,12 @@ class uRequest(libpry.AutoTree):
assert not "foo" in r.content
assert r.headers["boo"] == ["boo"]
+ def test_constrain_encoding(self):
+ r = tutils.treq()
+ r.headers["accept-encoding"] = ["gzip", "oink"]
+ r.constrain_encoding()
+ assert "oink" not in r.headers["accept-encoding"]
+
def test_decodeencode(self):
r = tutils.treq()
r.headers["content-encoding"] = ["identity"]
@@ -661,6 +691,10 @@ class uRequest(libpry.AutoTree):
assert r.content == "falafel"
r = tutils.treq()
+ r.content = "falafel"
+ assert not r.decode()
+
+ r = tutils.treq()
r.headers["content-encoding"] = ["identity"]
r.content = "falafel"
r.encode("identity")
@@ -690,6 +724,12 @@ class uResponse(libpry.AutoTree):
resp2 = resp.copy()
assert resp2 == resp
+ resp.content = None
+ assert resp._assemble()
+
+ resp.request.client_conn.close = True
+ assert "connection: close" in resp._assemble()
+
def test_refresh(self):
r = tutils.tresp()
n = time.time()
@@ -809,6 +849,10 @@ class uHeaders(libpry.AutoTree):
def setUp(self):
self.hd = flow.Headers()
+ def test_str_err(self):
+ h = flow.Headers()
+ libpry.raises(ValueError, h.__setitem__, "key", "foo")
+
def test_read_simple(self):
data = """
Header: one
diff --git a/test/test_utils.py b/test/test_utils.py
index d9546993..65c76ac9 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -29,6 +29,7 @@ class uhexdump(libpry.AutoTree):
def test_simple(self):
assert utils.hexdump("one\0"*10)
+
class udel_all(libpry.AutoTree):
def test_simple(self):
d = dict(a=1, b=2, c=3)
@@ -36,6 +37,13 @@ class udel_all(libpry.AutoTree):
assert d.keys() == ["c"]
+class uclean_hanging_newline(libpry.AutoTree):
+ def test_simple(self):
+ s = "foo\n"
+ assert utils.clean_hanging_newline(s) == "foo"
+ assert utils.clean_hanging_newline("foo") == "foo"
+
+
class upretty_size(libpry.AutoTree):
def test_simple(self):
assert utils.pretty_size(100) == "100B"
@@ -222,6 +230,7 @@ class u_parse_url(libpry.AutoTree):
class u_parse_size(libpry.AutoTree):
def test_simple(self):
+ assert not utils.parse_size("")
assert utils.parse_size("1") == 1
assert utils.parse_size("1k") == 1024
assert utils.parse_size("1m") == 1024**2
@@ -245,5 +254,6 @@ tests = [
udummy_cert(),
uLRUCache(),
u_parse_url(),
- u_parse_size()
+ u_parse_size(),
+ uclean_hanging_newline()
]