forked from AdSHSO/PythonPassword
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestPassword.py
49 lines (39 loc) · 1.4 KB
/
testPassword.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
import unittest
import Password
cleartext_password = "myS3cr3tP455w0Rd"
class TestPassword(unittest.TestCase):
def setUp(self):
self.pw_hasher = Password.Password()
def test_valid_hash(self):
hash = self.pw_hasher.hash_password(cleartext_password)
self.assertTrue(
self.pw_hasher.hash_check(
cleartext_password,
hash
))
def test_invalid_hash(self):
invalid_hash = b'$2b$12$o9kR21YMqEMofk2EEx2Y9OQeuaaQc2LbrYTtRNFEHwEh.NVcN.2lK'
hash = self.pw_hasher.hash_password(cleartext_password)
self.assertNotEqual(
hash,
invalid_hash
)
self.assertFalse(
self.pw_hasher.hash_check(
cleartext_password,
invalid_hash
))
def test_pw_too_short(self):
with self.assertRaises(ValueError):
self.pw_hasher.hash_password("Pw123")
def test_pw_too_long(self):
with self.assertRaises(ValueError):
self.pw_hasher.hash_password("Pw1" + "a"*128)
def test_no_capital_letter(self):
with self.assertRaises(ValueError):
self.pw_hasher.hash_password("aaaaaaaaaaaaaaaaaaaaaaaaaaaaa123")
def test_no_number(self):
with self.assertRaises(ValueError):
self.pw_hasher.hash_password("aaaaaaaaaaaaaaaaaaaaaaaaaaaAAA")
if __name__ == '__main__':
unittest.main()