diff options
author | Shadab Zafar <dufferzafar0@gmail.com> | 2016-08-08 12:55:04 +0530 |
---|---|---|
committer | Shadab Zafar <dufferzafar0@gmail.com> | 2016-08-15 12:00:23 +0530 |
commit | 03e61170424bb92199cff22797135498d5ec8ce5 (patch) | |
tree | 21df7a0f46e2688e75329d2973890f1517462537 /test | |
parent | 55f1ffe0b100c9aa2a24b041a91091601ea4575d (diff) | |
download | mitmproxy-03e61170424bb92199cff22797135498d5ec8ce5.tar.gz mitmproxy-03e61170424bb92199cff22797135498d5ec8ce5.tar.bz2 mitmproxy-03e61170424bb92199cff22797135498d5ec8ce5.zip |
Add a function to get cookie expiration time
Diffstat (limited to 'test')
-rw-r--r-- | test/netlib/http/test_cookies.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/netlib/http/test_cookies.py b/test/netlib/http/test_cookies.py index 5a0e264e..cc5115c7 100644 --- a/test/netlib/http/test_cookies.py +++ b/test/netlib/http/test_cookies.py @@ -1,6 +1,10 @@ +import time + from netlib.http import cookies from netlib.tutils import raises +import mock + def test_read_token(): tokens = [ @@ -247,6 +251,22 @@ def test_refresh_cookie(): assert cookies.refresh_set_cookie_header(c, 0) +@mock.patch('time.time') +def test_get_expiration_ts(*args): + # Freeze time + now_ts = 17 + time.time.return_value = now_ts + + CA = cookies.CookieAttrs + 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([("Max-Age", "0")])) == now_ts + assert F(CA([("Max-Age", "31")])) == now_ts + 31 + + def test_is_expired(): CA = cookies.CookieAttrs |