blob: f7c06b95bf818bd078b632f18720eb5a6b0d810f [file] [log] [blame]
Alex Gaynor2b21b122013-10-31 09:39:25 -07001import base64
2
3from cryptography.fernet import Fernet
4
5
6class TestFernet(object):
7 def test_generate(self):
8 f = Fernet(base64.urlsafe_b64decode(
9 b"cw_0x689RpI-jtRR7oE8h_eQsKImvJapLeSbXpwF4e4="
10 ))
11 token = f._encrypt_from_parts(
12 b"hello",
13 499162800,
14 b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",
15 )
Alex Gaynor5e87dfd2013-10-31 09:46:03 -070016 assert token == (b"gAAAAAAdwJ6wAAECAwQFBgcICQoLDA0ODy021cpGVWKZ_eEwCGM"
17 "4BLLF_5CV9dOPmrhuVUPgJobwOz7JcbmrR64jVmpU4IwqDA==")
Alex Gaynor2b21b122013-10-31 09:39:25 -070018
19 def test_verify(self):
20 f = Fernet(base64.urlsafe_b64decode(
21 b"cw_0x689RpI-jtRR7oE8h_eQsKImvJapLeSbXpwF4e4="
22 ))
Alex Gaynor5e87dfd2013-10-31 09:46:03 -070023 payload = f.decrypt(
24 (b"gAAAAAAdwJ6wAAECAwQFBgcICQoLDA0ODy021cpGVWKZ_eEwCGM4BLLF_5CV9dO"
25 "PmrhuVUPgJobwOz7JcbmrR64jVmpU4IwqDA=="),
26 ttl=60,
27 current_time=499162801
28 )
Alex Gaynor2b21b122013-10-31 09:39:25 -070029 assert payload == b"hello"