Changeset 4136 for TI12-security


Ignore:
Timestamp:
26/08/08 16:57:13 (11 years ago)
Author:
cbyrom
Message:

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

Location:
TI12-security/trunk/python/ndg.security.test/ndg/security/test/utils
Files:
6 added
1 edited

Legend:

Unmodified
Added
Removed
  • TI12-security/trunk/python/ndg.security.test/ndg/security/test/utils/testConfigFileParsers.py

    r4131 r4136  
    66''' 
    77import unittest, os 
    8 from ndg.security.common.utils.ConfigFileParsers import readProperties 
     8from ndg.security.common.utils.ConfigFileParsers import readProperties, readAndValidateProperties 
    99from ndg.security.server.AttAuthority import AttAuthority 
     10from ndg.security.server.SessionMgr import SessionMgr 
    1011from ConfigParser import MissingSectionHeaderError 
    1112 
    1213class testConfigFileParsers(unittest.TestCase): 
    1314     
     15    NDG_SEC_DIR_ENV_VAR = '$NDGSEC_DIR' 
     16    NDG_SEC_DIR = os.path.expandvars(NDG_SEC_DIR_ENV_VAR) 
    1417    BASE_DIR_ENV_VAR = '$PYTHON_TEST_DIR' 
    1518    BASE_DIR = os.path.expandvars(BASE_DIR_ENV_VAR) 
    16     ATT_AUTH_INI_FILE = BASE_DIR + "/siteAAttAuthority.cfg" 
    17     ATT_AUTH_XML_FILE = BASE_DIR + "/siteAAttAuthorityProperties.xml" 
    18     INVALID_INI_FILE = BASE_DIR + "/invalidSiteAAttAuthority.cfg" 
    19     INVALID_XML_FILE = BASE_DIR + "/invalidSiteAAttAuthorityProperties.xml" 
     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" 
    2027    MISSING_INI_FILE = "blah" 
    2128    MISSING_XML_FILE = "blah.xml" 
     
    2633        set up data used in the tests. 
    2734        ''' 
    28         if self.BASE_DIR == self.BASE_DIR_ENV_VAR: 
     35        if self.BASE_DIR == self.BASE_DIR_ENV_VAR or not self.BASE_DIR: 
    2936            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\ 
    3040                - please set this before running the tests") 
    3141 
    3242    def testMissingINIFile(self): 
    33         self.assertRaises(ValueError,readProperties, self.MISSING_INI_FILE, AttAuthority._AttAuthority__validKeys) 
     43        self.assertRaises(ValueError,readProperties, self.MISSING_INI_FILE) 
    3444 
    3545    def testMissingXMLFile(self): 
    36         self.assertRaises(ValueError,readProperties, self.MISSING_XML_FILE, AttAuthority._AttAuthority__validKeys) 
     46        self.assertRaises(ValueError,readProperties, self.MISSING_XML_FILE) 
    3747 
    3848    def testInvalidINIFile(self): 
    39         self.assertRaises(MissingSectionHeaderError,readProperties, self.INVALID_INI_FILE, AttAuthority._AttAuthority__validKeys) 
     49        self.assertRaises(MissingSectionHeaderError,readProperties, self.INVALID_INI_FILE) 
    4050 
    4151    def testInvalidXMLFile(self): 
    42         self.assertRaises(SyntaxError,readProperties, self.INVALID_XML_FILE, AttAuthority._AttAuthority__validKeys) 
     52        self.assertRaises(SyntaxError,readProperties, self.INVALID_XML_FILE) 
    4353             
    4454    def testBasicINIInput(self): 
    4555         
    46         cfg = readProperties(self.ATT_AUTH_INI_FILE, AttAuthority._AttAuthority__validKeys) 
     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) 
    47140        # do some basic checks of what is returned 
    48141        self.assertNotEqual(cfg, None) 
     
    50143        self.assertEqual(cfg['useSSL'], False) 
    51144        self.assertEqual(cfg['userRolesModName'], self.VALID_ROLES_MOD_NAME) 
    52         self.assertEqual(type(cfg['caCertFileList']), list) 
    53         self.assertEqual(len(cfg['caCertFileList']), 2) 
    54         self.assertEqual(cfg['caCertFileList'][0], '$NDGSEC_AACLNT_UNITTEST_DIR/ca/ndg-test-ca.crt') 
     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') 
    55148 
    56149 
    57     def testBasicXMLInput(self): 
     150    def testBasicXMLInputValidate(self): 
    58151         
    59         cfg = readProperties(self.ATT_AUTH_XML_FILE, AttAuthority._AttAuthority__validKeys) 
     152        cfg = readAndValidateProperties(self.ATT_AUTH_XML_FILE, validKeys=AttAuthority._AttAuthority__validKeys) 
    60153        # do some basic checks of what is returned 
    61154        self.assertNotEqual(cfg, None) 
     
    63156        self.assertEqual(cfg['useSSL'], False) 
    64157        self.assertEqual(cfg['userRolesModName'], self.VALID_ROLES_MOD_NAME) 
    65         self.assertEqual(type(cfg['caCertFileList']), list) 
    66         self.assertEqual(len(cfg['caCertFileList']), 2) 
    67         self.assertEqual(cfg['caCertFileList'][0], '$NDGSEC_AACLNT_UNITTEST_DIR/ca/ndg-test-ca.crt') 
    68  
    69  
    70     def testINIandXMLInput(self): 
    71         cfgINI = readProperties(self.ATT_AUTH_INI_FILE, AttAuthority._AttAuthority__validKeys) 
    72         cfgXML = readProperties(self.ATT_AUTH_XML_FILE, AttAuthority._AttAuthority__validKeys) 
    73         self.assertEqual(cfgINI, cfgXML) 
    74          
    75  
    76     def testAttAuthorityINIInput(self): 
    77          
    78         cfg = readProperties(self.ATT_AUTH_INI_FILE, AttAuthority._AttAuthority__validKeys) 
    79         # do some basic checks of what is returned 
    80         self.assertNotEqual(cfg, None) 
    81         self.assertEqual(type(cfg), dict) 
    82         self.assertEqual(cfg['useSSL'], False) 
    83         self.assertEqual(cfg['userRolesModName'], self.VALID_ROLES_MOD_NAME) 
    84         self.assertEqual(type(cfg['caCertFileList']), list) 
    85         self.assertEqual(len(cfg['caCertFileList']), 2) 
    86         self.assertEqual(cfg['caCertFileList'][0], '$NDGSEC_AACLNT_UNITTEST_DIR/ca/ndg-test-ca.crt') 
    87  
    88  
    89     def testAttAuthorityXMLInput(self): 
    90          
    91         cfg = readProperties(self.ATT_AUTH_XML_FILE, AttAuthority._AttAuthority__validKeys) 
    92         # do some basic checks of what is returned 
    93         self.assertNotEqual(cfg, None) 
    94         self.assertEqual(type(cfg), dict) 
    95         self.assertEqual(cfg['useSSL'], False) 
    96         self.assertEqual(cfg['userRolesModName'], self.VALID_ROLES_MOD_NAME) 
    97         self.assertEqual(type(cfg['caCertFileList']), list) 
    98         self.assertEqual(len(cfg['caCertFileList']), 2) 
    99         self.assertEqual(cfg['caCertFileList'][0], '$NDGSEC_AACLNT_UNITTEST_DIR/ca/ndg-test-ca.crt') 
    100                           
    101          
     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') 
    102161         
    103162 
Note: See TracChangeset for help on using the changeset viewer.