aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_fernet.py
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-11-22 10:12:05 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2013-11-22 10:12:05 -0800
commit1d2901cae193cb965480835aaf96696f8eecfaab (patch)
tree65ada261aa41bc3000d029480ee2d25f69a22288 /tests/test_fernet.py
parentaafa63cce69c446a0c4d713c8357c61d4a7a8f4e (diff)
downloadcryptography-1d2901cae193cb965480835aaf96696f8eecfaab.tar.gz
cryptography-1d2901cae193cb965480835aaf96696f8eecfaab.tar.bz2
cryptography-1d2901cae193cb965480835aaf96696f8eecfaab.zip
Hide the dangerous bits
Diffstat (limited to 'tests/test_fernet.py')
-rw-r--r--tests/test_fernet.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/tests/test_fernet.py b/tests/test_fernet.py
index 4080bd2d..c1caaa05 100644
--- a/tests/test_fernet.py
+++ b/tests/test_fernet.py
@@ -15,6 +15,7 @@ import base64
import calendar
import json
import os
+import time
import iso8601
@@ -51,22 +52,20 @@ class TestFernet(object):
@json_parametrize(
("secret", "now", "src", "ttl_sec", "token"), "verify.json",
)
- def test_verify(self, secret, now, src, ttl_sec, token):
+ def test_verify(self, secret, now, src, ttl_sec, token, monkeypatch):
f = Fernet(secret.encode("ascii"))
current_time = calendar.timegm(iso8601.parse_date(now).utctimetuple())
- payload = f.decrypt(
- token.encode("ascii"), ttl=ttl_sec, current_time=current_time
- )
+ monkeypatch.setattr(time, "time", lambda: current_time)
+ payload = f.decrypt(token.encode("ascii"), ttl=ttl_sec)
assert payload == src.encode("ascii")
@json_parametrize(("secret", "token", "now", "ttl_sec"), "invalid.json")
- def test_invalid(self, secret, token, now, ttl_sec):
+ def test_invalid(self, secret, token, now, ttl_sec, monkeypatch):
f = Fernet(secret.encode("ascii"))
current_time = calendar.timegm(iso8601.parse_date(now).utctimetuple())
+ monkeypatch.setattr(time, "time", lambda: current_time)
with pytest.raises(InvalidToken):
- f.decrypt(
- token.encode("ascii"), ttl=ttl_sec, current_time=current_time
- )
+ f.decrypt(token.encode("ascii"), ttl=ttl_sec)
def test_unicode(self):
f = Fernet(base64.b64encode(b"\x00" * 32))