Ignore:
Timestamp:
29/09/09 15:42:02 (10 years ago)
Author:
pjkersha
Message:

Integrated automated start-up and shutdown of Paste http servers for unit tests.

Location:
TI12-security/trunk/python/ndg_security_test/ndg/security/test/unit
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • TI12-security/trunk/python/ndg_security_test/ndg/security/test/unit/__init__.py

    r5774 r5779  
    2828    sets the generic data directory path''' 
    2929    configDirEnvVarName = 'NDGSEC_TEST_CONFIG_DIR' 
     30    SITEA_ATTRIBUTEAUTHORITY_PORTNUM = 5000 
     31    SITEB_ATTRIBUTEAUTHORITY_PORTNUM = 5100 
     32    SESSIONMANAGER_PORTNUM = 5500 
    3033     
    3134    mkDataDirPath = staticmethod(mkDataDirPath) 
     35     
     36    NDGSEC_UNITTESTS_DISABLE_THREAD_SERVICES_ENVVAR = \ 
     37        'NDGSEC_UNITTESTS_DISABLE_THREAD_SERVICES' 
     38     
     39    _disableServiceStartup = lambda self: bool(os.environ.get( 
     40        BaseTestCase.NDGSEC_UNITTESTS_DISABLE_THREAD_SERVICES_ENVVAR)) 
     41     
     42    disableServiceStartup = property(fget=_disableServiceStartup, 
     43                                     doc="Stop automated start-up of services " 
     44                                         "for unit tests") 
    3245     
    3346    def __init__(self, *arg, **kw): 
     
    3851        self.services = [] 
    3952         
    40     def addService(self, cfgFilePath, port): 
     53    def addService(self, *arg, **kw): 
    4154        """Utility for setting up threads to run Paste HTTP based services with 
    4255        unit tests 
     
    4760        @type port: int 
    4861        """ 
     62        if self.disableServiceStartup: 
     63            return 
     64         
    4965        try: 
    50             self.services.append(PasteDeployAppServer(cfgFilePath, port=port)) 
     66            self.services.append(PasteDeployAppServer(*arg, **kw)) 
    5167            self.services[-1].startThread() 
    5268             
     
    5975                                              'sitea',  
    6076                                              'site-a.ini')) 
    61         self.addService(siteACfgFilePath, 5000) 
     77        self.addService(cfgFilePath=siteACfgFilePath,  
     78                        port=BaseTestCase.SITEA_ATTRIBUTEAUTHORITY_PORTNUM) 
    6279         
    6380        siteBCfgFilePath = mkDataDirPath(join('attributeauthority', 
    6481                                              'siteb',  
    6582                                              'site-b.ini')) 
    66         self.addService(siteBCfgFilePath, 5100)         
     83        self.addService(cfgFilePath=siteBCfgFilePath,  
     84                        port=BaseTestCase.SITEB_ATTRIBUTEAUTHORITY_PORTNUM)         
     85 
     86    def startSessionManager(self): 
     87        """Serve test Session Manager service""" 
     88        cfgFilePath = mkDataDirPath(join('sessionmanager',  
     89                                         'session-manager.ini')) 
     90        self.addService(cfgFilePath=cfgFilePath,  
     91                        port=BaseTestCase.SESSIONMANAGER_PORTNUM) 
    6792         
    6893 
  • TI12-security/trunk/python/ndg_security_test/ndg/security/test/unit/openid/relyingparty/validation/idpvalidator.xml

    r5497 r5779  
    99--> 
    1010<IdPValidators xmlns="urn:esg:security:authz:1.0:IdPValidator"> 
    11     <validator name="test_validation.ProviderWhitelistValidator"> 
     11    <validator 
     12     name="ndg.security.test.unit.openid.relyingparty.validation.test_validation.ProviderWhitelistValidator"> 
    1213        <parameter name="config-file" value="$NDGSEC_UNITTEST_IDPVALIDATION_DIR/providerWhitelist.cfg"/> 
    1314    </validator> 
    14     <validator name="test_validation.ProviderIdentifierTestValidator"> 
     15    <validator  
     16     name="ndg.security.test.unit.openid.relyingparty.validation.test_validation.ProviderIdentifierTestValidator"> 
    1517        <parameter name="config-file" value="$NDGSEC_UNITTEST_IDPVALIDATION_DIR/providerIdentifierWhitelist.cfg"/> 
    1618    </validator> 
  • TI12-security/trunk/python/ndg_security_test/ndg/security/test/unit/openid/relyingparty/validation/test_validation.py

    r5499 r5779  
    5151 
    5252class DiscoveryInfoPlaceHolder(object): 
    53     def getOPEndpoint(self): 
    54         return 'https://localhost/openid/provider' 
     53    getOPEndpoint = lambda self: 'https://localhost/openid/provider' 
    5554 
    5655  
    5756class IdentifierPlaceHolder(object): 
    58     def getIdentifier(self):  
    59         return 'myid' 
     57    getIdentifier = lambda self: 'myid' 
    6058 
    6159from M2Crypto import X509 
  • TI12-security/trunk/python/ndg_security_test/ndg/security/test/unit/sessionmanager/test_sessionmanager.py

    r5648 r5779  
    4141    passphrase = None 
    4242    test4Passphrase = None 
    43      
     43 
     44    def __init__(self, *arg, **kw): 
     45        super(SessionManagerTestCase, self).__init__(*arg, **kw) 
     46        self.startAttributeAuthorities() 
     47 
    4448    def setUp(self): 
    4549        super(SessionManagerTestCase, self).setUp() 
  • TI12-security/trunk/python/ndg_security_test/ndg/security/test/unit/sessionmanagerclient/test_sessionmanagerclient.py

    r5290 r5779  
    4646    test01Passphrase = None 
    4747    test03Passphrase = None 
     48 
     49    def __init__(self, *arg, **kw): 
     50        super(SessionManagerClientTestCase, self).__init__(*arg, **kw) 
     51        self.startSessionManager() 
     52        self.startAttributeAuthorities() 
    4853 
    4954    def _getCertChainFromProxyCertFile(self, certChainFilePath): 
  • TI12-security/trunk/python/ndg_security_test/ndg/security/test/unit/soap/test_soap.py

    r5527 r5779  
    1919from urllib2 import HTTPHandler, URLError 
    2020 
     21from ndg.security.test.unit import BaseTestCase 
    2122from ndg.security.common.soap.etree import SOAPEnvelope 
    2223from ndg.security.common.soap.client import UrlLib2SOAPClient, \ 
     
    2526class SOAPBindingMiddleware(object): 
    2627    """Simple WSGI interface for SOAP service""" 
    27      
     28         
    2829    def __call__(self, environ, start_response): 
    2930        requestFile = environ['wsgi.input'] 
     
    4243     
    4344     
    44 class SOAPTestCase(unittest.TestCase): 
    45     endpoint = 'http://localhost:10080/soap' 
     45class SOAPTestCase(BaseTestCase): 
     46    SOAP_SERVICE_PORTNUM = 10080 
     47    ENDPOINT = 'http://localhost:%d/soap' % SOAP_SERVICE_PORTNUM 
    4648     
    4749    def __init__(self, *args, **kwargs): 
     
    5052        self.app = paste.fixture.TestApp(wsgiApp) 
    5153          
    52         unittest.TestCase.__init__(self, *args, **kwargs) 
     54        super(SOAPTestCase, self).__init__(*args, **kwargs) 
    5355         
    5456    def test01Envelope(self): 
     
    8789         
    8890        # Paster based service must be running in separate script 
     91        self.addService(app=SOAPBindingMiddleware(),  
     92                        port=SOAPTestCase.SOAP_SERVICE_PORTNUM) 
     93         
    8994        client = UrlLib2SOAPClient() 
    9095         
     
    9398         
    9499        request = UrlLib2SOAPRequest() 
    95         request.url = SOAPTestCase.endpoint 
     100        request.url = SOAPTestCase.ENDPOINT 
    96101        request.envelope = SOAPEnvelope() 
    97102        request.envelope.create() 
  • TI12-security/trunk/python/ndg_security_test/ndg/security/test/unit/wsgi/__init__.py

    r5774 r5779  
    2121    """Wrapper to paste.httpserver to enable background threading""" 
    2222     
    23     def __init__(self, cfgFilePath, port=7443, host='0.0.0.0'): 
     23    def __init__(self, app=None, cfgFilePath=None, port=7443, host='0.0.0.0'): 
    2424        """Load an application configuration from cfgFilePath ini file and  
    2525        instantiate Paste server object 
    2626        """        
    2727        self.__thread = None 
    28         fileConfig(cfgFilePath) 
    29         app = loadapp('config:%s' % cfgFilePath) 
     28         
     29        if cfgFilePath: 
     30            fileConfig(cfgFilePath) 
     31            app = loadapp('config:%s' % cfgFilePath) 
     32             
     33        elif app is None: 
     34            raise KeyError('Either the "cfgFilePath" or "app" keyword must be ' 
     35                           'set') 
     36             
    3037        self.__pasteServer = paste.httpserver.serve(app, host=host, port=port,  
    3138                                                    start_loop=False) 
  • TI12-security/trunk/python/ndg_security_test/ndg/security/test/unit/wsgi/attributeauthority/test.ini

    r5644 r5779  
    1919 
    2020[filter:AttributeAuthorityFilter] 
    21 paste.filter_app_factory = ndg.security.server.wsgi.attributeauthority:AttributeAuthorityMiddleware 
     21paste.filter_app_factory = ndg.security.server.wsgi.attributeauthority:AttributeAuthorityMiddleware.filter_app_factory 
    2222prefix = attributeauthority. 
    2323 
  • TI12-security/trunk/python/ndg_security_test/ndg/security/test/unit/wsgi/authn/test_authn.py

    r5766 r5779  
    120120                                'test.crt') 
    121121        sslClientCert = X509Cert.Read(sslClientCertFilePath).toString() 
    122         extra_environ = {'HTTPS':'1', 'SSL_CLIENT_CERT': sslClientCert} 
     122         
     123        # Add APache SSL environment variables and sdummy AuthKit set user 
     124        # session cookie method 
     125        extra_environ = { 
     126            'HTTPS':'1',  
     127            'SSL_CLIENT_CERT': sslClientCert, 
     128            AuthKitSSLAuthnMiddleware.SET_USER_ENVIRON_KEYNAME: lambda id: None 
     129            } 
    123130 
    124131        print("request secured URI '/test_sslClientAuthn' ...") 
  • TI12-security/trunk/python/ndg_security_test/ndg/security/test/unit/wsgi/ssl/test.ini

    r5774 r5779  
    2121paste.filter_app_factory = ndg.security.server.wsgi.ssl:ApacheSSLAuthnMiddleware 
    2222prefix = ssl. 
    23 caCertFilePathList = %(testConfigDir)s/ca/ndg-test-ca.crt 
    24 clientCertVerificationClassName =  
    25 rePathMatchList = ^/secured/.*$ ^/restrict.* 
     23ssl.caCertFilePathList = %(testConfigDir)s/ca/ndg-test-ca.crt 
     24ssl.rePathMatchList = ^/secured/.*$ ^/restrict.* 
     25ssl.clientCertDNMatchList = /O=NDG/OU=BADC/CN=test /O=localhost/OU=local/CN=test2 
Note: See TracChangeset for help on using the changeset viewer.