aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_protocol_http.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2015-04-14 15:14:36 +1200
committerAldo Cortesi <aldo@nullcube.com>2015-04-14 15:14:36 +1200
commitab7e2857cc9095c4cee8ca9b569c16516aa520ba (patch)
tree37ceeb9370695e4ad40b07696d780bd1d5f19bf1 /test/test_protocol_http.py
parente17eacd8d77c78daa88d8f89ace990463378d98d (diff)
downloadmitmproxy-ab7e2857cc9095c4cee8ca9b569c16516aa520ba.tar.gz
mitmproxy-ab7e2857cc9095c4cee8ca9b569c16516aa520ba.tar.bz2
mitmproxy-ab7e2857cc9095c4cee8ca9b569c16516aa520ba.zip
New get_cookies for HttpResponse
Diffstat (limited to 'test/test_protocol_http.py')
-rw-r--r--test/test_protocol_http.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/test_protocol_http.py b/test/test_protocol_http.py
index 11ab503b..0276cab7 100644
--- a/test/test_protocol_http.py
+++ b/test/test_protocol_http.py
@@ -230,6 +230,62 @@ class TestHTTPResponse:
assert "foo" in repr(r)
assert repr(tutils.tresp(content=CONTENT_MISSING))
+ def test_get_cookies_none(self):
+ h = odict.ODictCaseless()
+ resp = tutils.tresp()
+ resp.headers = h
+ assert not resp.get_cookies()
+
+ def test_get_cookies_simple(self):
+ h = odict.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"][0] == ["cookievalue", odict.ODict()]
+
+ def test_get_cookies_with_parameters(self):
+ h = odict.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][0] == "cookievalue"
+ attrs = result["cookiename"][0][1]
+ assert len(attrs)==4
+ assert attrs["domain"] == ["example.com"]
+ assert attrs["expires"] == ["Wed Oct 21 16:29:41 2015"]
+ assert attrs["path"] == ["/"]
+ assert attrs["httponly"] == [None]
+
+ def test_get_cookies_no_value(self):
+ h = odict.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][0] == ""
+ assert len(result["cookiename"][0][1])==2
+
+ def test_get_cookies_twocookies(self):
+ h = odict.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"][0] == ["cookievalue", odict.ODict()]
+ assert "othercookie" in result
+ assert result["othercookie"][0] == ["othervalue", odict.ODict()]
+
+
class TestHTTPFlow(object):
def test_repr(self):