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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/Tests/etreewss/client/echoClientTest.py@4038
Revision 4038, 3.5 KB checked in by pjkersha, 11 years ago (diff)

Completed ElementTree - ZSI integration for WS-Security SignatureHandler? but still problems with ET C14N for signature generation: C14N produces superfluous xmlns declarations.

  • 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                                 refC14nKw={'inclusive_namespaces':[]},
62                                 signedInfoC14nKw={'inclusive_namespaces':[]})
63
64        locator = EchoServiceLocator()
65        self.clnt = locator.getEcho(uri, 
66                                    readerclass=ElementTreeProxy,
67                                    writerclass=ElementTreeProxy,
68                                    sig_handler=sigHandler,
69                                    tracefile=sys.stderr)
70       
71
72    def test1Echo(self):
73        '''test1Echo: test signed message and signed response from server'''
74           
75        try: 
76            resp = self.clnt.Echo("Hello from client")
77            log.info("Message returned was: %s", resp)
78        except NoSignatureFound:
79            log.info("No signature in response")
80        except:
81            self.fail(traceback.print_exc())
82     
83#_____________________________________________________________________________       
84class EchoClientTestSuite(unittest.TestSuite):
85    def __init__(self):
86        map = map(EchoClientTestCase,
87                  (
88                    "test1Echo",
89                  ))
90        unittest.TestSuite.__init__(self, map)
91                                       
92if __name__ == "__main__":
93    unittest.main()
Note: See TracBrowser for help on using the repository browser.