Ignore:
Timestamp:
06/12/07 14:26:58 (12 years ago)
Author:
pjkersha
Message:

security/python/ndg.security.test/ndg/security/test/wsSecurity/client: complete unit test

Location:
TI12-security/trunk/python/ndg.security.test/ndg/security/test/wsSecurity/client
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TI12-security/trunk/python/ndg.security.test/ndg/security/test/wsSecurity/client

    • Property svn:ignore set to
      Junk-*.pem
  • TI12-security/trunk/python/ndg.security.test/ndg/security/test/wsSecurity/client/echoClientTest.py

    r3115 r3122  
    44# 
    55# Import the client proxy object 
    6 from EchoServer_client import EchoServerSOAP 
    7 import sys 
    8  
    9 import wsSecurity 
     6from Echo_services import EchoLocator 
    107 
    118import unittest 
     
    1815from ndg.security.common import wsSecurity 
    1916 
    20 class WSSecurityClientTestCase(unittest.TestCase): 
     17class EchoClientTestCase(unittest.TestCase): 
    2118     
    2219    def setUp(self): 
    2320         
    24         configParser = SafeConfigParser() 
    25         configParser.read("./myProxyClientTest.cfg") 
     21        self.cfg = SafeConfigParser() 
     22        self.cfg.read("./echoClientTest.cfg") 
     23        uri = self.cfg.get('setUp', 'uri') 
     24        signingPriKeyFilePath = self.cfg.get('setUp', 'signingPriKeyFilePath') 
     25        signingPriKeyPwd = self.cfg.get('setUp', 'signingPriKeyPwd') 
     26        signingCertFilePath = self.cfg.get('setUp', 'signingCertFilePath') 
     27        caCertFilePathList = self.cfg.get('setUp',  
     28                                          'caCertFilePathList').split() 
    2629         
    27         self.cfg = {} 
    28         for section in configParser.sections(): 
    29             self.cfg[section] = dict(configParser.items(section)) 
    30              
    31         self.clnt = WSSecurityClient(\ 
    32                           propFilePath=self.cfg['setUp']['propfilepath']) 
     30        # Signature handler object is passed to binding 
     31        sigHandler = wsSecurity.SignatureHandler( 
     32                                 signingPriKeyFilePath=signingPriKeyFilePath, 
     33                                 signingPriKeyPwd=signingPriKeyPwd, 
     34                                 signingCertFilePath=signingCertFilePath, 
     35                                 caCertFilePathList=caCertFilePathList) 
     36 
     37        locator = EchoLocator() 
     38        self.clnt = locator.getEcho(uri,  
     39                                    sig_handler=sigHandler, 
     40                                    tracefile=sys.stderr) 
    3341         
    3442 
     
    3644        '''test1Echo: test signed message and signed response from server''' 
    3745             
    38         passphrase = self.cfg['test1Echo'].get('passphrase') 
    39         if passphrase is None: 
    40             passphrase = getpass.getpass(\ 
    41                                  prompt="\ntest1Echo cred. pass-phrase: ") 
    42              
    43         ownerPassphrase = self.cfg['test1Echo'].get('ownerpassphrase') 
    44         if ownerPassphrase is None: 
    45             ownerPassphrase = getpass.getpass(\ 
    46                               prompt="\ntest1Echo cred. owner pass-phrase: ") 
    47              
    4846        try: 
    49             self.clnt.store(self.cfg['test1Echo']['username'], 
    50                         passphrase, 
    51                         self.cfg['test1Echo']['certfile'], 
    52                         self.cfg['test1Echo']['keyfile'], 
    53                         ownerCertFile=self.cfg['test1Echo']['ownercertfile'], 
    54                         ownerKeyFile=self.cfg['test1Echo']['ownerkeyfile'], 
    55                         ownerPassphrase=ownerPassphrase, 
    56                         force=False) 
    57             print "Store creds for user %s" % \ 
    58                                             self.cfg['test1Echo']['username'] 
     47            resp = self.clnt.Echo("Hello from client") 
     48            print "Message returned was: %s" % resp 
    5949        except: 
    6050            self.fail(traceback.print_exc()) 
    61              
     51      
    6252#_____________________________________________________________________________        
    63 class WSSecurityClientTestSuite(unittest.TestSuite): 
     53class EchoClientTestSuite(unittest.TestSuite): 
    6454    def __init__(self): 
    65         map = map(WSSecurityClientTestCase, 
     55        map = map(EchoClientTestCase, 
    6656                  ( 
    6757                    "test1Echo", 
     
    7161if __name__ == "__main__": 
    7262    unittest.main() 
    73 # Lambda used by WS-Security handler to check which operation has been 
    74 # invoked 
    75 isEchoRequest = lambda sw: sw.body.node.childNodes[0].localName=='Echo' 
    76 isEchoEncrRequest = lambda sw: sw.body.node.childNodes[0].localName=='EchoEncr' 
    77  
    78 isEchoResponse = lambda ps: \ 
    79 ps.dom.childNodes[1].childNodes[1].childNodes[0].localName == 'EchoResponse' 
    80 isEchoEncrResponse = lambda ps: \ 
    81 ps.dom.childNodes[1].childNodes[1].childNodes[0].localName=='EchoEncrResponse' 
    82  
    83 class WSSEhandler: 
    84     def __init__(self, sigHandler=None, encrHandler=None): 
    85         self.sigHandler = sigHandler 
    86         self.encrHandler = encrHandler 
    87          
    88     def sign(self, sw): 
    89         if self.sigHandler: 
    90             self.sigHandler.sign(sw) 
    91              
    92     def verify(self, ps): 
    93         if self.sigHandler: 
    94             self.sigHandler.verify(ps) 
    95          
    96     def encrypt(self, sw): 
    97         if self.encrHandler: 
    98             self.encrHandler.encrypt(sw) 
    99             
    100     def decrypt(self, ps): 
    101         if self.encrHandler: 
    102             self.encrHandler.decrypt(ps) 
    103  
    104  
    105 #priKeyPwd = open('../tmp2').read().strip() 
    106 #certFilePath = '../Junk-cert.pem' 
    107 #priKeyFilePath = '../Junk-key.pem' 
    108 priKeyPwd = None 
    109 certFilePath = '../webSphereTestcert.pem' 
    110 priKeyFilePath = '../webSphereTestkey.pem' 
    111  
    112 # Signature handler object is passed to binding 
    113 sigHandler = wsSecurity.SignatureHandler(certFilePath=certFilePath, 
    114                                          priKeyFilePath=priKeyFilePath, 
    115                                          priKeyPwd=priKeyPwd) 
    116  
    117 encrHandler = wsSecurity.EncryptionHandler(certFilePath=certFilePath, 
    118                                            priKeyFilePath=priKeyFilePath, 
    119                                            priKeyPwd=priKeyPwd) 
    120  
    121 # Test encryption only 
    122 #wsseHandler = WSSEhandler(sigHandler, encrHandler) 
    123 wsseHandler = WSSEhandler(encrHandler=encrHandler) 
    124      
    125          
    126 # Instantiate a client proxy object, then call it 
    127 #wsURL = "http://192.100.78.234:9081/EchoServiceWeb/services/EchoServer" 
    128 wsURL = "http://localhost:7000" 
    129 echoSrv = EchoServerSOAP(wsURL, 
    130                          sig_handler=sigHandler, 
    131                          encr_handler=encrHandler, 
    132                          tracefile=sys.stdout) 
    133 try: 
    134     #import pdb;pdb.set_trace() 
    135     print echoSrv.Echo("Test String") 
    136     #print echoSrv.EchoEncr("Test Secret") 
    137 except Exception, e: 
    138     print "Failed to echo: ", e 
    139  
Note: See TracChangeset for help on using the changeset viewer.