source: TI12-security/trunk/python/ndg.security.test/ndg/security/test/combinedservices/serverapp.py @ 4501

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.test/ndg/security/test/combinedservices/serverapp.py@4501
Revision 4501, 2.4 KB checked in by pjkersha, 11 years ago (diff)

New ndg.security.server.wsgi.utils package to hold Session Manager and Attribute Authority client wrappers. These check environ for a local SM/AA instance or call a remote service if a URI is given.

  • Added a test for Combined Services unit test to try out a Session Manager connect using the new wrapper.
Line 
1#!/usr/bin/env python
2"""NDG Security test harness for Ccombined Session Manager and Attribute
3Authority services running under a single Paste instance.
4
5NERC Data Grid Project
6
7This software may be distributed under the terms of the Q Public License,
8version 1.0 or later.
9"""
10__author__ = "P J Kershaw"
11__date__ = "20/11/08"
12__copyright__ = "(C) 2008 STFC & NERC"
13__contact__ = "Philip.Kershaw@stfc.ac.uk"
14__revision__ = "$Id$"
15import os
16from ndg.security.server.wsgi.utils.sessionmanagerclient import \
17    WSGISessionManagerClient
18   
19class InfoApp(object):
20    method = {
21        "/": 'default',
22        "/test_connect": "test_connect"
23    }
24   
25    def __call__(self, environ, start_response):
26       
27        methodName = self.method.get(environ['PATH_INFO'], '').rstrip()
28        if methodName:
29            action = getattr(self, methodName)
30            return action(environ, start_response)
31        else:
32            start_response('404 Not Found', [('Content-type', 'text/plain')])
33            return "NDG Security Combined Services Unit tests: invalid URI"
34           
35    def default(self, environ, start_response):
36        start_response('200 OK', [('Content-type', 'text/plain')])
37        return "NDG Security Combined Services Unit Tests"
38
39    def test_connect(self, environ, start_response):
40       
41        client = WSGISessionManagerClient(environ=environ)
42        res = client.connect("testuser", passphrase="testpassword")
43        start_response('200 OK', [('Content-type', 'text/plain')])
44        return "test_connect succeeded"
45       
46def app_factory(global_config, **local_conf):
47    return InfoApp()
48
49
50# Initialize environment for unit tests
51if 'NDGSEC_COMBINED_SRVS_UNITTEST_DIR' not in os.environ:
52    os.environ['NDGSEC_COMBINED_SRVS_UNITTEST_DIR'] = \
53                                    os.path.abspath(os.path.dirname(__file__))
54   
55# To start the Site A Attribute Authority run
56# $ paster serve site-a.ini or run this file as a script
57# $ ./siteAServerApp.py [port #]
58if __name__ == '__main__':
59    import sys
60    import logging
61    logging.basicConfig(level=logging.DEBUG)
62
63    if len(sys.argv) > 1:
64        port = int(sys.argv[1])
65    else:
66        port = 8000
67       
68    cfgFilePath = os.path.join(os.path.dirname(os.path.abspath(__file__)),
69                               'services.ini')
70       
71    from paste.httpserver import serve
72    from paste.deploy import loadapp
73
74    app = loadapp('config:%s' % cfgFilePath)
75    serve(app, host='0.0.0.0', port=port)
Note: See TracBrowser for help on using the repository browser.