source: TI12-security/trunk/python/Tests/etreewss/client/echoClientTest.py @ 4129

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/Tests/etreewss/client/echoClientTest.py@4129
Revision 4129, 3.4 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.etree import SignatureHandler, \
16                                                NoSignatureFound
17
18from os.path import expandvars as xpdVars
19from os.path import join as jnPath
20mkPath = lambda file: jnPath(os.environ['NDGSEC_WSSECLNT_UNITTEST_DIR'], file)
21
22from ndg.security.common.zsi_utils.elementtreeproxy import ElementTreeProxy
23
24import logging
25logging.basicConfig(level=logging.DEBUG)
26log = logging.getLogger(__name__)
27
28class EchoClientTestCase(unittest.TestCase):
29   
30    def setUp(self):
31        if 'NDGSEC_INT_DEBUG' in os.environ:
32            import pdb
33            pdb.set_trace()
34       
35        if 'NDGSEC_WSSECLNT_UNITTEST_DIR' not in os.environ:
36            os.environ['NDGSEC_WSSECLNT_UNITTEST_DIR'] = \
37                os.path.abspath(os.path.dirname(__file__))
38       
39        configFilePath = jnPath(os.environ['NDGSEC_WSSECLNT_UNITTEST_DIR'],
40                                "echoClientTest.cfg")
41        self.cfg = SafeConfigParser()
42        self.cfg.read(configFilePath)
43        uri = self.cfg.get('setUp', 'uri')
44        signingPriKeyFilePath = \
45                        xpdVars(self.cfg.get('setUp', 'signingPriKeyFilePath'))
46        signingPriKeyPwd = self.cfg.get('setUp', 'signingPriKeyPwd')
47        signingCertFilePath = \
48                        xpdVars(self.cfg.get('setUp', 'signingCertFilePath'))
49        caCertFilePathList = [xpdVars(file) for file in \
50                              self.cfg.get('setUp', 
51                                          'caCertFilePathList').split()]
52       
53        # Signature handler object is passed to binding
54        # TODO: swap 'unsupressedPrefixes' to 'inclusive_namespaces' in
55        # wssecurity.WSSecurityConfig
56        sigHandler = SignatureHandler(
57                                 signingPriKeyFilePath=signingPriKeyFilePath,
58                                 signingPriKeyPwd=signingPriKeyPwd,
59                                 signingCertFilePath=signingCertFilePath,
60                                 caCertFilePathList=caCertFilePathList)
61
62        locator = EchoServiceLocator()
63        self.clnt = locator.getEcho(uri, 
64                                    readerclass=ElementTreeProxy,
65                                    writerclass=ElementTreeProxy,
66                                    sig_handler=sigHandler,
67                                    tracefile=sys.stderr)
68       
69
70    def test1Echo(self):
71        '''test1Echo: test signed message and signed response from server'''
72           
73        try: 
74            resp = self.clnt.Echo("Hello from client")
75            log.info("Message returned was: %s", resp)
76        except NoSignatureFound:
77            log.info("No signature in response")
78        except:
79            self.fail(traceback.print_exc())
80     
81#_____________________________________________________________________________       
82class EchoClientTestSuite(unittest.TestSuite):
83    def __init__(self):
84        map = map(EchoClientTestCase,
85                  (
86                    "test1Echo",
87                  ))
88        unittest.TestSuite.__init__(self, map)
89                                       
90if __name__ == "__main__":
91    unittest.main()
Note: See TracBrowser for help on using the repository browser.