-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_password.py
executable file
·62 lines (52 loc) · 2.18 KB
/
test_password.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
#!/usr/bin/env python3
"""This Module tests the password entry module"""
import unittest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from libpkpass.password import PasswordEntry
from libpkpass.identities import IdentityDB
class TestBasicFunction(unittest.TestCase):
"""This Class tests the password entry class"""
def setUp(self):
self.certdir = "test/pki/intermediate/certs"
self.keydir = "test/pki/intermediate/private"
self.cabundle = "test/pki/intermediate/certs/ca-bundle"
self.file1 = "test/passwords/testpassword"
self.file2 = "test/scratch/testpassword"
self.secret = "Secret"
self.textblob = "Testing TextField"
self.sender = "r1"
self.iddb = IdentityDB()
self.iddb.id = self.sender
self.iddb.recipient_list = ["r2", "r3"]
db_path = "test/pki/intermediate/certs/rd.db"
self.iddb.args = {
"db": {
"uri": f"sqlite+pysqlite:///{db_path}",
"engine": create_engine(f"sqlite+pysqlite:///{db_path}"),
},
}
self.iddb.session = sessionmaker(bind=self.iddb.args["db"]["engine"])()
self.iddb.load_certs_from_directory(self.certdir, self.cabundle)
self.iddb.load_keys_from_directory(self.keydir)
def test_create_encrypt_decrypt(self):
"""create a password entry"""
passwordentry = PasswordEntry(
name="testcreate", description=self.textblob, creator="r1", authorizer="r1"
)
passwordentry.add_recipients(
secret=self.secret,
distributor="r1",
recipients=self.iddb.recipient_list,
session=self.iddb.session,
)
def test_read_write(self):
"""Read and write password entry data"""
passwordentry = PasswordEntry()
passwordentry.read_password_data(self.file1)
passwordentry.write_password_data(self.file2, overwrite=True)
with open(self.file1, "r", encoding="ASCII") as file1:
with open(self.file2, "r", encoding="ASCII") as file2:
self.assertTrue(file1.read() == file2.read())
if __name__ == "__main__":
unittest.main()