-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
74 lines (44 loc) · 1.83 KB
/
Copy pathtest.py
File metadata and controls
74 lines (44 loc) · 1.83 KB
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
from hashlib import sha1
import unittest, os
from compromised import isPwned, get_line_length, read_cfg
class Test_findHash(unittest.TestCase):
@classmethod
def setUpClass(cls):
pass
@classmethod
def tearDownClass(cls):
pass
def setUp(self):
self.secret = 'password@1234'
self.TARGET_HASH = sha1(self.secret+'salt').hexdigest().upper()
self.file_path = "test_passwords_sha1.txt"
""" get the target file size"""
self.fileSize = os.path.getsize(self.file_path)
self.LINE_LENGTH = get_line_length(self.file_path)
self.total_lines = self.fileSize / self.LINE_LENGTH
pass
def tearDown(self):
pass
def test_readCfg(self):
self.assertNotEqual(os.environ['APP_CONFIG'], True)
self.assertNotEquals(read_cfg(), '')
def hash_pass(self):
return sha1(read_cfg()).hexdigest().upper()
def test_recursive_search_pass(self):
with open(self.file_path,'rb+') as f:
# get the length of the file
total_lines = self.fileSize / self.LINE_LENGTH
index_range = (0, total_lines)
line_index = self.total_lines/2
result = isPwned(f, self.hash_pass(), self.LINE_LENGTH, line_index, index_range)
self.assertEqual(result, True)
def test_recursive_search_fail(self):
with open(self.file_path,'rb+') as f:
# get the length of the file
total_lines = self.fileSize / self.LINE_LENGTH
index_range = (0, total_lines)
line_index = self.total_lines/2
result = isPwned(f, self.TARGET_HASH, self.LINE_LENGTH, line_index, index_range)
self.assertEqual(result, False)
if __name__ == '__main__':
unittest.main()