aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_flow.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_flow.py')
-rw-r--r--test/test_flow.py124
1 files changed, 20 insertions, 104 deletions
diff --git a/test/test_flow.py b/test/test_flow.py
index b41eb630..f5d06906 100644
--- a/test/test_flow.py
+++ b/test/test_flow.py
@@ -2,6 +2,7 @@ import Queue, time, os.path
from cStringIO import StringIO
import email.utils
import mock
+from netlib import odict
from libmproxy import filt, protocol, controller, utils, tnetstring, flow
from libmproxy.protocol.primitives import Error, Flow
from libmproxy.protocol.http import decoded, CONTENT_MISSING
@@ -125,6 +126,10 @@ class TestServerPlaybackState:
r.request.path = "voing"
assert s._hash(r) != s._hash(r2)
+ r.request.path = "path?blank_value"
+ r2.request.path = "path?"
+ assert s._hash(r) != s._hash(r2)
+
def test_headers(self):
s = flow.ServerPlaybackState(["foo"], [], False, False, None, False, None, False)
r = tutils.tflow(resp=True)
@@ -197,12 +202,12 @@ class TestServerPlaybackState:
r2 = tutils.tflow(resp=True)
r2.request.headers["Content-Type"] = ["application/x-www-form-urlencoded"]
r2.request.content = "paramx=x&param1=1"
- # same parameters
+ # same parameters
assert s._hash(r) == s._hash(r2)
- # ignored parameters !=
+ # ignored parameters !=
r2.request.content = "paramx=x&param1=2"
assert s._hash(r) == s._hash(r2)
- # missing parameter
+ # missing parameter
r2.request.content="paramx=x"
assert s._hash(r) == s._hash(r2)
# ignorable parameter added
@@ -223,7 +228,7 @@ class TestServerPlaybackState:
r2 = tutils.tflow(resp=True)
r2.request.headers["Content-Type"] = ["application/json"]
r2.request.content = '{"param1":"1"}'
- # same content
+ # same content
assert s._hash(r) == s._hash(r2)
# distint content (note only x-www-form-urlencoded payload is analysed)
r2.request.content = '{"param1":"2"}'
@@ -238,7 +243,7 @@ class TestServerPlaybackState:
r2 = tutils.tflow(resp=True)
r2.request.headers["Content-Type"] = ["application/x-www-form-urlencoded"]
r2.request.content = "paramx=x"
- # same parameters
+ # same parameters
assert s._hash(r) == s._hash(r2)
def test_ignore_content(self):
@@ -927,7 +932,7 @@ class TestRequest:
assert r.get_path_components() == []
r.path = "/foo/bar"
assert r.get_path_components() == ["foo", "bar"]
- q = flow.ODict()
+ q = odict.ODict()
q["test"] = ["123"]
r.set_query(q)
assert r.get_path_components() == ["foo", "bar"]
@@ -941,12 +946,12 @@ class TestRequest:
assert "%2F" in r.path
def test_getset_form_urlencoded(self):
- d = flow.ODict([("one", "two"), ("three", "four")])
+ d = odict.ODict([("one", "two"), ("three", "four")])
r = tutils.treq(content=utils.urlencode(d.lst))
r.headers["content-type"] = [protocol.http.HDR_FORM_URLENCODED]
assert r.get_form_urlencoded() == d
- d = flow.ODict([("x", "y")])
+ d = odict.ODict([("x", "y")])
r.set_form_urlencoded(d)
assert r.get_form_urlencoded() == d
@@ -954,7 +959,7 @@ class TestRequest:
assert not r.get_form_urlencoded()
def test_getset_query(self):
- h = flow.ODictCaseless()
+ h = odict.ODictCaseless()
r = tutils.treq()
r.path = "/foo?x=y&a=b"
@@ -971,14 +976,14 @@ class TestRequest:
r.path = "/foo?x=y&a=b"
assert r.get_query()
- r.set_query(flow.ODict([]))
+ r.set_query(odict.ODict([]))
assert not r.get_query()
- qv = flow.ODict([("a", "b"), ("c", "d")])
+ qv = odict.ODict([("a", "b"), ("c", "d")])
r.set_query(qv)
assert r.get_query() == qv
def test_anticache(self):
- h = flow.ODictCaseless()
+ h = odict.ODictCaseless()
r = tutils.treq()
r.headers = h
h["if-modified-since"] = ["test"]
@@ -1042,43 +1047,8 @@ class TestRequest:
r.encode("gzip")
assert r.get_decoded_content() == "falafel"
- def test_get_cookies_none(self):
- h = flow.ODictCaseless()
- r = tutils.treq()
- r.headers = h
- assert r.get_cookies() is None
-
- def test_get_cookies_single(self):
- h = flow.ODictCaseless()
- h["Cookie"] = ["cookiename=cookievalue"]
- r = tutils.treq()
- r.headers = h
- result = r.get_cookies()
- assert len(result)==1
- assert result['cookiename']==('cookievalue',{})
-
- def test_get_cookies_double(self):
- h = flow.ODictCaseless()
- h["Cookie"] = ["cookiename=cookievalue;othercookiename=othercookievalue"]
- r = tutils.treq()
- r.headers = h
- result = r.get_cookies()
- assert len(result)==2
- assert result['cookiename']==('cookievalue',{})
- assert result['othercookiename']==('othercookievalue',{})
-
- def test_get_cookies_withequalsign(self):
- h = flow.ODictCaseless()
- h["Cookie"] = ["cookiename=coo=kievalue;othercookiename=othercookievalue"]
- r = tutils.treq()
- r.headers = h
- result = r.get_cookies()
- assert len(result)==2
- assert result['cookiename']==('coo=kievalue',{})
- assert result['othercookiename']==('othercookievalue',{})
-
def test_header_size(self):
- h = flow.ODictCaseless()
+ h = odict.ODictCaseless()
h["headername"] = ["headervalue"]
r = tutils.treq()
r.headers = h
@@ -1086,7 +1056,7 @@ class TestRequest:
assert len(raw) == 62
def test_get_content_type(self):
- h = flow.ODictCaseless()
+ h = odict.ODictCaseless()
h["Content-Type"] = ["text/plain"]
resp = tutils.tresp()
resp.headers = h
@@ -1178,62 +1148,8 @@ class TestResponse:
result = len(r._assemble_headers())
assert result==44
- def test_get_cookies_none(self):
- h = flow.ODictCaseless()
- resp = tutils.tresp()
- resp.headers = h
- assert not resp.get_cookies()
-
- def test_get_cookies_simple(self):
- h = flow.ODictCaseless()
- h["Set-Cookie"] = ["cookiename=cookievalue"]
- resp = tutils.tresp()
- resp.headers = h
- result = resp.get_cookies()
- assert len(result)==1
- assert "cookiename" in result
- assert result["cookiename"] == ("cookievalue", {})
-
- def test_get_cookies_with_parameters(self):
- h = flow.ODictCaseless()
- h["Set-Cookie"] = ["cookiename=cookievalue;domain=example.com;expires=Wed Oct 21 16:29:41 2015;path=/; HttpOnly"]
- resp = tutils.tresp()
- resp.headers = h
- result = resp.get_cookies()
- assert len(result)==1
- assert "cookiename" in result
- assert result["cookiename"][0] == "cookievalue"
- assert len(result["cookiename"][1])==4
- assert result["cookiename"][1]["domain"]=="example.com"
- assert result["cookiename"][1]["expires"]=="Wed Oct 21 16:29:41 2015"
- assert result["cookiename"][1]["path"]=="/"
- assert result["cookiename"][1]["httponly"]==""
-
- def test_get_cookies_no_value(self):
- h = flow.ODictCaseless()
- h["Set-Cookie"] = ["cookiename=; Expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/"]
- resp = tutils.tresp()
- resp.headers = h
- result = resp.get_cookies()
- assert len(result)==1
- assert "cookiename" in result
- assert result["cookiename"][0] == ""
- assert len(result["cookiename"][1])==2
-
- def test_get_cookies_twocookies(self):
- h = flow.ODictCaseless()
- h["Set-Cookie"] = ["cookiename=cookievalue","othercookie=othervalue"]
- resp = tutils.tresp()
- resp.headers = h
- result = resp.get_cookies()
- assert len(result)==2
- assert "cookiename" in result
- assert result["cookiename"] == ("cookievalue", {})
- assert "othercookie" in result
- assert result["othercookie"] == ("othervalue", {})
-
def test_get_content_type(self):
- h = flow.ODictCaseless()
+ h = odict.ODictCaseless()
h["Content-Type"] = ["text/plain"]
resp = tutils.tresp()
resp.headers = h