source: TI12-security/trunk/python/ndg.security.test/ndg/security/test/AttCert/X509Test.py @ 2953

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.test/ndg/security/test/AttCert/X509Test.py@2953
Revision 2953, 2.8 KB checked in by pjkersha, 13 years ago (diff)
  • Property svn:executable set to *
  • Property svn:keywords set to Id
Line 
1#!/usr/bin/env python
2"""NDG X509 Module unit tests
3
4NERC Data Grid Project
5"""
6__author__ = "P J Kershaw"
7__date__ = "03/01/07"
8__copyright__ = "(C) 2007 STFC & NERC"
9__license__ = \
10"""This software may be distributed under the terms of the Q Public
11License, version 1.0 or later."""
12__contact__ = "P.J.Kershaw@rl.ac.uk"
13__revision__ = '$Id$'
14
15import unittest
16import os
17import sys
18import getpass
19import traceback
20
21from ConfigParser import SafeConfigParser
22from ndg.security.common.X509 import *
23
24class X509TestCase(unittest.TestCase):
25   
26    def setUp(self):
27       
28        configParser = SafeConfigParser()
29        configParser.read("./x509Test.cfg")
30       
31        self.cfg = {}
32        for section in configParser.sections():
33            self.cfg[section] = dict(configParser.items(section))
34           
35           
36    def test1X509CertRead(self):
37        'test1X509CertRead: read in a cert from file'
38        print self.test1X509CertRead.__doc__
39        self.X509Cert=X509CertRead(self.cfg['test1X509CertRead']['certfile'])
40        assert(self.X509Cert)
41
42    def test2X509CertAsPEM(self):
43        'test2X509CertAsPEM: display as a PEM format string'
44        self.test1X509CertRead()
45        print self.test2X509CertAsPEM.__doc__
46        self.pemString = self.X509Cert.asPEM()
47        print self.pemString
48
49
50    def test3X509CertParse(self):
51        'test3X509CertParse: parse from a PEM format string'
52        self.test2X509CertAsPEM()
53        print self.test3X509CertParse.__doc__
54        assert(X509CertParse(self.pemString))
55
56
57    def test4GetDN(self):
58        'test4GetDN: extract distinguished name'
59        self.test1X509CertRead()
60        print self.test4GetDN.__doc__
61        self.dn = self.X509Cert.dn
62        print self.dn
63       
64    def test5DN(self):
65        'test5DN: test X.500 Distinguished Name attributes'
66        print self.test5DN.__doc__
67        self.test4GetDN()
68        for item in self.dn.items():
69            print "%s=%s" % item
70       
71    def test6DNCmp(self):
72        '''test6DNCmp: test X.500 Distinguished Name comparison
73        operators'''
74        print self.test6DNCmp.__doc__
75        self.test4GetDN()
76        testDN = X500DN(dn="/O=a/OU=b/CN=c")
77
78        assert(not(testDN == self.dn))
79        assert(testDN != self.dn)
80        assert(self.dn == self.dn)
81        assert(not(self.dn != self.dn))
82           
83       
84class X509TestSuite(unittest.TestSuite):
85    def __init__(self):
86        map = map(X509TestCase,
87                  (
88                    "test1X509CertRead",
89                    "test2X509CertAsPEM",
90                    "test3X509CertParse",
91                    "test4GetDN",
92                    "test5DN",
93                    "test6DNCmp"
94                  ))
95        unittest.TestSuite.__init__(self, map)
96 
97                                       
98if __name__ == "__main__":
99    unittest.main()
Note: See TracBrowser for help on using the repository browser.