Ignore:
Timestamp:
17/07/09 16:41:29 (12 years ago)
Author:
pjkersha
Message:

Work on unit testing for IdP Validator implementation + SSL client authN validator

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI12-security/trunk/python/ndg.security.test/ndg/security/test/unit/openid/relyingparty/validation/test_validation.py

    r5491 r5497  
     1"""OpenID IdP Validation unit test package 
     2 
     3NERC DataGrid Project 
     4""" 
     5__author__ = "P J Kershaw" 
     6__date__ = "16/07/09" 
     7__copyright__ = "(C) 2009 Science and Technology Facilities Council" 
     8__license__ = "BSD - see LICENSE file in top-level directory" 
     9__contact__ = "Philip.Kershaw@stfc.ac.uk" 
     10__revision__ = '$Id$' 
     11import logging 
     12logging.basicConfig(level=logging.DEBUG) 
     13 
     14import os 
     15import unittest 
     16from ndg.security.test.unit import BaseTestCase 
     17from ndg.security.server.wsgi.openid.relyingparty.validation import \ 
     18    IdPValidator, IdPValidationDriver, IdPInvalidException 
     19     
     20class ProviderWhitelistValidator(IdPValidator): 
     21    def __init__(self): 
     22        pass 
     23     
     24    def initialize(self, parameters): 
     25        '''@raise ConfigException:'''  
     26        pass 
     27        
     28    def validate(self, idpEndpoint, idpIdentity): 
     29        '''@raise IdPInvalidException: 
     30        @raise ConfigException:'''  
     31        pass 
     32 
     33 
     34class ProviderIdentifierTestValidator(IdPValidator): 
     35    def __init__(self): 
     36        pass 
     37 
     38    def initialize(self, parameters): 
     39        '''@raise ConfigException:'''  
     40        pass 
     41        
     42    def validate(self, idpEndpoint, idpIdentity): 
     43        '''@raise IdPInvalidException: 
     44        @raise ConfigException:'''  
     45        raise IdPInvalidException() 
     46 
     47 
     48class DiscoveryInfoPlaceHolder(object): 
     49    def getOPEndpoint(self): 
     50        return 'https://localhost/openid/provider' 
     51 
     52  
     53class IdentifierPlaceHolder(object): 
     54    def getIdentifier(self):  
     55        return 'myid' 
     56 
     57 
     58class IdPValidationTestCase(unittest.TestCase): 
     59    thisDir = os.path.dirname(os.path.abspath(__file__)) 
     60    idpConfigFilePath = os.path.join(thisDir, 'idpvalidator.xml') 
     61    os.environ['NDGSEC_UNITTEST_IDPVALIDATION_DIR'] = thisDir 
     62     
     63    def test01IdPConfigFileEnvVarNotSet(self): 
     64        identifier = IdentifierPlaceHolder() 
     65        discoveries = [DiscoveryInfoPlaceHolder()] 
     66         
     67        idPValidationDriver = IdPValidationDriver() 
     68        validDiscoveries = idPValidationDriver.performIdPValidation(identifier, 
     69                                                                discoveries) 
     70        # Expect no discoveries returned because the IDP_CONFIG_FILE  
     71        # environment variable is not set 
     72        self.assert_(len(validDiscoveries) == 1) 
     73         
     74 
     75    def test02(self): 
     76        identifier = IdentifierPlaceHolder() 
     77        discoveries = [DiscoveryInfoPlaceHolder()] 
     78         
     79        os.environ['IDP_CONFIG_FILE'] = IdPValidationTestCase.idpConfigFilePath 
     80        idPValidationDriver = IdPValidationDriver() 
     81        validDiscoveries = idPValidationDriver.performIdPValidation(identifier, 
     82                                                                discoveries) 
     83        self.assert_(len(validDiscoveries) == 1) 
     84         
     85if __name__ == "__main__": 
     86    unittest.main()         
Note: See TracChangeset for help on using the changeset viewer.