source: TI12-security/trunk/python/ndg.security.test/ndg/security/test/SessionMgr/SessionMgrClientTest.py @ 1945

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.test/ndg/security/test/SessionMgr/SessionMgrClientTest.py@1945
Revision 1945, 8.2 KB checked in by pjkersha, 13 years ago (diff)

python/ndg.security.server/ndg/security/server/SessionMgr/init.py: started refactoring of connect, addUser
and reqAuthorisation methods to allow for new ZSI code, doc-lit. WSDL, WS-Security and new MyProxy? client.

python/ndg.security.server/ndg/security/server/MyProxy.py,
python/ndg.security.test/ndg/security/test/MyProxy/myProxyClientTest.cfg and
python/ndg.security.test/ndg/security/test/MyProxy/MyProxyClientTest.py: changed store method to include explicit
passphrase argument.

python/ndg.security.test/ndg/security/test/SessionMgr/SessionMgrClientTest.py: moved from test/ into a dedicated
module directory.

python/ndg.security.test/ndg/security/test/XMLSecDoc/*: unit test for new XMLSecDoc class which implements
enveloped signature using M2Crypto, ZSI and DOM rather than pyXMLSec as before.

python/Tests/MyProxyClient/m2CryptoMyPxClnt.py: allow client post connection check - i.e. commented out:
conn.clientPostConnectionCheck = None

python/ndg.security.common/ndg/security/common/XMLMsg.py: no longer needed with new version of ZSI + use of
WS-Security.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2
3"""Test harness for NDG Session Manager client - makes requests for
4authentication and authorisation.  An Attribute Authority and Simple CA
5services must be running for the reqAuthorisation and addUser tests
6
7NERC Data Grid Project
8
9P J Kershaw 23/02/06
10
11Renamed from SessionClientTest.py 27/0/4/06
12Moved and renamed SessionMgrClientTest.py 23/11/06
13
14Copyright (C) 2006 CCLRC & NERC
15
16This software may be distributed under the terms of the Q Public License,
17version 1.0 or later.
18"""
19import unittest
20import os, sys
21 
22from ndg.security.common.SessionMgr import SessionMgrClient
23from ndg.security.common.SessionCookie import SessionCookie
24
25
26class SessionMgrClientTestCase(unittest.TestCase):
27   
28    def setUp(self):
29        self.config = {}
30
31        testConfig = {}
32        #testConfig['smURI'] = 'https://192.100.78.199:5700/SessionManager'
33        #testConfig['smURI'] = 'http://glue.badc.rl.ac.uk/SessionManager'
34        #testConfig['smURI'] = 'https://glue.badc.rl.ac.uk/SessionManager'
35        #testConfig['smURI'] = 'https://localhost:5700/SessionManager'
36        #testConfig['smURI'] = 'https://192.100.78.135:5700/SessionManager'
37        testConfig['smURI'] = 'https://glue.badc.rl.ac.uk/SessionManager'
38        testConfig['aaURI'] = 'https://localhost:5000/AttributeAuthority'
39
40       
41        testConfig['newUserName'] = 'BugsBunny' 
42        testConfig['newUsernamePPhrase'] = open('./tmp1').read().strip()           
43        testConfig['userName'] = 'gabriel'
44        testConfig['userNamePPhrase'] = open('./tmp2').read().strip()
45        testConfig['trustedHostRequiredRole'] = 'academic'
46
47        testConfig['aaCertFilePath'] = None
48
49        # Public key of session manager used to encrypt requests
50        # If no public key is set, it will be retrieved using the
51        # getCert WS method
52        testConfig['smCertFilePath'] = '../../../../Tests/webSphereTestcert.pem'
53
54        testConfig['clntPriKeyPwd'] = open("./tmp3").read().strip()
55
56        testConfig['clntCertFilePath'] = None
57        testConfig['clntPriKeyFilePath'] = '../../../../Tests/webSphereTestkey.pem'
58       
59
60        # Uncomment for required test
61        self.config = testConfig
62        #self.config = glueConfig
63
64        tracefile = sys.stderr
65       
66        # Initialise the Session Manager client connection
67        # Omit traceFile keyword to leave out SOAP debug info
68        self.clnt = SessionMgrClient(uri=self.config['smURI'],
69                        smCertFilePath=self.config['smCertFilePath'],
70                        clntCertFilePath=self.config['clntCertFilePath'],
71                        clntPriKeyFilePath=self.config['clntPriKeyFilePath'],
72                        clntPriKeyPwd=self.config['clntPriKeyPwd'],
73                        tracefile=tracefile) 
74       
75        self.sessCookie = None
76        self.proxyCert = None
77
78
79    def testAddUser(self):
80        """Add a new user ID to the MyProxy repository"""
81       
82        # Note the pass-phrase is read from the file tmp.  To pass
83        # explicitly as a string use the 'pPhrase' keyword instead
84        self.clnt.addUser(self.config['newUserName'], 
85                          pPhrase=self.config['newUsernamePPhrase'])
86        print "Added user '%s'" % self.config['newUserName']
87       
88
89    def testCookieConnect(self):
90        """testCookieConnect: Connect as if acting as a browser client -
91        a cookie is returned"""
92        #import pdb;pdb.set_trace()
93        # Note the pass-phrase is read from the file tmp.  To pass
94        # explicitly as a string use the 'pPhrase' keyword instead
95        sSessCookie = self.clnt.connect(self.config['userName'], 
96                                    pPhrase=self.config['userNamePPhrase'])
97
98        self.sessCookie = SessionCookie(sSessCookie)
99        print "User '%s' connected to Session Manager:\n%s" % \
100            (self.config['userName'], sSessCookie)
101           
102
103    def testProxyCertConnect(self):
104        """testProxyCertConnect: Connect as a command line client -
105        a proxyCert is returned"""
106
107        self.proxyCert = self.clnt.connect(self.config['userName'], 
108                                      pPhrase=self.config['userNamePPhrase'],
109                                      createServerSess=True,
110                                      getCookie=False)
111        print "User '%s' connected to Session Manager:\n%s" % \
112            (self.config['userName'], self.proxyCert)
113           
114
115    def testCookieDisconnect(self):
116        """testCookieDisconnect: disconnect as if acting as a browser client -
117        a cookie is returned"""
118       
119        self.testCookieConnect()
120       
121        self.clnt.disconnect(sessCookie=str(self.sessCookie))
122        print "User disconnected from Session Manager:\n%s" % self.sessCookie
123           
124
125    def testProxyCertDisconnect(self):
126        """testProxyCertDisconnect: Connect as a command line client -
127        a proxyCert is returned"""
128       
129        self.testProxyCertConnect()
130           
131        self.clnt.disconnect(proxyCert=self.proxyCert)
132        print "User disconnected from Session Manager:\n%s" % self.proxyCert
133
134
135    def testCookieReqAuthorisation(self):
136        """testCookieReqAuthorisation: make an authorisation request using
137        a cookie as authentication credential"""
138       
139        self.testCookieConnect()
140        attCert, statusCode, extAttCertList = self.clnt.reqAuthorisation(\
141                        sessID=self.sessCookie.sessionID, 
142                        attAuthorityURI=self.config['aaURI'],
143                        encrSessionMgrURI=self.sessCookie.encrSessionMgrURI)
144       
145        print "Attribute Certificate:\n%s" % attCert 
146        print "User authorisation: %s" % statusCode
147        print "External Attribute Certificate List:\n%s" % extAttCertList
148
149
150    def testCookieReqAuthorisationWithExtAttCertList(self):
151        """testCookieReqAuthorisation: make an authorisation request using
152        a cookie as authentication credential"""
153       
154        self.testCookieConnect()
155        attCert, statusCode, extAttCertList = self.clnt.reqAuthorisation(\
156                        sessID=self.sessCookie.sessionID, 
157                        attAuthorityURI=self.config['aaURI'],
158                        encrSessionMgrURI=self.sessCookie.encrSessionMgrURI,
159                        extAttCertList=['AC1', 'AC2', 'AC3'])
160         
161        print "Attribute Certificate:\n%s" % attCert 
162        print "User authorisation: %s" % statusCode
163        print "External Attribute Certificate List:\n%s" % extAttCertList
164
165
166    def testProxyCertReqAuthorisation(self):
167        """testProxyCertReqAuthorisation: make an authorisation request using
168        a proxy cert as authentication credential"""
169        self.testProxyCertConnect()
170       
171        # Request an attribute certificate from an Attribute Authority
172        # using the proxyCert returned from connect()
173        attCert, statusCode, extAttCertList = self.clnt.reqAuthorisation(\
174                                         proxyCert=self.proxyCert,
175                                         attAuthorityURI=self.config['aaURI'])
176         
177        print "Attribute Certificate:\n%s" % attCert 
178        print "User authorisation: %s" % statusCode
179        print "External Attribute Certificate List:\n%s" % extAttCertList
180
181
182    def testGetX509Cert(self):
183        "testGetX509Cert: return the Session Manager's X.509 Cert."
184        cert = self.clnt.getX509Cert()
185                                             
186        print "Session Manager X.509 Certificate:\n" + cert
187           
188           
189#_____________________________________________________________________________       
190class SessionMgrClientTestSuite(unittest.TestSuite):
191   
192    def __init__(self):
193        map = map(SessionMgrClientTestCase,
194                  (
195                    "testAddUser",
196                    "testCookieConnect",
197                    "testProxyCertConnect",
198                    "testCookieDisconnect",
199                    "testProxyCertDisconnect",
200                    "testCookieReqAuthorisation",
201                    "testProxyCertReqAuthorisation",
202                    "testGetX509Cert",
203                  ))
204        unittest.TestSuite.__init__(self, map)
205           
206                                                   
207if __name__ == "__main__":
208    unittest.main()       
Note: See TracBrowser for help on using the repository browser.