Changeset 1998


Ignore:
Timestamp:
12/01/07 16:30:13 (13 years ago)
Author:
pjkersha
Message:

python/ndg.security.test/ndg/security/test/SessionMgr/SessionMgrClientTest.py and
python/ndg.security.test/ndg/security/test/SessionMgr/sessionMgrClientTest.cfg: added a config file to enable
easy modification of parameters such as Session Manager URI and account details.

Location:
TI12-security/trunk/python/ndg.security.test/ndg/security/test/SessionMgr
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • TI12-security/trunk/python/ndg.security.test/ndg/security/test/SessionMgr/SessionMgrClientTest.py

    r1945 r1998  
    1818""" 
    1919import unittest 
    20 import os, sys 
     20import os, sys, getpass 
    2121  
    2222from ndg.security.common.SessionMgr import SessionMgrClient 
     
    2727     
    2828    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  
    4029         
    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' 
     30        configParser = SafeConfigParser() 
     31        configParser.read("./sessionMgrClientTest.cfg") 
    5832         
    59  
    60         # Uncomment for required test 
    61         self.config = testConfig 
    62         #self.config = glueConfig 
     33        self.cfg = {} 
     34        for section in configParser.sections(): 
     35            self.cfg[section] = dict(configParser.items(section)) 
    6336 
    6437        tracefile = sys.stderr 
     
    6639        # Initialise the Session Manager client connection 
    6740        # 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)  
     41        self.clnt = SessionMgrClient(uri=self.cfg['setup']['smuri'], 
     42                smCertFilePath=self.cfg['setup']['smcertfilepath'], 
     43                clntCertFilePath=self.cfg['setup']['clntcertfilepath'], 
     44                clntPriKeyFilePath=self.cfg['setup']['clntprikeyfilepath'], 
     45                clntPriKeyPwd=clntPriKeyPwd, 
     46                tracefile=tracefile)  
    7447         
    7548        self.sessCookie = None 
     
    8053        """Add a new user ID to the MyProxy repository""" 
    8154         
     55        passphrase = self.cfg['testAddUser'].get('passphrase') or \ 
     56            getpass.getpass(prompt="\ntestAddUser pass-phrase for new user: ") 
     57             
    8258        # Note the pass-phrase is read from the file tmp.  To pass 
    8359        # 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'] 
     60        self.clnt.addUser(self.cfg['testAddUser']['username'],  
     61                          pPhrase=passphrase) 
     62        print "Added user '%s'" % self.cfg['testAddUser']['username'] 
    8763         
    8864 
     
    9066        """testCookieConnect: Connect as if acting as a browser client -  
    9167        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']) 
     68 
     69        passphrase = self.cfg['testCookieConnect'].get('passphrase') or \ 
     70        getpass.getpass(prompt="\ntestCookieConnect pass-phrase for user: ") 
     71 
     72        sSessCookie = self.clnt.connect(\ 
     73                                    self.cfg['testCookieConnect']['username'],  
     74                                    pPhrase=passphrase) 
    9775 
    9876        self.sessCookie = SessionCookie(sSessCookie) 
    9977        print "User '%s' connected to Session Manager:\n%s" % \ 
    100             (self.config['userName'], sSessCookie) 
     78            (self.cfg['testCookieConnect']['username'], sSessCookie) 
    10179             
    10280 
     
    10583        a proxyCert is returned""" 
    10684 
    107         self.proxyCert = self.clnt.connect(self.config['userName'],  
    108                                       pPhrase=self.config['userNamePPhrase'], 
    109                                       createServerSess=True, 
    110                                       getCookie=False) 
     85        passphrase = self.cfg['testProxyCertConnect'].get('passphrase') or \ 
     86            getpass.getpass(\ 
     87                    prompt="\ntestProxyCertConnect pass-phrase for user: ") 
     88 
     89        self.proxyCert = self.clnt.connect(\ 
     90                               self.cfg['testProxyCertConnect']['username'],  
     91                               pPhrase=passphrase, 
     92                               createServerSess=True, 
     93                               getCookie=False) 
    11194        print "User '%s' connected to Session Manager:\n%s" % \ 
    112             (self.config['userName'], self.proxyCert) 
     95            (self.cfg['testProxyCertConnect']['username'], self.proxyCert) 
    11396             
    11497 
     
    139122        self.testCookieConnect() 
    140123        attCert, statusCode, extAttCertList = self.clnt.reqAuthorisation(\ 
    141                         sessID=self.sessCookie.sessionID,  
    142                         attAuthorityURI=self.config['aaURI'], 
    143                         encrSessionMgrURI=self.sessCookie.encrSessionMgrURI) 
     124            sessID=self.sessCookie.sessionID,  
     125            attAuthorityURI=self.cfg['testCookieReqAuthorisation']['aauri'], 
     126            encrSessionMgrURI=self.sessCookie.encrSessionMgrURI) 
    144127         
    145128        print "Attribute Certificate:\n%s" % attCert   
     
    153136         
    154137        self.testCookieConnect() 
     138         
     139        aaURI = \ 
     140            self.cfg['testCookieReqAuthorisationWithExtAttCertList']['aauri'] 
     141             
    155142        attCert, statusCode, extAttCertList = self.clnt.reqAuthorisation(\ 
    156143                        sessID=self.sessCookie.sessionID,  
    157                         attAuthorityURI=self.config['aaURI'], 
     144                        attAuthorityURI=aaURI, 
    158145                        encrSessionMgrURI=self.sessCookie.encrSessionMgrURI, 
    159146                        extAttCertList=['AC1', 'AC2', 'AC3']) 
     
    171158        # Request an attribute certificate from an Attribute Authority  
    172159        # using the proxyCert returned from connect() 
     160         
     161        aaURI = self.cfg['testProxyCertReqAuthorisation']['aauri'] 
    173162        attCert, statusCode, extAttCertList = self.clnt.reqAuthorisation(\ 
    174                                          proxyCert=self.proxyCert, 
    175                                          attAuthorityURI=self.config['aaURI']) 
     163                                                 proxyCert=self.proxyCert, 
     164                                                 attAuthorityURI=aaURI) 
    176165           
    177166        print "Attribute Certificate:\n%s" % attCert   
Note: See TracChangeset for help on using the changeset viewer.