]> www.wagner.pp.ru Git - oss/ctypescrypto.git/blob - tests/testoids.py
Added explicit check for CMS functions in libcrypto
[oss/ctypescrypto.git] / tests / testoids.py
1 from ctypescrypto.oid import Oid,create,cleanup
2 import unittest
3
4 class TestStandard(unittest.TestCase):
5     def test_cn(self):
6         o=Oid("2.5.4.3")
7         self.assertEqual(repr(o),"Oid('2.5.4.3')")
8         self.assertEqual(o.dotted(),"2.5.4.3")
9         self.assertEqual(str(o),"2.5.4.3")
10         self.assertEqual(o.shortname(),"CN")
11         self.assertEqual(o.longname(),"commonName")
12     def test_getnid(self):
13         o=Oid("2.5.4.3")
14         x=Oid("CN")
15         self.assertEqual(o.nid,x.nid)
16         self.assertEqual(o,x)
17         self.assertEqual(hash(o),hash(x))
18
19     def test_cons2(self):
20         o=Oid("2.5.4.3")
21         x=Oid("commonName")
22         self.assertEqual(o.nid,x.nid)
23     def test_bynid(self):
24         o=Oid("2.5.4.3")
25         x=Oid(o.nid)
26         self.assertEqual(o.nid,x.nid)
27     def test_clone(self):
28         o1=Oid('2.5.4.3')
29         o2=Oid(o1)
30         self.assertEqual(o1.nid,o2.nid)
31     def test_fromunicode(self):
32         o=Oid(u'commonName')
33         self.assertEqual(o.shortname(),'CN')
34     def test_wrongoid(self):
35         with self.assertRaises(ValueError):
36             o=Oid("1.2.3.4.5.6.7.8.10.111.1111")
37     def test_wrongname(self):
38         with self.assertRaises(ValueError):
39             o=Oid("No such oid in the database")
40     def test_wrongnid(self):
41         with self.assertRaises(ValueError):
42             o=Oid(9999999)
43     def test_wrongtype(self):
44         with self.assertRaises(TypeError):
45             o=Oid([2,5,3,4])
46
47 class TestCustom(unittest.TestCase):
48     def _no_testCreate(self):
49         d='1.2.643.9.100.99'
50         sn="CtypesCryptoTestOid"
51         long_name="Test Oid in CryptoCom namespace"
52         o=create(d,sn,long_name)
53         self.assertEqual(str(o),d)
54         self.assertEqual(o.shortname(),sn)
55         self.assertEqual(o.longname(),long_name)
56     def testLookup(self):
57         d='1.2.643.9.100.99'
58         sn="CtypesCryptoTestOid"
59         long_name="Test Oid In CryptoCom Namespace"
60         o=create(d,sn,long_name)
61         x=Oid(sn)
62         self.assertEqual(o,x)
63     def _no_testFromObj(self):
64         from ctypescrypto import libcrypto
65         from ctypes import c_int, c_char_p, c_void_p
66         libcrypto.OBJ_txt2obj.argtypes = (c_char_p, c_int)
67         libcrypto.OBJ_txt2obj.restype = c_void_p
68         obj= libcrypto.OBJ_txt2obj("1.2.643.100.9",1)
69         oid=Oid.fromobj(obj)
70         self.assertEqual(str(oid),'1.2.643.100.9')
71     def tearDown(self):
72         # Always call cleanup before next test
73         cleanup()
74     
75
76
77
78 if __name__ == '__main__':
79     unittest.main()