source: TI12-security/trunk/NDGSecurity/python/ndg_security_test/ndg/security/test/integration/full_system/securityservicesapp.py @ 7829

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDGSecurity/python/ndg_security_test/ndg/security/test/integration/full_system/securityservicesapp.py@7829
Revision 7829, 2.6 KB checked in by pjkersha, 10 years ago (diff)

Incomplete - task 16: NDG Security 2.x.x - incl. updated Paster templates

  • Completed Attribute Service template and tested standalone
  • Property svn:keywords set to Id
Line 
1#!/usr/bin/env python
2"""NDG Security test harness for security web services middleware stack
3
4NERC DataGrid Project
5
6"""
7__author__ = "P J Kershaw"
8__date__ = "20/11/08"
9__copyright__ = "(C) 2009 Science and Technology Facilities Council"
10__contact__ = "Philip.Kershaw@stfc.ac.uk"
11__revision__ = "$Id$"
12import os
13from os.path import dirname, abspath, join
14import optparse 
15     
16from OpenSSL import SSL
17
18from ndg.security.test.unit import BaseTestCase, TEST_CONFIG_DIR
19from ndg.security.test.unit.wsgi import PasteDeployAppServer
20
21INI_FILENAME = 'securityservices.ini'
22
23os.environ['NDGSEC_INTEGRATION_TEST_DIR'] = os.path.dirname(os.path.dirname(
24                                                                    __file__))
25os.environ[BaseTestCase.configDirEnvVarName] = TEST_CONFIG_DIR
26
27
28
29# To start run
30# $ paster serve services.ini or run this file as a script, see
31# $ ./securityservicesapp.py -h
32if __name__ == '__main__':   
33    cfgFileName = INI_FILENAME
34    cfgFilePath = os.path.join(dirname(abspath(__file__)), cfgFileName) 
35       
36    parser = optparse.OptionParser()
37    parser.add_option("-p",
38                      "--port",
39                      dest="port",
40                      default=7443,
41                      type='int',
42                      help="port number to run under")
43
44    parser.add_option("-s",
45                      "--with-ssl",
46                      dest="withSSL",
47                      default='True',
48                      help="Run with SSL")
49
50    parser.add_option("-c",
51                      "--conf",
52                      dest="configFilePath",
53                      default=cfgFilePath,
54                      help="Configuration file path")
55   
56    # Initialise test user database
57    from ndg.security.test.unit import BaseTestCase
58    BaseTestCase.initDb()
59   
60    opt = parser.parse_args()[0]
61   
62    if opt.withSSL.lower() == 'true':
63        certFilePath = os.path.join(BaseTestCase.NDGSEC_TEST_CONFIG_DIR, 
64                                    'pki', 
65                                    'localhost.crt')
66        priKeyFilePath = os.path.join(BaseTestCase.NDGSEC_TEST_CONFIG_DIR, 
67                                      'pki', 
68                                      'localhost.key')
69       
70        ssl_context = SSL.Context(SSL.SSLv23_METHOD)
71        ssl_context.set_options(SSL.OP_NO_SSLv2)
72   
73        ssl_context.use_privatekey_file(priKeyFilePath)
74        ssl_context.use_certificate_file(certFilePath)
75    else:
76        ssl_context = None
77
78    server = PasteDeployAppServer(cfgFilePath=opt.configFilePath, 
79                                  port=opt.port,
80                                  ssl_context=ssl_context) 
81    server.start()
Note: See TracBrowser for help on using the repository browser.