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

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

Successfully tested echo client (ndg.security.test.wsSecurity.client) with DOM based C14N vs. echo server running ElementTree C14N (security/python/Tests/etreewss/server)

  • fixed _verifyTimestamp in ndg.security.common.wsSecurity.SignatureHandler?
  • Fixed logging for ndg.security.test.wsSecurity.client.echoClientTest
  • 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 import wsSecurity
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 = jnPath(os.environ['NDGSEC_WSSECLNT_UNITTEST_DIR'],
36                                "echoClientTest.cfg")
37        self.cfg = SafeConfigParser()
38        self.cfg.read(configFilePath)
39        uri = self.cfg.get('setUp', 'uri')
40        signingPriKeyFilePath = \
41                        xpdVars(self.cfg.get('setUp', 'signingPriKeyFilePath'))
42        signingPriKeyPwd = self.cfg.get('setUp', 'signingPriKeyPwd')
43        signingCertFilePath = \
44                        xpdVars(self.cfg.get('setUp', 'signingCertFilePath'))
45        caCertFilePathList = [xpdVars(file) for file in \
46                              self.cfg.get('setUp', 
47                                          'caCertFilePathList').split()]
48       
49        # Signature handler object is passed to binding
50        sigHandler = wsSecurity.SignatureHandler(
51                                 signingPriKeyFilePath=signingPriKeyFilePath,
52                                 signingPriKeyPwd=signingPriKeyPwd,
53                                 signingCertFilePath=signingCertFilePath,
54                                 caCertFilePathList=caCertFilePathList,
55                                 refC14nKw={'unsuppressedPrefixes':[]},
56                                 signedInfoC14nKw={'unsuppressedPrefixes':[]})
57
58        locator = EchoServiceLocator()
59        self.clnt = locator.getEcho(uri, 
60                                    sig_handler=sigHandler,
61                                    tracefile=sys.stderr)
62       
63
64    def test1Echo(self):
65        '''test1Echo: test signed message and signed response from server'''
66           
67        try:
68            resp = self.clnt.Echo("Hello from client")
69            print "Message returned was: %s" % resp
70        except:
71            self.fail(traceback.print_exc())
72     
73#_____________________________________________________________________________       
74class EchoClientTestSuite(unittest.TestSuite):
75    def __init__(self):
76        map = map(EchoClientTestCase,
77                  (
78                    "test1Echo",
79                  ))
80        unittest.TestSuite.__init__(self, map)
81                                       
82if __name__ == "__main__":
83    unittest.main()
Note: See TracBrowser for help on using the repository browser.