/
crypt_test.py
76 lines (56 loc) · 2.02 KB
/
crypt_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import unittest
from crypt import Crypt
"""
d_values = ('plaintext', 'passphrase')
"""
d_values = (
('servas', 'poidl'),
('gassdasdasd', 'asdasdasdasad'),
('kjkuererwerew', 'dfsdfddd'),
('asdfsdfsdfsdfsdfsdfsdfsdfsdf', 'se'),
('ssd', 'oida'),
('', '2'),
('', ''),
(1212332, 121324324345435)
)
class DecryptEncryptCheck(unittest.TestCase):
cipher_key = 'my secret phrase'
def test_ed_cycle(self):
for pt, pph in d_values:
c = Crypt(pph)
u = c.encrypt(pt)
dc = c.decrypt(u)
print "assert equal: %s == %s" % (dc, str(pt))
self.assertEqual(dc, str(pt))
def test_module_name(self):
c = Crypt(self.cipher_key)
assert hasattr(c, '__module__')
assert c.__module__ == 'CommonCrypt.Crypt'
def test_attributes(self):
c = Crypt(self.cipher_key)
assert hasattr(c, 'BLOCK_SIZE')
assert hasattr(c, 'decrypt')
assert hasattr(c, 'encrypt')
assert callable(c.decrypt)
assert callable(c.encrypt)
def test_private_attributes(self):
c = Crypt(self.cipher_key)
assert hasattr(c, 'iv') is False
assert hasattr(c, 'key') is False
assert hasattr(c, '_Crypt__iv')
assert hasattr(c, '_Crypt__key')
assert hasattr(c, '_Crypt__pad')
assert hasattr(c, '_Crypt__trim')
def test_blocksize(self):
c = Crypt(self.cipher_key)
assert c.BLOCK_SIZE == 8
def test_encrypt(self):
c = Crypt(self.cipher_key)
encrypted = c.encrypt('some random plain text')
assert encrypted == 'b1XdLeAJ54bz/ALcDd2FeAez7y5z33Le'
def test_decrypt(self):
c = Crypt(self.cipher_key)
decrypted = c.decrypt('3b1b943Dcrqm179NGt3GnA==')
assert decrypted == 'ace to the base'
if __name__ == "__main__":
unittest.main()