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

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

python/ndg.security.test/ndg/security/test/AttAuthority/AttAuthorityClientTest.py: added config parser so that params can be set from a configuration file.

python/ndg.security.test/ndg/security/test/SessionMgr/SessionMgrClientTest.
py and python/ndg.security.test/ndg/security/test/SessionMgr/sessionMgrClientTest.cfg: added config parser + prompt for passwords where not set in config.

python/ndg.security.common/ndg/security/common/AttAuthority/init.py:
AA client code - added documentation and changed getAttCert so that an AttCert?
type can be passed in as well as a string for userAttCert arg.

  • 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
9@author P J Kershaw
10
1123/02/06
12
13Renamed from SessionClientTest.py 27/0/4/06
14Moved and renamed SessionMgrClientTest.py 23/11/06
15
16@copyright (C) 2007 CCLRC & NERC
17
18@license This software may be distributed under the terms of the Q Public
19License, version 1.0 or later.
20"""
21import unittest
22import os, sys, getpass
23from ConfigParser import SafeConfigParser
24
25from ndg.security.common.SessionMgr import SessionMgrClient
26from ndg.security.common.SessionCookie import SessionCookie
27
28
29class SessionMgrClientTestCase(unittest.TestCase):
30   
31    def setUp(self):
32       
33        configParser = SafeConfigParser()
34        configParser.read("./sessionMgrClientTest.cfg")
35       
36        self.cfg = {}
37        for section in configParser.sections():
38            self.cfg[section] = dict(configParser.items(section))
39
40        tracefile = sys.stderr
41
42        clntPriKeyPwd = self.cfg['setUp'].get('clntprikeypwd') or \
43            getpass.getpass(prompt="\nsetUp - client private key password: ")
44       
45        # Initialise the Session Manager client connection
46        # Omit traceFile keyword to leave out SOAP debug info
47        self.clnt = SessionMgrClient(uri=self.cfg['setUp']['smuri'],
48                smCertFilePath=self.cfg['setUp']['smcertfilepath'],
49                clntCertFilePath=self.cfg['setUp']['clntcertfilepath'],
50                clntPriKeyFilePath=self.cfg['setUp']['clntprikeyfilepath'],
51                clntPriKeyPwd=clntPriKeyPwd,
52                tracefile=tracefile) 
53       
54        self.sessCookie = None
55        self.proxyCert = None
56
57
58    def test1AddUser(self):
59        """Add a new user ID to the MyProxy repository"""
60       
61        passphrase = self.cfg['test1AddUser'].get('passphrase') or \
62            getpass.getpass(prompt="\ntest1AddUser pass-phrase for new user: ")
63           
64        # Note the pass-phrase is read from the file tmp.  To pass
65        # explicitly as a string use the 'pPhrase' keyword instead
66        self.clnt.addUser(self.cfg['test1AddUser']['username'], 
67                          pPhrase=passphrase)
68        print "Added user '%s'" % self.cfg['test1AddUser']['username']
69       
70
71    def test2CookieConnect(self):
72        """test2CookieConnect: Connect as if acting as a browser client -
73        a cookie is returned"""
74
75        passphrase = self.cfg['test2CookieConnect'].get('passphrase') or \
76        getpass.getpass(prompt="\ntest2CookieConnect pass-phrase for user: ")
77
78        sSessCookie = self.clnt.connect(\
79                                    self.cfg['test2CookieConnect']['username'], 
80                                    pPhrase=passphrase)
81
82        self.sessCookie = SessionCookie(sSessCookie)
83        print "User '%s' connected to Session Manager:\n%s" % \
84            (self.cfg['test2CookieConnect']['username'], sSessCookie)
85           
86
87    def test3ProxyCertConnect(self):
88        """test3ProxyCertConnect: Connect as a command line client -
89        a proxyCert is returned"""
90
91        passphrase = self.cfg['test3ProxyCertConnect'].get('passphrase') or \
92            getpass.getpass(\
93                    prompt="\ntest3ProxyCertConnect pass-phrase for user: ")
94
95        self.proxyCert = self.clnt.connect(\
96                               self.cfg['test3ProxyCertConnect']['username'], 
97                               pPhrase=passphrase,
98                               createServerSess=True,
99                               getCookie=False)
100        print "User '%s' connected to Session Manager:\n%s" % \
101            (self.cfg['test3ProxyCertConnect']['username'], self.proxyCert)
102           
103
104    def test4CookieDisconnect(self):
105        """test4CookieDisconnect: disconnect as if acting as a browser client -
106        a cookie is returned"""
107       
108        print "\n\t" + self.test4CookieDisconnect.__doc__
109        self.test2CookieConnect()
110       
111        self.clnt.disconnect(sessCookie=str(self.sessCookie))
112        print "User disconnected from Session Manager:\n%s" % self.sessCookie
113           
114
115    def test5ProxyCertDisconnect(self):
116        """test5ProxyCertDisconnect: Connect as a command line client -
117        a proxyCert is returned"""
118       
119        print "\n\t" + self.test5ProxyCertDisconnect.__doc__
120        self.test3ProxyCertConnect()
121           
122        self.clnt.disconnect(proxyCert=self.proxyCert)
123        print "User disconnected from Session Manager:\n%s" % self.proxyCert
124
125
126    def test6CookieReqAuthorisation(self):
127        """test6CookieReqAuthorisation: make an authorisation request using
128        a cookie as authentication credential"""
129
130        print "\n\t" + self.test6CookieReqAuthorisation.__doc__       
131        self.test2CookieConnect()
132        attCert, statusCode, extAttCertList = self.clnt.reqAuthorisation(\
133            sessID=self.sessCookie.sessionID, 
134            attAuthorityURI=self.cfg['test6CookieReqAuthorisation']['aauri'],
135            encrSessionMgrURI=self.sessCookie.encrSessionMgrURI)
136       
137        print "Attribute Certificate:\n%s" % attCert 
138        print "User authorisation: %s" % statusCode
139        print "External Attribute Certificate List:\n%s" % extAttCertList
140
141
142    def test6aCookieReqAuthorisationWithExtAttCertList(self):
143        """test6CookieReqAuthorisation: make an authorisation request using
144        a cookie as authentication credential"""
145       
146        print "\n\t" + self.test6aCookieReqAuthorisationWithExtAttCertList.__doc__       
147        self.test2CookieConnect()
148       
149        aaURI = \
150            self.cfg['test6aCookieReqAuthorisationWithExtAttCertList']['aauri']
151           
152        attCert, statusCode, extAttCertList = self.clnt.reqAuthorisation(\
153                        sessID=self.sessCookie.sessionID, 
154                        attAuthorityURI=aaURI,
155                        encrSessionMgrURI=self.sessCookie.encrSessionMgrURI,
156                        extAttCertList=['AC1', 'AC2', 'AC3'])
157         
158        print "Attribute Certificate:\n%s" % attCert 
159        print "User authorisation: %s" % statusCode
160        print "External Attribute Certificate List:\n%s" % extAttCertList
161
162
163    def test7ProxyCertReqAuthorisation(self):
164        """test7ProxyCertReqAuthorisation: make an authorisation request using
165        a proxy cert as authentication credential"""
166        print "\n\t" + self.test7ProxyCertReqAuthorisation.__doc__
167        self.test3ProxyCertConnect()
168       
169        # Request an attribute certificate from an Attribute Authority
170        # using the proxyCert returned from connect()
171       
172        aaURI = self.cfg['test7ProxyCertReqAuthorisation']['aauri']
173        attCert, statusCode, extAttCertList = self.clnt.reqAuthorisation(\
174                                                 proxyCert=self.proxyCert,
175                                                 attAuthorityURI=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 test8GetX509Cert(self):
183        "test8GetX509Cert: 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                    "test1AddUser",
196                    "test2CookieConnect",
197                    "test3ProxyCertConnect",
198                    "test4CookieDisconnect",
199                    "test5ProxyCertDisconnect",
200                    "test6CookieReqAuthorisation",
201                    "test6aCookieReqAuthorisationWithExtAttCertList",
202                    "test7ProxyCertReqAuthorisation",
203                    "test8GetX509Cert",
204                  ))
205        unittest.TestSuite.__init__(self, map)
206           
207                                                   
208if __name__ == "__main__":
209    unittest.main()       
Note: See TracBrowser for help on using the repository browser.