source: TI12-security/trunk/python/ndg.security.test/ndg/security/test/utils/testConfigFileParsers.py @ 4136

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.test/ndg/security/test/utils/testConfigFileParsers.py@4136
Revision 4136, 7.7 KB checked in by cbyrom, 11 years ago (diff)

Extend test suite to exercise new functions available to config parser
utility class + add new test config files for use with the tests.

Line 
1'''
2A test class for the Utilities module.
3
4C Byrom Jun 2008
5Tessella
6'''
7import unittest, os
8from ndg.security.common.utils.ConfigFileParsers import readProperties, readAndValidateProperties
9from ndg.security.server.AttAuthority import AttAuthority
10from ndg.security.server.SessionMgr import SessionMgr
11from ConfigParser import MissingSectionHeaderError
12
13class testConfigFileParsers(unittest.TestCase):
14   
15    NDG_SEC_DIR_ENV_VAR = '$NDGSEC_DIR'
16    NDG_SEC_DIR = os.path.expandvars(NDG_SEC_DIR_ENV_VAR)
17    BASE_DIR_ENV_VAR = '$PYTHON_TEST_DIR'
18    BASE_DIR = os.path.expandvars(BASE_DIR_ENV_VAR)
19    NDGSEC_AACLNT_UNITTEST_DIR_ENV_VAR = '$NDGSEC_AACLNT_UNITTEST_DIR'
20    NDGSEC_AACLNT_UNITTEST_DIR = os.path.expandvars(NDGSEC_AACLNT_UNITTEST_DIR_ENV_VAR)
21    ATT_AUTH_INI_FILE = BASE_DIR + "/attAuthority.cfg"
22    ATT_AUTH_XML_FILE = BASE_DIR + "/attAuthorityProperties.xml"
23    SESSION_MGR_INI_FILE = BASE_DIR + "/sessionMgr.cfg"
24    SESSION_MGR_XML_FILE = BASE_DIR + "/sessionMgrProperties.xml"
25    INVALID_INI_FILE = BASE_DIR + "/invalidAttAuthority.cfg"
26    INVALID_XML_FILE = BASE_DIR + "/invalidAttAuthorityProperties.xml"
27    MISSING_INI_FILE = "blah"
28    MISSING_XML_FILE = "blah.xml"
29   
30    VALID_ROLES_MOD_NAME = 'siteAUserRoles' 
31    def setUp(self):
32        '''
33        set up data used in the tests.
34        '''
35        if self.BASE_DIR == self.BASE_DIR_ENV_VAR or not self.BASE_DIR:
36            raise SystemError("The '$PYTHON_TEST_DIR' environment variable is not set up\
37                - please set this before running the tests")
38        if self.NDGSEC_AACLNT_UNITTEST_DIR == self.NDGSEC_AACLNT_UNITTEST_DIR_ENV_VAR or not self.NDGSEC_AACLNT_UNITTEST_DIR:
39            raise SystemError("The '$NDGSEC_AACLNT_UNITTEST_DIR' environment variable is not set up\
40                - please set this before running the tests")
41
42    def testMissingINIFile(self):
43        self.assertRaises(ValueError,readProperties, self.MISSING_INI_FILE)
44
45    def testMissingXMLFile(self):
46        self.assertRaises(ValueError,readProperties, self.MISSING_XML_FILE)
47
48    def testInvalidINIFile(self):
49        self.assertRaises(MissingSectionHeaderError,readProperties, self.INVALID_INI_FILE)
50
51    def testInvalidXMLFile(self):
52        self.assertRaises(SyntaxError,readProperties, self.INVALID_XML_FILE)
53           
54    def testBasicINIInput(self):
55       
56        cfg = readProperties(self.ATT_AUTH_INI_FILE, validKeys=AttAuthority._AttAuthority__validKeys)
57        # do some basic checks of what is returned
58        self.assertNotEqual(cfg, None)
59        self.assertEqual(type(cfg), dict)
60        self.assertEqual(cfg['useSSL'], None)
61        self.assertEqual(cfg['userRolesModName'], self.VALID_ROLES_MOD_NAME)
62        self.assertEqual(type(cfg['WS-Security']), dict)
63        self.assertEqual(len(cfg['WS-Security']['caCertFileList']), 2)
64        self.assertEqual(cfg['WS-Security']['caCertFileList'][0], self.BASE_DIR + '/ca/ndg-test-ca.crt')
65
66
67    def testBasicXMLInput(self):
68       
69        cfg = readProperties(self.ATT_AUTH_XML_FILE, validKeys=AttAuthority._AttAuthority__validKeys)
70        # do some basic checks of what is returned
71        self.assertNotEqual(cfg, None)
72        self.assertEqual(type(cfg), dict)
73        self.assertEqual(cfg['useSSL'], None)
74        self.assertEqual(cfg['userRolesModName'], self.VALID_ROLES_MOD_NAME)
75        self.assertEqual(type(cfg['WS-Security']), dict)
76        self.assertEqual(len(cfg['WS-Security']['caCertFileList']), 2)
77        self.assertEqual(cfg['WS-Security']['caCertFileList'][0], self.BASE_DIR + '/ca/ndg-test-ca.crt')
78
79
80    def testINIandXMLInput(self):
81        cfgINI = readProperties(self.ATT_AUTH_INI_FILE, validKeys=AttAuthority._AttAuthority__validKeys)
82        cfgXML = readProperties(self.ATT_AUTH_XML_FILE, validKeys=AttAuthority._AttAuthority__validKeys)
83        self.assertEqual(cfgINI, cfgXML)
84       
85
86    def testAttAuthorityINIInput(self):
87       
88        cfg = readProperties(self.ATT_AUTH_INI_FILE, validKeys=AttAuthority._AttAuthority__validKeys)
89        # do some basic checks of what is returned
90        self.assertNotEqual(cfg, None)
91        self.assertEqual(type(cfg), dict)
92        self.assertEqual(cfg['useSSL'], None)
93        self.assertEqual(cfg['userRolesModName'], self.VALID_ROLES_MOD_NAME)
94        self.assertEqual(type(cfg['WS-Security']), dict)
95        self.assertEqual(len(cfg['WS-Security']['caCertFileList']), 2)
96        self.assertEqual(cfg['WS-Security']['caCertFileList'][0], self.BASE_DIR + '/ca/ndg-test-ca.crt')
97
98
99    def testAttAuthorityXMLInput(self):
100       
101        cfg = readProperties(self.ATT_AUTH_XML_FILE, validKeys=AttAuthority._AttAuthority__validKeys)
102        # do some basic checks of what is returned
103        self.assertNotEqual(cfg, None)
104        self.assertEqual(type(cfg), dict)
105        self.assertEqual(cfg['useSSL'], None)
106        self.assertEqual(cfg['userRolesModName'], self.VALID_ROLES_MOD_NAME)
107        self.assertEqual(type(cfg['WS-Security']), dict)
108        self.assertEqual(len(cfg['WS-Security']['caCertFileList']), 2)
109        self.assertEqual(cfg['WS-Security']['caCertFileList'][0], self.BASE_DIR + '/ca/ndg-test-ca.crt')
110       
111
112    def testSessionMgrINIInput(self):
113       
114        cfg = readProperties(self.SESSION_MGR_INI_FILE, validKeys=SessionMgr._SessionMgr__validElem)
115        # do some basic checks of what is returned
116        self.assertNotEqual(cfg, None)
117        self.assertEqual(type(cfg), dict)
118        self.assertEqual(cfg['useSSL'], 'Yes')
119        self.assertEqual(type(cfg['WS-Security']), dict)
120        self.assertEqual(len(cfg['WS-Security']['caCertFileList']), 1)
121        self.assertEqual(cfg['WS-Security']['caCertFileList'][0], self.NDG_SEC_DIR + '/conf/certs/ca/cacert.pem')
122
123
124    def testSessionMgrXMLInput(self):
125       
126        cfg = readProperties(self.SESSION_MGR_XML_FILE, validKeys=SessionMgr._SessionMgr__validElem)
127        # do some basic checks of what is returned
128        self.assertNotEqual(cfg, None)
129        self.assertEqual(type(cfg), dict)
130        self.assertEqual(cfg['useSSL'], 'Yes')
131        self.assertEqual(type(cfg['WS-Security']), dict)
132        self.assertEqual(len(cfg['WS-Security']['caCertFileList']), 1)
133        self.assertEqual(cfg['WS-Security']['caCertFileList'][0], self.NDG_SEC_DIR + '/conf/certs/ca/cacert.pem')
134                         
135       
136           
137    def testBasicINIInputValidate(self):
138       
139        cfg = readAndValidateProperties(self.ATT_AUTH_INI_FILE, validKeys=AttAuthority._AttAuthority__validKeys)
140        # do some basic checks of what is returned
141        self.assertNotEqual(cfg, None)
142        self.assertEqual(type(cfg), dict)
143        self.assertEqual(cfg['useSSL'], False)
144        self.assertEqual(cfg['userRolesModName'], self.VALID_ROLES_MOD_NAME)
145        self.assertEqual(type(cfg['WS-Security']), dict)
146        self.assertEqual(len(cfg['WS-Security']['caCertFileList']), 2)
147        self.assertEqual(cfg['WS-Security']['caCertFileList'][0], self.BASE_DIR + '/ca/ndg-test-ca.crt')
148
149
150    def testBasicXMLInputValidate(self):
151       
152        cfg = readAndValidateProperties(self.ATT_AUTH_XML_FILE, validKeys=AttAuthority._AttAuthority__validKeys)
153        # do some basic checks of what is returned
154        self.assertNotEqual(cfg, None)
155        self.assertEqual(type(cfg), dict)
156        self.assertEqual(cfg['useSSL'], False)
157        self.assertEqual(cfg['userRolesModName'], self.VALID_ROLES_MOD_NAME)
158        self.assertEqual(type(cfg['WS-Security']), dict)
159        self.assertEqual(len(cfg['WS-Security']['caCertFileList']), 2)
160        self.assertEqual(cfg['WS-Security']['caCertFileList'][0], self.BASE_DIR + '/ca/ndg-test-ca.crt')
161       
162
163if __name__ == '__main__':
164
165    unittest.main()
Note: See TracBrowser for help on using the repository browser.