aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_fernet.py
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-10-31 09:39:25 -0700
committerAlex Gaynor <alex.gaynor@gmail.com>2013-10-31 09:39:25 -0700
commit2b21b12d337e65c59b5d18e42f1927c64565945d (patch)
treef1b0b4019dcbcb5bc884e6745ca43e60ad82ef0c /tests/test_fernet.py
parentf593848419b0d871509df388dadef8c1c98d9a99 (diff)
downloadcryptography-2b21b12d337e65c59b5d18e42f1927c64565945d.tar.gz
cryptography-2b21b12d337e65c59b5d18e42f1927c64565945d.tar.bz2
cryptography-2b21b12d337e65c59b5d18e42f1927c64565945d.zip
Added test cases, fixed a bug
Diffstat (limited to 'tests/test_fernet.py')
-rw-r--r--tests/test_fernet.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/test_fernet.py b/tests/test_fernet.py
new file mode 100644
index 00000000..e9d07f81
--- /dev/null
+++ b/tests/test_fernet.py
@@ -0,0 +1,23 @@
+import base64
+
+from cryptography.fernet import Fernet
+
+
+class TestFernet(object):
+ def test_generate(self):
+ f = Fernet(base64.urlsafe_b64decode(
+ b"cw_0x689RpI-jtRR7oE8h_eQsKImvJapLeSbXpwF4e4="
+ ))
+ token = f._encrypt_from_parts(
+ b"hello",
+ 499162800,
+ b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",
+ )
+ assert token == b"gAAAAAAdwJ6wAAECAwQFBgcICQoLDA0ODy021cpGVWKZ_eEwCGM4BLLF_5CV9dOPmrhuVUPgJobwOz7JcbmrR64jVmpU4IwqDA=="
+
+ def test_verify(self):
+ f = Fernet(base64.urlsafe_b64decode(
+ b"cw_0x689RpI-jtRR7oE8h_eQsKImvJapLeSbXpwF4e4="
+ ))
+ payload = f.decrypt(b"gAAAAAAdwJ6wAAECAwQFBgcICQoLDA0ODy021cpGVWKZ_eEwCGM4BLLF_5CV9dOPmrhuVUPgJobwOz7JcbmrR64jVmpU4IwqDA==", 60)
+ assert payload == b"hello"