source: TI12-security/trunk/python/ndg.security.test/ndg/security/test/integration/openid/securedapp.py @ 5046

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

Added integration test for OpenID Relying Party and OpenID Provider in same WSGI stack.

Line 
1#!/usr/bin/env python
2"""NDG Security test harness for securing an application with OpenID middleware
3
4NERC DataGrid Project
5
6"""
7__author__ = "P J Kershaw"
8__date__ = "26/02/09"
9__copyright__ = "(C) 2009 Science and Technology Facilities Council"
10__license__ = "BSD - See top-level directory for LICENSE file."
11__contact__ = "Philip.Kershaw@stfc.ac.uk"
12__revision__ = "$Id$"
13
14class TestOpenIDMiddleware(object):
15    '''Test Application for the Authentication handler to protect'''
16    response = "Test OpenID application"
17       
18    def __init__(self, app_conf, **local_conf):
19        pass
20   
21    def __call__(self, environ, start_response):
22       
23        if 'REMOTE_USER' in environ:
24            response = """<html>
25    <head/>
26    <body>
27        <p>Authenticated!</p>
28        <p><a href="/logout">logout</a></p>
29    </body>
30</html>"""
31            start_response('200 OK', 
32                           [('Content-type', 'text/html'),
33                            ('Content-length', str(len(response)))])
34        else:
35            response = "Trigger OpenID Relying Party..."
36            start_response('401 Unauthorized', 
37                           [('Content-type', 'text/plain'),
38                            ('Content-length', str(len(response)))])
39        return [response]
40   
41# To start run
42# $ paster serve services.ini or run this file as a script
43# $ ./securedapp.py [port #]
44if __name__ == '__main__':
45    import sys
46    import os
47    from os.path import dirname, abspath
48    import logging
49    logging.basicConfig(level=logging.DEBUG)
50
51    if len(sys.argv) > 1:
52        port = int(sys.argv[1])
53    else:
54        port = 9080
55       
56    cfgFilePath = os.path.join(dirname(abspath(__file__)), 'securedapp.ini')
57       
58    from paste.httpserver import serve
59    from paste.deploy import loadapp
60   
61    app = loadapp('config:%s' % cfgFilePath)
62    serve(app, host='0.0.0.0', port=port)
Note: See TracBrowser for help on using the repository browser.