source: TI12-security/trunk/python/ndg.security.test/ndg/security/test/authenservice/test_authen_service.py @ 4158

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.test/ndg/security/test/authenservice/test_authen_service.py@4158
Revision 4158, 4.1 KB checked in by cbyrom, 11 years ago (diff)

Create new utility module, ClassFactory? - to allow generic instantiation
of classes dynamically.

Implement use of this in the AttAuth? and SessionMgr? services + adjust
the config files for these accordingly + abstract use of MyProxy? in
SessionMgr? to generic authNService - and create packages with real
and test authN services. Adjust the SessionMgr? tests to use the
test authN service.

Line 
1"""
2Abstract proxy class - to act as an 'interface' to use for proxy clients
3
4NERC Data Grid Project
5"""
6__author__ = "C Byrom - Tessella"
7__date__ = "28/08/08"
8__copyright__ = "(C) 2008 STFC & NERC"
9__license__ = \
10"""This software may be distributed under the terms of the Q Public
11License, version 1.0 or later."""
12__contact__ = "P.J.Kershaw@rl.ac.uk"
13__revision__ = '$Id: $'
14
15from ndg.security.server.SessionMgr import AbstractAutheNService
16
17import logging, os, sys
18log = logging.getLogger(__name__)
19
20#_____________________________________________________________________________
21class TestAutheNService(AbstractAutheNService):
22    """
23    A simple test proxy client with the methods stubbed out to allow
24    for use in testing SessionMgr
25    - NB, the stubbed out methods here are overkill in terms of the AbstractAutheNService
26    interface - they are included to dummy out the MyProxy methods - in case
27    further testing is implemented of this in future.
28    """
29    NDG_SEC_DIR_ENV_VAR = '$NDGSEC_DIR'
30    NDG_SEC_DIR = os.path.expandvars(NDG_SEC_DIR_ENV_VAR)
31
32    TEST_PROXY_CERT_FILE = NDG_SEC_DIR + "/authenservice/sm.crt"
33    TEST_PROXY_CERT2_FILE = NDG_SEC_DIR + "/myProxy/ndg-test-ca.crt"
34    TEST_PROXY_KEY_FILE = NDG_SEC_DIR + "/authenservice/sm.key"
35    TEST_USER_CERT_FILE = NDG_SEC_DIR + "/myProxy/user.crt"
36    INFO_ERROR_MESSAGE = "INFO_ERROR_MESSAGE"
37    START_DATE = "START_DATE"
38    END_DATE = "END_DATE"
39    CERT_OWNER = "CERT_OWNER"
40    TEST_CERT_CHAIN = []
41
42    def __init__(self, propFilePath=None, **prop):
43        log.info("TestAutheNService __init__() called")
44        log.info("Loading in the various cert and key data...")
45        if self.NDG_SEC_DIR == self.NDG_SEC_DIR_ENV_VAR or not self.NDG_SEC_DIR:
46            raise SystemError("The '$NDGSEC_DIR' environment variable is not set up\
47                - please set this before running the tests")
48           
49        f = open(self.TEST_PROXY_CERT_FILE, 'r')
50        self.TEST_PROXY_CERT = f.read()
51        f.close
52        f = open(self.TEST_PROXY_CERT2_FILE, 'r')
53        self.TEST_PROXY_CERT2 = f.read()
54        f.close
55        f = open(self.TEST_PROXY_KEY_FILE, 'r')
56        self.TEST_PROXY_KEY = f.read()
57        f.close
58        f = open(self.TEST_USER_CERT_FILE, 'r')
59        self.TEST_USER_CERT = f.read()
60        f.close
61       
62        log.info("Finished loading all required data")
63
64    def writeProxyFile(cls, proxyCert, proxyPriKey, userCert, filePath=None):
65        log.info("TestAutheNService writeProxyFile() called")
66
67    def readProxyFile(cls, filePath=None):
68        log.info("TestAutheNService writeProxyFile() called")
69        return tuple(self.TEST_PROXY_CERT, self.TEST_PROXY_KEY, self.TEST_USER_CERT)
70
71    def setProperties(self, **prop):
72        log.info("TestAutheNService setProperties() called")
73
74
75    def info(self,
76             username, 
77             ownerCertFile=None,
78             ownerKeyFile=None,
79             ownerPassphrase=None):
80        log.info("TestAutheNService setProperties() called")
81        return True, self.INFO_ERROR_MESSAGE, [self.START_DATE, self.END_DATE, self.CERT_OWNER]
82
83
84    def changePassphrase(self,
85                         username, 
86                         passphrase,
87                         newPassphrase,
88                         ownerCertFile=None,
89                         ownerKeyFile=None,
90                         ownerPassphrase=None):
91        log.info("TestAutheNService changePassphrase() called")
92
93
94    def destroy(self,
95                username, 
96                ownerCertFile=None,
97                ownerKeyFile=None,
98                ownerPassphrase=None):
99        log.info("TestAutheNService destroy() called")
100
101
102    def store(self,
103              username,
104              passphrase, 
105              certFile,
106              keyFile,
107              ownerCertFile=None,
108              ownerKeyFile=None,
109              ownerPassphrase=None,
110              lifetime=None,
111              force=True):
112        log.info("TestAutheNService store() called")
113
114
115    def logon(self, username, passphrase, lifetime=None):
116        log.info("TestAutheNService store() called")
117        return tuple([self.TEST_PROXY_CERT, self.TEST_PROXY_KEY, self.TEST_CERT_CHAIN])
118
119                         
Note: See TracBrowser for help on using the repository browser.