blob: e9d07f8192c6ddb20a722680de01840f70e28111 [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 )
16 assert token == b"gAAAAAAdwJ6wAAECAwQFBgcICQoLDA0ODy021cpGVWKZ_eEwCGM4BLLF_5CV9dOPmrhuVUPgJobwOz7JcbmrR64jVmpU4IwqDA=="
17
18 def test_verify(self):
19 f = Fernet(base64.urlsafe_b64decode(
20 b"cw_0x689RpI-jtRR7oE8h_eQsKImvJapLeSbXpwF4e4="
21 ))
22 payload = f.decrypt(b"gAAAAAAdwJ6wAAECAwQFBgcICQoLDA0ODy021cpGVWKZ_eEwCGM4BLLF_5CV9dOPmrhuVUPgJobwOz7JcbmrR64jVmpU4IwqDA==", 60)
23 assert payload == b"hello"