source: TI12-security/trunk/python/ndg.security.test/ndg/security/test/integration/authz/securedapp.py @ 5016

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.test/ndg/security/test/integration/authz/securedapp.py@5017
Revision 5016, 1.9 KB checked in by pjkersha, 11 years ago (diff)

Rearranged authz integration tests to run two application servers: one simulating an application stack to be secured, the other a stack of security services to perform authentication / authorization.

Line 
1class TestAuthNMiddleware(object):
2    '''Test Application for the Authentication handler to protect'''
3    response = "Test Authentication redirect application"
4       
5    def __init__(self, app_conf, **local_conf):
6        pass
7   
8    def __call__(self, environ, start_response):
9       
10        if environ['PATH_INFO'] == '/test_401WithNotLoggedIn':
11            status = "401 Unauthorized"
12           
13        elif environ['PATH_INFO'] == '/test_401WithLoggedIn':
14            status = "401 Unauthorized"
15            environ['REMOTE_USER'] = 'testuser'           
16           
17        elif environ['PATH_INFO'] == '/test_200WithNotLoggedIn':
18            status = "200 OK"
19           
20        elif environ['PATH_INFO'] == '/test_200WithLoggedIn':
21            environ['REMOTE_USER'] = 'testuser'
22            status = "200 OK"
23        else:
24            status = "404 Not found"
25               
26        start_response(status,
27                       [('Content-length', 
28                         str(len(TestAuthNMiddleware.response))),
29                        ('Content-type', 'text/plain')])
30        return [TestAuthNMiddleware.response]
31   
32def app_factory(globalConfig, **localConfig):
33    return AuthZTestMiddleware(None, globalConfig, **localConfig)
34
35def filter_app_factory(app, globalConfig, **localConfig):
36    return AuthZTestMiddleware(app, globalConfig, **localConfig)
37   
38# To start run
39# $ paster serve services.ini or run this file as a script
40# $ ./securedapp.py [port #]
41if __name__ == '__main__':
42    import sys
43    import logging
44    logging.basicConfig(level=logging.DEBUG)
45
46    if len(sys.argv) > 1:
47        port = int(sys.argv[1])
48    else:
49        port = 80080
50       
51    cfgFilePath = os.path.join(dirname(abspath(__file__)), 'securedapp.ini')
52       
53    from paste.httpserver import serve
54    from paste.deploy import loadapp
55   
56    app = loadapp('config:%s' % cfgFilePath)
57    serve(app, host='0.0.0.0', port=port)
Note: See TracBrowser for help on using the repository browser.