deprecated sfa.util.misc (duplicate for namespace)
[sfa.git] / tests / testKeypair.py
1 #!/usr/bin/python
2 import sys
3 sys.path.append('..')
4
5 import unittest
6 import xmlrpclib
7 import base64
8 from sfa.trust.certificate import Keypair
9
10 class TestKeypair(unittest.TestCase):
11    def setUp(self):
12       pass
13
14    def testCreate(self):
15       k = Keypair()
16       k.create()
17
18    def testSaveLoadFile(self):
19       k = Keypair()
20       k.create()
21
22       k.save_to_file("test.key")
23
24       k2 = Keypair()
25       k2.load_from_file("test.key")
26
27       self.assertEqual(k.as_pem(), k2.as_pem())
28
29    def test_get_m2_pkey(self):
30       k = Keypair()
31       k.create()
32
33       m2 = k.get_m2_pkey()
34       self.assert_(m2 != None)
35
36    def test_get_openssl_pkey(self):
37       k = Keypair()
38       k.create()
39
40       pk = k.get_openssl_pkey()
41       self.assert_(pk != None)
42
43    def test_sign_verify(self):
44       k = Keypair()
45       k.create()
46
47       data = "this is a test"
48       sig = k.sign_string(data)
49
50       print k.verify_string(data, sig)
51
52 if __name__ == "__main__":
53     unittest.main()