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

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

test/SessionMgrClientTest.py: test different URIs for external connectivity tests.
Tests/Echo/?*.py: test encryption + signature.

  • 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://glue.badc.rl.ac.uk/SessionManager'#'https://localhost:5700/SessionManager'
33        testConfig['smURI'] = 'https://192.100.78.199:5700/SessionManager'
34        testConfig['aaURI'] = 'https://localhost:5000/AttributeAuthority'
35
36       
37        testConfig['newUserName'] = 'BugsBunny' 
38        testConfig['newUsernamePPhrase'] = open('./tmp1').read().strip()           
39        testConfig['userName'] = 'gabriel'
40        testConfig['userNamePPhrase'] = open('./tmp2').read().strip()
41        testConfig['trustedHostRequiredRole'] = 'academic'
42
43        testConfig['aaCertFilePath'] = None
44
45        # Public key of session manager used to encrypt requests
46        # If no public key is set, it will be retrieved using the
47        # getCert WS method
48        testConfig['smCertFilePath'] = '../../../../Tests/webSphereTestcert.pem'
49
50        testConfig['clntPriKeyPwd'] = open("./tmp3").read().strip()
51
52        testConfig['clntCertFilePath'] = None
53        testConfig['clntPriKeyFilePath'] = '../../../../Tests/webSphereTestkey.pem'
54       
55
56        # Uncomment for required test
57        self.config = testConfig
58        #self.config = glueConfig
59
60        tracefile = sys.stderr
61       
62        # Initialise the Session Manager client connection
63        # Omit traceFile keyword to leave out SOAP debug info
64        self.clnt = SessionMgrClient(uri=self.config['smURI'],
65                        smCertFilePath=self.config['smCertFilePath'],
66                        clntCertFilePath=self.config['clntCertFilePath'],
67                        clntPriKeyFilePath=self.config['clntPriKeyFilePath'],
68                        clntPriKeyPwd=self.config['clntPriKeyPwd'],
69                        tracefile=tracefile) 
70       
71        self.sessCookie = None
72        self.proxyCert = None
73
74
75    def testAddUser(self):
76        """Add a new user ID to the MyProxy repository"""
77       
78        # Note the pass-phrase is read from the file tmp.  To pass
79        # explicitly as a string use the 'pPhrase' keyword instead
80        self.clnt.addUser(self.config['newUserName'], 
81                          pPhrase=self.config['newUsernamePPhrase'])
82        print "Added user '%s'" % self.config['newUserName']
83       
84
85    def testCookieConnect(self):
86        """testCookieConnect: Connect as if acting as a browser client -
87        a cookie is returned"""
88        #import pdb;pdb.set_trace()
89        # Note the pass-phrase is read from the file tmp.  To pass
90        # explicitly as a string use the 'pPhrase' keyword instead
91        sSessCookie = self.clnt.connect(self.config['userName'], 
92                                    pPhrase=self.config['userNamePPhrase'])
93
94        self.sessCookie = SessionCookie(sSessCookie)
95        print "User '%s' connected to Session Manager:\n%s" % \
96            (self.config['userName'], sSessCookie)
97           
98
99    def testProxyCertConnect(self):
100        """testProxyCertConnect: Connect as a command line client -
101        a proxyCert is returned"""
102
103        self.proxyCert = self.clnt.connect(self.config['userName'], 
104                                      pPhrase=self.config['userNamePPhrase'],
105                                      createServerSess=True,
106                                      getCookie=False)
107        print "User '%s' connected to Session Manager:\n%s" % \
108            (self.config['userName'], self.proxyCert)
109           
110
111    def testCookieDisconnect(self):
112        """testCookieDisconnect: disconnect as if acting as a browser client -
113        a cookie is returned"""
114       
115        self.testCookieConnect()
116       
117        self.clnt.disconnect(sessCookie=str(self.sessCookie))
118        print "User disconnected from Session Manager:\n%s" % self.sessCookie
119           
120
121    def testProxyCertDisconnect(self):
122        """testProxyCertDisconnect: Connect as a command line client -
123        a proxyCert is returned"""
124       
125        self.testProxyCertConnect()
126           
127        self.clnt.disconnect(proxyCert=self.proxyCert)
128        print "User disconnected from Session Manager:\n%s" % self.proxyCert
129
130
131    def testCookieReqAuthorisation(self):
132        """testCookieReqAuthorisation: make an authorisation request using
133        a cookie as authentication credential"""
134       
135        self.testCookieConnect()
136        attCert, statusCode, extAttCertList = self.clnt.reqAuthorisation(\
137                        sessID=self.sessCookie.sessionID, 
138                        attAuthorityURI=self.config['aaURI'],
139                        encrSessionMgrURI=self.sessCookie.encrSessionMgrURI)
140       
141        print "Attribute Certificate:\n%s" % attCert 
142        print "User authorisation: %s" % statusCode
143        print "External Attribute Certificate List:\n%s" % extAttCertList
144
145
146    def testCookieReqAuthorisationWithExtAttCertList(self):
147        """testCookieReqAuthorisation: make an authorisation request using
148        a cookie as authentication credential"""
149       
150        self.testCookieConnect()
151        attCert, statusCode, extAttCertList = self.clnt.reqAuthorisation(\
152                        sessID=self.sessCookie.sessionID, 
153                        attAuthorityURI=self.config['aaURI'],
154                        encrSessionMgrURI=self.sessCookie.encrSessionMgrURI,
155                        extAttCertList=['AC1', 'AC2', 'AC3'])
156         
157        print "Attribute Certificate:\n%s" % attCert 
158        print "User authorisation: %s" % statusCode
159        print "External Attribute Certificate List:\n%s" % extAttCertList
160
161
162    def testProxyCertReqAuthorisation(self):
163        """testProxyCertReqAuthorisation: make an authorisation request using
164        a proxy cert as authentication credential"""
165        self.testProxyCertConnect()
166       
167        # Request an attribute certificate from an Attribute Authority
168        # using the proxyCert returned from connect()
169        attCert, statusCode, extAttCertList = self.clnt.reqAuthorisation(\
170                                         proxyCert=self.proxyCert,
171                                         attAuthorityURI=self.config['aaURI'])
172         
173        print "Attribute Certificate:\n%s" % attCert 
174        print "User authorisation: %s" % statusCode
175        print "External Attribute Certificate List:\n%s" % extAttCertList
176
177
178    def testGetX509Cert(self):
179        "testGetX509Cert: return the Session Manager's X.509 Cert."
180        cert = self.clnt.getX509Cert()
181                                             
182        print "Session Manager X.509 Certificate:\n" + cert
183           
184           
185#_____________________________________________________________________________       
186class SessionMgrClientTestSuite(unittest.TestSuite):
187   
188    def __init__(self):
189        map = map(SessionMgrClientTestCase,
190                  (
191                    "testAddUser",
192                    "testCookieConnect",
193                    "testProxyCertConnect",
194                    "testCookieDisconnect",
195                    "testProxyCertDisconnect",
196                    "testCookieReqAuthorisation",
197                    "testProxyCertReqAuthorisation",
198                    "testGetX509Cert",
199                  ))
200        unittest.TestSuite.__init__(self, map)
201           
202                                                   
203if __name__ == "__main__":
204    unittest.main()       
Note: See TracBrowser for help on using the repository browser.