Ignore:
Timestamp:
09/01/08 14:50:08 (12 years ago)
Author:
pjkersha
Message:

Working version of Session Manager unit tests with certs included in SVN issued from test CA.

security/python/ndg.security.test/ndg/security/test/attAuthority/README: added note about test config file.

security/python/ndg.security.test/ndg/security/test/attAuthority/siteAAttAuthorityProperties.xml,
security/python/ndg.security.test/ndg/security/test/attAuthority/siteBAttAuthorityProperties.xml:
added note about MyProxy? CA certificate inclusion for WSSE signature handler to trust requests authenticated by certs from MyProxy? CA. This is needed for running these services with Session Manager and Session Manager Cleint unit tests

security/python/ndg.security.test/ndg/security/test/ca/README: added note that this unit test is currently defunct.

security/python/ndg.security.test/ndg/security/test/gatekeeper/README,
security/python/ndg.security.test/ndg/security/test/Log: added

security/python/ndg.security.test/ndg/security/test/myProxy/README: added note about ensuring test creds are removed from the repository.

security/python/ndg.security.test/ndg/security/test/sessionCookie/README: note that this test is defunct. Pylons code can perform the same function

security/python/ndg.security.test/ndg/security/test/sessionCookie/SessionCookieTest.py,
security/python/ndg.security.test/ndg/security/test/sessionCookie/sessionCookieTest.cfg:
altered so that files are ref'd by env vars so that tests can be run from any dir

security/python/ndg.security.test/ndg/security/test/README: added

security/python/ndg.security.test/ndg/security/test/sessionMgr/sessionMgrProperties.xml,
security/python/ndg.security.test/ndg/security/test/sessionMgr/sessionMgrTest.cfg,
security/python/ndg.security.test/ndg/security/test/sessionMgr/test.py:

  • altered so that files are ref'd by env vars so that tests can be run from any dir
  • test1Connect PKI output is dumped to user.creds file.
File:
1 edited

