diff options
author | Theo Chatzimichos <tampakrap@gentoo.org> | 2013-08-19 12:15:15 +0200 |
---|---|---|
committer | Theo Chatzimichos <tampakrap@gentoo.org> | 2013-08-19 23:21:09 +0200 |
commit | c89dcaf1addd60a993d1ca53326a3844ab03eea0 (patch) | |
tree | d882ff55f4f0c4429d9868bcb152560e1a5a1f14 | |
parent | Add @anonymous_required decorator (diff) | |
download | identity.gentoo.org-c89dcaf1addd60a993d1ca53326a3844ab03eea0.tar.gz identity.gentoo.org-c89dcaf1addd60a993d1ca53326a3844ab03eea0.tar.bz2 identity.gentoo.org-c89dcaf1addd60a993d1ca53326a3844ab03eea0.zip |
Add tests for OkupyCipher
-rw-r--r-- | okupy/tests/unit/test_cipher.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/okupy/tests/unit/test_cipher.py b/okupy/tests/unit/test_cipher.py new file mode 100644 index 0000000..31ac795 --- /dev/null +++ b/okupy/tests/unit/test_cipher.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +from Crypto import Random +from unittest import TestCase + +from ...common.crypto import cipher + + +class OkupyCipherTests(TestCase): + def test_verify_password_less_than_8_chars(self): + hash = cipher.encrypt('test1') + self.assertEqual(cipher.decrypt(hash, 5), 'test1') + + def test_verify_password_8_chars(self): + hash = cipher.encrypt('testtest') + self.assertEqual(cipher.decrypt(hash, 8), 'testtest') + + def test_verify_password_more_than_8_chars(self): + hash = cipher.encrypt('testtest123') + self.assertEqual(cipher.decrypt(hash, 11), 'testtest123') + + def test_verify_password_more_than_16_chars(self): + hash = cipher.encrypt('testtest123456789012') + self.assertEqual(cipher.decrypt(hash, 20), 'testtest123456789012') + + def test_encrypt_random_bytes(self): + password = Random.get_random_bytes(45) + hash = cipher.encrypt(password) + self.assertEqual(cipher.decrypt(hash, 45), password) |