more helpful log line for Renew
[sfa.git] / tests / testGid.py
1 import unittest
2 from sfa.trust.certificate import Keypair
3 from sfa.trust.gid import *
4
5 class TestGid(unittest.TestCase):
6    def setUp(self):
7       pass
8
9    def testSetGetHrn(self):
10       gid = GID(subject="test")
11       hrn = "test.hrn"
12
13       gid.set_hrn(hrn)
14       self.assertEqual(gid.get_hrn(), hrn)
15
16    def testSetGetUuid(self):
17       gid = GID(subject="test")
18       u = uuid.uuid4().int
19
20       gid.set_uuid(u)
21       self.assertEqual(gid.get_uuid(), u)
22
23    def testEncodeDecode(self):
24       gid = GID(subject="test")
25       u = uuid.uuid4().int
26       hrn = "test.hrn"
27
28       gid.set_uuid(u)
29       gid.set_hrn(hrn)
30
31       gid.encode()
32       gid.decode()
33
34       self.assertEqual(gid.get_hrn(), hrn)
35       self.assertEqual(gid.get_uuid(), u)
36
37    def testSaveAndLoadString(self):
38       gid = GID(subject="test")
39
40       u = uuid.uuid4().int
41       hrn = "test.hrn"
42
43       gid.set_uuid(u)
44       gid.set_hrn(hrn)
45
46       # create an issuer and sign the certificate
47       issuerKey =  Keypair(create = True)
48       issuerSubject = "testissuer"
49       gid.set_issuer(issuerKey, issuerSubject)
50       gid.sign()
51
52       certstr = gid.save_to_string()
53
54       #print certstr
55
56       gid2 = GID(string = certstr)
57
58       self.assertEqual(gid.get_hrn(), hrn)
59       self.assertEqual(gid.get_uuid(), u)
60
61 if __name__ == "__main__":
62     unittest.main()