Legend:

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

    r3139 r3192  
    1818import os, sys, getpass, re 
    1919from ConfigParser import SafeConfigParser 
     20import traceback 
    2021 
    2122from ndg.security.common.X509 import X509CertParse 
    2223from ndg.security.server.SessionMgr import * 
     24from ndg.security.server.MyProxy import MyProxyClient 
     25 
     26from os.path import expandvars as xpdVars 
     27from os.path import join as jnPath 
     28mkPath = lambda file: jnPath(os.environ['NDGSEC_SM_UNITTEST_DIR'], file) 
    2329 
    2430 
     
    3036    test1Passphrase = None 
    3137    test3Passphrase = None 
    32  
     38     
    3339    def setUp(self): 
    3440         
    35         self.cfg = SafeConfigParser() 
    36         self.cfg.read("./sessionMgrTest.cfg") 
    37          
    38         os.environ['NDGSEC_SM_UNITTEST_DIR'] = \ 
    39             os.path.expandvars(self.cfg.get('setUp',  
    40                                             'NDGSEC_SM_UNITTEST_DIR')) 
    41              
    42         # Initialise the Session Manager client connection 
    43         # Omit traceFile keyword to leave out SOAP debug info 
    44         self.sm = SessionMgr(propFilePath=self.cfg.get('setUp',  
    45                                                        'propFilePath')) 
    4641        if 'NDGSEC_INT_DEBUG' in os.environ: 
    4742            import pdb 
    4843            pdb.set_trace() 
     44         
     45        if 'NDGSEC_SM_UNITTEST_DIR' not in os.environ: 
     46            os.environ['NDGSEC_SM_UNITTEST_DIR'] = \ 
     47                os.path.abspath(os.path.dirname(__file__)) 
     48         
     49        self.cfg = SafeConfigParser() 
     50        configFilePath = jnPath(os.environ['NDGSEC_SM_UNITTEST_DIR'], 
     51                                "sessionMgrTest.cfg") 
     52        self.cfg.read(configFilePath) 
     53                     
     54        # Initialise the Session Manager client connection 
     55        # Omit traceFile keyword to leave out SOAP debug info 
     56        propFilePath = xpdVars(self.cfg.get('setUp', 'propFilePath')) 
     57        self.sm = SessionMgr(propFilePath=propFilePath) 
     58         
    4959                                   
    5060    def test1Connect(self): 
     
    5262         
    5363        print "\n\t" + self.test1Connect.__doc__ 
     64         
     65        username = self.cfg.get('test1Connect', 'username') 
    5466         
    5567        if SessionMgrTestCase.test1Passphrase is None and \ 
     
    6072        if not SessionMgrTestCase.test1Passphrase: 
    6173            SessionMgrTestCase.test1Passphrase = getpass.getpass(\ 
    62                                prompt="\ntest1Connect pass-phrase for user: ") 
     74                prompt="\ntest1Connect pass-phrase for user %s: " % username) 
    6375 
    6476        userCert, self.userPriKey, self.issuingCert, self.sessID = \ 
    65             self.sm.connect(username=self.cfg.get('test1Connect', 'username'),  
     77            self.sm.connect(username=username,  
    6678                            passphrase=SessionMgrTestCase.test1Passphrase) 
    6779        self.userCert = X509CertParse(userCert) 
    6880         
    6981        print "User '%s' connected to Session Manager:\n%s" % \ 
    70             (self.cfg.get('test1Connect', 'username'), self.sessID) 
     82                                                        (username, self.sessID) 
     83        creds = self.issuingCert or '' + userCert + self.userPriKey 
     84        open(mkPath("user.creds"), "w").write(creds) 
     85     
    7186             
    7287    def test2GetSessionStatus(self): 
     
    89104        print "\n\t" + self.test3ConnectNoCreateServerSess.__doc__ 
    90105         
     106        username = self.cfg.get('test3ConnectNoCreateServerSess', 'username') 
     107 
    91108        if SessionMgrTestCase.test3Passphrase is None and \ 
    92109           self.cfg.has_option('test3ConnectNoCreateServerSess',  
     
    97114        if not SessionMgrTestCase.test3Passphrase: 
    98115            SessionMgrTestCase.test3Passphrase = getpass.getpass(\ 
    99             prompt="\ntest3ConnectNoCreateServerSess pass-phrase for user: ") 
    100  
    101         username = self.cfg.get('test3ConnectNoCreateServerSess', 'username') 
     116        prompt="\ntest3ConnectNoCreateServerSess pass-phrase for user %s: " % \ 
     117            username) 
     118 
    102119        self.userCert, self.userPriKey, self.issuingCert, sessID = \ 
    103120            self.sm.connect(username=username,  
     
    108125        assert not sessID, "Expecting a null session ID!" 
    109126           
    110         print "User '%s' connected to Session Manager:\n%s" % \ 
    111                 (self.cfg.get('test3ConnectNoCreateServerSess', 'username'),  
    112                  self.userCert) 
     127        print "User '%s' retrieved creds. from Session Manager:\n%s" % \ 
     128                                                    (username, self.userCert) 
    113129             
    114130 
     
    152168        print "Attribute Certificate:\n%s" % attCert  
    153169        attCert.filePath = \ 
    154             self.cfg.get('test6GetAttCertWithSessID', 'acoutfilepath')  
     170            xpdVars(self.cfg.get('test6GetAttCertWithSessID', 'acoutfilepath'))  
    155171        attCert.write() 
    156172         
     
    213229        # Use output from test6GetAttCertWithSessID! 
    214230        extACFilePath = \ 
    215     self.cfg.get('test6cGetAttCertWithExtAttCertListWithSessID', 'extacfilepath')    
     231        xpdVars(self.cfg.get('test6cGetAttCertWithExtAttCertListWithSessID',  
     232                             'extacfilepath'))    
    216233        extAttCert = open(extACFilePath).read() 
    217234         
    218         attCert, errMsg, extAttCertList = self.sm.getAttCert(sessID=self.sessID,  
    219                                        aaURI=aaURI, 
    220                                        extAttCertList=[extAttCert]) 
     235        attCert, errMsg, extAttCertList = self.sm.getAttCert( 
     236                                                   sessID=self.sessID,  
     237                                                   aaURI=aaURI, 
     238                                                   extAttCertList=[extAttCert]) 
    221239        if errMsg: 
    222240            self.fail(errMsg) 
     
    247265     
    248266    def __init__(self): 
    249         map = map(SessionMgrTestCase, 
    250                   ( 
    251                     "test1Connect", 
    252                     "test2GetSessionStatus", 
    253                     "test3ConnectNoCreateServerSess", 
    254                     "test4DisconnectWithSessID", 
    255                     "test5DisconnectWithUserCert", 
    256                     "test6GetAttCertWithSessID", 
    257                     "test6bGetMappedAttCertWithSessID", 
    258                     "test6cGetAttCertWithExtAttCertListWithSessID", 
    259                     "test7GetAttCertWithUserCert", 
    260                   )) 
    261         unittest.TestSuite.__init__(self, map) 
     267        print "SessionMgrTestSuite ..." 
     268        smTestCaseMap = map(SessionMgrTestCase, 
     269                          ( 
     270                            "test1Connect", 
     271                            "test2GetSessionStatus", 
     272                            "test3ConnectNoCreateServerSess", 
     273                            "test4DisconnectWithSessID", 
     274                            "test5DisconnectWithUserCert", 
     275                            "test6GetAttCertWithSessID", 
     276                            "test6bGetMappedAttCertWithSessID", 
     277                            "test6cGetAttCertWithExtAttCertListWithSessID", 
     278                            "test7GetAttCertWithUserCert", 
     279                          )) 
     280        unittest.TestSuite.__init__(self, smTestCaseMap) 
    262281             
    263282                                                     
    264283if __name__ == "__main__": 
     284#    suite = SessionMgrTestSuite() 
     285#    unittest.TextTestRunner(verbosity=2).run(suite) 
    265286    unittest.main()         
Note: See TracChangeset for help on using the changeset viewer.