Alex Gaynor | 2b21b12 | 2013-10-31 09:39:25 -0700 | [diff] [blame^] | 1 | import base64 |
| 2 | |
| 3 | from cryptography.fernet import Fernet |
| 4 | |
| 5 | |
| 6 | class 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" |