blob: 79eaec09c9c0f309f9e2f2f343b889dd64ae794d (
plain)
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
|
#!/usr/bin/env python
"""Unit tests for M2Crypto.Engine."""
try:
import unittest2 as unittest
except ImportError:
import unittest
from M2Crypto import Engine
class EngineTestCase(unittest.TestCase):
privkey = 'tests/rsa.priv.pem'
bad_id = '1bea1edfeb97'
def tearDown(self):
Engine.cleanup()
def test_by_id_junk(self):
with self.assertRaises(ValueError):
Engine.Engine(self.bad_id)
with self.assertRaises(ValueError):
Engine.Engine()
def test_by_id_openssl(self):
Engine.load_openssl()
e = Engine.Engine('openssl')
self.assertEqual(e.get_name(), 'Software engine support')
self.assertEqual(e.get_id(), 'openssl')
def test_by_id_dynamic(self):
Engine.load_dynamic()
Engine.Engine('dynamic')
def test_load_private(self):
Engine.load_openssl()
e = Engine.Engine('openssl')
e.set_default()
e.load_private_key(self.privkey)
def test_load_certificate(self):
Engine.load_openssl()
e = Engine.Engine('openssl')
e.set_default()
try:
with self.assertRaises(Engine.EngineError):
e.load_certificate('/dev/null')
except SystemError:
pass
def suite():
return unittest.makeSuite(EngineTestCase)
if __name__ == '__main__':
unittest.TextTestRunner().run(suite())
|