aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorShadab Zafar <dufferzafar0@gmail.com>2016-08-11 15:52:32 +0530
committerShadab Zafar <dufferzafar0@gmail.com>2016-08-15 12:00:23 +0530
commit988174246b4f06ca702cbcd9aacb2e3ef7cd5280 (patch)
tree93ca9e75f2f0f73037e442a27fcb37f1e914b4a8 /test
parent567cbe6cb9bae3bde7b1d4d95ad70dd0db3485ff (diff)
downloadmitmproxy-988174246b4f06ca702cbcd9aacb2e3ef7cd5280.tar.gz
mitmproxy-988174246b4f06ca702cbcd9aacb2e3ef7cd5280.tar.bz2
mitmproxy-988174246b4f06ca702cbcd9aacb2e3ef7cd5280.zip
Add some cookie formatting related tests
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/test_examples.py24
-rw-r--r--test/netlib/http/test_cookies.py6
2 files changed, 25 insertions, 5 deletions
diff --git a/test/mitmproxy/test_examples.py b/test/mitmproxy/test_examples.py
index 62e6a652..402120c0 100644
--- a/test/mitmproxy/test_examples.py
+++ b/test/mitmproxy/test_examples.py
@@ -13,6 +13,7 @@ import netlib.utils
from netlib import tutils as netutils
from netlib.http import Headers
+from netlib.http import cookies
from . import tutils, mastertest
@@ -102,7 +103,7 @@ class TestScripts(mastertest.MasterTest):
assert f.request.host == "mitmproxy.org"
-class TestHARDump(mastertest.MasterTest):
+class TestHARDump():
def setup(self):
times = dict(
@@ -125,10 +126,29 @@ class TestHARDump(mastertest.MasterTest):
path = os.path.join(tdir, "somefile")
m, sc = tscript("har_dump.py", six.moves.shlex_quote(path))
- self.invoke(m, "response", self.req_get)
+ m.addons.invoke(m, "response", self.req_get)
m.addons.remove(sc)
with open(path, "r") as inp:
har = json.load(inp)
assert len(har["log"]["entries"]) == 1
+
+ def test_format_cookies(self):
+ m, sc = tscript("har_dump.py", "-")
+ format_cookies = sc.ns.ns["format_cookies"]
+
+ CA = cookies.CookieAttrs
+
+ f = format_cookies([("n", "v", CA([("k", "v")]))])[0]
+ assert f['name'] == "n"
+ assert f['value'] == "v"
+ assert not f['httpOnly']
+ assert not f['secure']
+
+ f = format_cookies([("n", "v", CA([("httponly", None), ("secure", None)]))])[0]
+ assert f['httpOnly']
+ assert f['secure']
+
+ f = format_cookies([("n", "v", CA([("expires", "Fri, 24-Aug-2063 00:00:00 GMT")]))])[0]
+ assert f['expires'] == "2063-08-24T05:30:00+00:00"
diff --git a/test/netlib/http/test_cookies.py b/test/netlib/http/test_cookies.py
index cc5115c7..828029c6 100644
--- a/test/netlib/http/test_cookies.py
+++ b/test/netlib/http/test_cookies.py
@@ -261,7 +261,7 @@ def test_get_expiration_ts(*args):
F = cookies.get_expiration_ts
assert F(CA([("Expires", "Thu, 01-Jan-1970 00:00:00 GMT")])) == 0
- assert F(CA([("Expires", "Thu, 24-Aug-2063 00:00:00 GMT")])) == 2955139200
+ assert F(CA([("Expires", "Fri, 24-Aug-2063 00:00:00 GMT")])) == 2955139200
assert F(CA([("Max-Age", "0")])) == now_ts
assert F(CA([("Max-Age", "31")])) == now_ts + 31
@@ -280,9 +280,9 @@ def test_is_expired():
# or both
assert cookies.is_expired(CA([("Expires", "Thu, 01-Jan-1970 00:00:00 GMT"), ("Max-Age", "0")]))
- assert not cookies.is_expired(CA([("Expires", "Thu, 24-Aug-2063 00:00:00 GMT")]))
+ assert not cookies.is_expired(CA([("Expires", "Fri, 24-Aug-2063 00:00:00 GMT")]))
assert not cookies.is_expired(CA([("Max-Age", "1")]))
- assert not cookies.is_expired(CA([("Expires", "Thu, 15-Jul-2068 00:00:00 GMT"), ("Max-Age", "1")]))
+ assert not cookies.is_expired(CA([("Expires", "Sun, 15-Jul-2068 00:00:00 GMT"), ("Max-Age", "1")]))
assert not cookies.is_expired(CA([("Max-Age", "nan")]))
assert not cookies.is_expired(CA([("Expires", "false")]))