source: TI12-security/trunk/python/ndg.security.test/ndg/security/test/wsSecurity/client/echoClientTest.py @ 4075

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.test/ndg/security/test/wsSecurity/client/echoClientTest.py@4075
Revision 4075, 3.0 KB checked in by cbyrom, 12 years ago (diff)

Improve logging on test client/server + make use of lambda mkpath function.

  • Property svn:executable set to *
RevLine 
[1696]1#!/usr/bin/env python
[1542]2#
3# Exampe echo client, to show extended code generation in ZSI
4#
5# Import the client proxy object
[3124]6from EchoService_services import EchoServiceLocator
[1542]7
[3115]8import unittest
9import os
10import sys
11import getpass
12import traceback
13
14from ConfigParser import SafeConfigParser
15from ndg.security.common import wsSecurity
16
[3195]17from os.path import expandvars as xpdVars
18from os.path import join as jnPath
19mkPath = lambda file: jnPath(os.environ['NDGSEC_WSSECLNT_UNITTEST_DIR'], file)
20
[4052]21import logging
22logging.basicConfig(level=logging.DEBUG)
23
[3122]24class EchoClientTestCase(unittest.TestCase):
[3115]25   
26    def setUp(self):
[3195]27        if 'NDGSEC_INT_DEBUG' in os.environ:
28            import pdb
29            pdb.set_trace()
[3115]30       
[3195]31        if 'NDGSEC_WSSECLNT_UNITTEST_DIR' not in os.environ:
32            os.environ['NDGSEC_WSSECLNT_UNITTEST_DIR'] = \
33                os.path.abspath(os.path.dirname(__file__))
34       
[4075]35        configFilePath = mkPath('echoClientTest.cfg')
[3122]36        self.cfg = SafeConfigParser()
[3195]37        self.cfg.read(configFilePath)
[3122]38        uri = self.cfg.get('setUp', 'uri')
[3195]39        signingPriKeyFilePath = \
40                        xpdVars(self.cfg.get('setUp', 'signingPriKeyFilePath'))
[3122]41        signingPriKeyPwd = self.cfg.get('setUp', 'signingPriKeyPwd')
[3195]42        signingCertFilePath = \
43                        xpdVars(self.cfg.get('setUp', 'signingCertFilePath'))
44        caCertFilePathList = [xpdVars(file) for file in \
45                              self.cfg.get('setUp', 
46                                          'caCertFilePathList').split()]
[3115]47       
[3122]48        # Signature handler object is passed to binding
49        sigHandler = wsSecurity.SignatureHandler(
50                                 signingPriKeyFilePath=signingPriKeyFilePath,
51                                 signingPriKeyPwd=signingPriKeyPwd,
52                                 signingCertFilePath=signingCertFilePath,
[3652]53                                 caCertFilePathList=caCertFilePathList,
54                                 refC14nKw={'unsuppressedPrefixes':[]},
55                                 signedInfoC14nKw={'unsuppressedPrefixes':[]})
[3122]56
[3124]57        locator = EchoServiceLocator()
[3122]58        self.clnt = locator.getEcho(uri, 
59                                    sig_handler=sigHandler,
60                                    tracefile=sys.stderr)
[3115]61       
62
63    def test1Echo(self):
64        '''test1Echo: test signed message and signed response from server'''
65           
66        try:
[3122]67            resp = self.clnt.Echo("Hello from client")
68            print "Message returned was: %s" % resp
[3115]69        except:
70            self.fail(traceback.print_exc())
[3122]71     
[3115]72#_____________________________________________________________________________       
[3122]73class EchoClientTestSuite(unittest.TestSuite):
[3115]74    def __init__(self):
[3122]75        map = map(EchoClientTestCase,
[3115]76                  (
77                    "test1Echo",
78                  ))
79        unittest.TestSuite.__init__(self, map)
80                                       
81if __name__ == "__main__":
82    unittest.main()
Note: See TracBrowser for help on using the repository browser.