-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_id.py
executable file
·67 lines (59 loc) · 2.32 KB
/
test_id.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
#!/usr/bin/env python3
"""This Module tests iddb module"""
import unittest
import os.path
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from libpkpass.identities import IdentityDB
from libpkpass.models.recipient import Recipient
class TestBasicFunction(unittest.TestCase):
"""This class tests the iddb class"""
def setUp(self):
self.certdir = "test/pki/intermediate/certs"
self.keydir = "test/pki/intermediate/private"
self.cabundle = "test/pki/intermediate/certs/ca-bundle"
db_path = "test/pki/intermediate/certs/rd.db"
self.iddb = IdentityDB()
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"])()
def test_certificate_loading(self):
"""Load a cert into our test"""
self.iddb.load_certs_from_directory(self.certdir, self.cabundle)
for identity in ("r1", "r2", "r3"):
assert identity in [
x[0] for x in self.iddb.session.query(Recipient.name).all()
]
def test_key_loading(self):
"""Load a key into our test"""
self.iddb.load_keys_from_directory(self.keydir)
for identity in ("r1", "r2", "r3"):
assert identity in [
x[0] for x in self.iddb.session.query(Recipient.name).all()
]
test_id = (
self.iddb.session.query(Recipient)
.filter(Recipient.name == identity)
.first()
)
assert os.path.isfile(test_id.key)
def test_keycert_loading(self):
"""Load a keycert into our test"""
self.iddb.load_certs_from_directory(self.certdir, self.cabundle)
self.iddb.load_keys_from_directory(self.keydir)
for identity in ("r1", "r2", "r3"):
assert identity in [
x[0] for x in self.iddb.session.query(Recipient.name).all()
]
test_id = (
self.iddb.session.query(Recipient)
.filter(Recipient.name == identity)
.first()
)
assert os.path.isfile(test_id.key)
if __name__ == "__main__":
unittest.main()