-
Notifications
You must be signed in to change notification settings - Fork 95
/
test_keys.py
80 lines (60 loc) · 3.15 KB
/
test_keys.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
77
78
79
80
from tests import base
import copy
import xmlsec
consts = xmlsec.constants
class TestKeys(base.TestMemoryLeaks):
def test_key_from_memory(self):
key = xmlsec.Key.from_memory(self.load("rsakey.pem"), format=consts.KeyDataFormatPem)
self.assertIsNotNone(key)
def test_key_from_file(self):
key = xmlsec.Key.from_file(self.path("rsakey.pem"), format=consts.KeyDataFormatPem)
self.assertIsNotNone(key)
def test_key_from_fileobj(self):
with open(self.path("rsakey.pem"), "rb") as fobj:
key = xmlsec.Key.from_file(fobj, format=consts.KeyDataFormatPem)
self.assertIsNotNone(key)
def test_generate(self):
key = xmlsec.Key.generate(klass=consts.KeyDataAes, size=256, type=consts.KeyDataTypeSession)
self.assertIsNotNone(key)
def test_from_binary_file(self):
key = xmlsec.Key.from_binary_file(klass=consts.KeyDataDes, filename=self.path("deskey.bin"))
self.assertIsNotNone(key)
def test_load_cert_from_file(self):
key = xmlsec.Key.from_file(self.path("rsakey.pem"), format=consts.KeyDataFormatPem)
self.assertIsNotNone(key)
key.load_cert_from_file(self.path("rsacert.pem"), format=consts.KeyDataFormatPem)
def test_load_cert_from_fileobj(self):
key = xmlsec.Key.from_file(self.path("rsakey.pem"), format=consts.KeyDataFormatPem)
self.assertIsNotNone(key)
with open(self.path("rsacert.pem"), "rb") as fobj:
key.load_cert_from_file(fobj, format=consts.KeyDataFormatPem)
def test_load_cert_from_memory(self):
key = xmlsec.Key.from_file(self.path("rsakey.pem"), format=consts.KeyDataFormatPem)
self.assertIsNotNone(key)
key.load_cert_from_memory(self.load("rsacert.pem"), format=consts.KeyDataFormatPem)
def test_name(self):
key = xmlsec.Key.from_file(self.path("rsakey.pem"), format=consts.KeyDataFormatPem)
key.name = "rsakey"
self.assertEqual("rsakey", key.name)
def test_copy(self):
key = xmlsec.Key.from_file(self.path("rsakey.pem"), format=consts.KeyDataFormatPem)
key2 = copy.copy(key)
del key
key2.load_cert_from_file(self.path("rsacert.pem"), format=consts.KeyDataFormatPem)
class TestKeysManager(base.TestMemoryLeaks):
def test_add_key(self):
key = xmlsec.Key.from_file(self.path("rsakey.pem"), format=consts.KeyDataFormatPem)
mngr = xmlsec.KeysManager()
mngr.add_key(key)
def test_load_cert(self):
mngr = xmlsec.KeysManager()
mngr.add_key(xmlsec.Key.from_file(self.path("rsakey.pem"), format=consts.KeyDataFormatPem))
mngr.load_cert(self.path("rsacert.pem"), format=consts.KeyDataFormatPem, type=consts.KeyDataTypeTrusted)
def test_load_cert_from_memory(self):
mngr = xmlsec.KeysManager()
mngr.add_key(xmlsec.Key.from_file(self.path("rsakey.pem"), format=consts.KeyDataFormatPem))
mngr.load_cert_from_memory(self.load("rsacert.pem"), format=consts.KeyDataFormatPem, type=consts.KeyDataTypeTrusted)
def test_load_invalid_key(self):
mngr = xmlsec.KeysManager()
with self.assertRaises(ValueError):
mngr.add_key(xmlsec.Key())