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

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

General refactoring and updating of code, including:

Removal of refC14nKw and singnedInfoC14nKw keywords in wsssecurity session manager config
(the refC14nInclNS and signedInfoC14nInclNS keywords are sufficient);
Creation of new DOM signature handler class, dom.py, based on the wsSecurity
class;
Abstraction of common code between dom.py and etree.py into new parent
class, BaseSignatureHandler?.py.
Fixing and extending use of properties in the SignatureHandler? code.
Fixing a few bugs with the original SignatureHandler? code.
Updating of test cases to new code/code structure.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2#
3# Exampe echo client, to show extended code generation in ZSI
4#
5# Import the client proxy object
6from EchoService_services import EchoServiceLocator
7
8import unittest
9import os
10import sys
11import getpass
12import traceback
13
14from ConfigParser import SafeConfigParser
15from ndg.security.common.wssecurity.dom import SignatureHandler
16
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
21import logging
22logging.basicConfig(level=logging.DEBUG)
23
24class EchoClientTestCase(unittest.TestCase):
25   
26    def setUp(self):
27        if 'NDGSEC_INT_DEBUG' in os.environ:
28            import pdb
29            pdb.set_trace()
30       
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       
35        configFilePath = mkPath('echoClientTest.cfg')
36        self.cfg = SafeConfigParser()
37        self.cfg.read(configFilePath)
38        uri = self.cfg.get('setUp', 'uri')
39        signingPriKeyFilePath = \
40                        xpdVars(self.cfg.get('setUp', 'signingPriKeyFilePath'))
41        signingPriKeyPwd = self.cfg.get('setUp', 'signingPriKeyPwd')
42        signingCertFilePath = \
43                        xpdVars(self.cfg.get('setUp', 'signingCertFilePath'))
44        caCertFilePathList = [xpdVars(file) for file in \
45                              self.cfg.get('setUp', 
46                                          'caCertFilePathList').split()]
47       
48        # Signature handler object is passed to binding
49        sigHandler = SignatureHandler(
50                                 signingPriKeyFilePath=signingPriKeyFilePath,
51                                 signingPriKeyPwd=signingPriKeyPwd,
52                                 signingCertFilePath=signingCertFilePath,
53                                 caCertFilePathList=caCertFilePathList,
54                                 refC14nInclNS=[],
55                                 signedInfoC14nInclNS=[])
56
57        locator = EchoServiceLocator()
58        self.clnt = locator.getEcho(uri, 
59                                    sig_handler=sigHandler,
60                                    tracefile=sys.stderr)
61       
62
63    def test1Echo(self):
64        '''test1Echo: test signed message and signed response from server'''
65           
66        try:
67            resp = self.clnt.Echo("Hello from client")
68            print "Message returned was: %s" % resp
69        except:
70            self.fail(traceback.print_exc())
71     
72#_____________________________________________________________________________       
73class EchoClientTestSuite(unittest.TestSuite):
74    def __init__(self):
75        map = map(EchoClientTestCase,
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.