source: TI12-security/trunk/python/ndg.security.test/ndg/security/test/sslclientauthnmiddleware/sslclientauthnapp.py @ 4738

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.test/ndg/security/test/sslclientauthnmiddleware/sslclientauthnapp.py@5053
Revision 4738, 1.5 KB checked in by pjkersha, 11 years ago (diff)

Refactored WSGI SSL Client AuthN unit tests separating out test files into the config dir.

Line 
1import logging
2logging.basicConfig(level=logging.DEBUG)
3import os
4from os.path import dirname, abspath, join
5
6from ndg.security.server.wsgi.apploader import AppLoaderMiddleware
7
8def application(environ, start_response):
9    status = '200 OK'
10    output = 'Access allowed to this URL'
11
12    response_headers = [('Content-type', 'text/plain'),
13                        ('Content-Length', str(len(output)))]
14    start_response(status, response_headers)
15
16    return [output]
17
18def app_factory(app_conf, **local_conf):
19    return application
20
21from ndg.security.test import BaseTestCase
22
23# Initialize environment for unit tests
24if BaseTestCase.configDirEnvVarName not in os.environ:
25    os.environ[BaseTestCase.configDirEnvVarName] = \
26                            join(dirname(abspath(dirname(__file__))), 'config')
27
28# Initialize environment for unit tests
29if 'NDGSEC_SSLCLNTAUTHN_UNITTEST_DIR' not in os.environ:
30    os.environ['NDGSEC_SSLCLNTAUTHN_UNITTEST_DIR'] = \
31                                    os.path.abspath(os.path.dirname(__file__))
32                                   
33if __name__ == '__main__':
34    import sys
35    from paste.httpserver import serve
36
37    if len(sys.argv) > 1:
38        port = int(sys.argv[1])
39    else:
40        port = 7000
41       
42    cfgFilePath = os.path.join(os.path.dirname(os.path.abspath(__file__)),
43                               'test.ini')
44   
45    sslPEM = os.environ['NDGSEC_SSLCLNTAUTHN_UNITTEST_DIR']+'/localhost.pem'
46    app = AppLoaderMiddleware(configFilePath=cfgFilePath)
47    serve(app, host='0.0.0.0', port=port, ssl_pem=sslPEM)
Note: See TracBrowser for help on using the repository browser.