source: TI12-security/trunk/python/ndg.security.test/ndg/security/test/wssecurity/foursuite/client/test_echoclient.py @ 5057

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.test/ndg/security/test/wssecurity/foursuite/client/test_echoclient.py@5057
Revision 5057, 3.7 KB checked in by pjkersha, 11 years ago (diff)

Tested WS-Security SignatureHandler? based on the 4Suite-XML Canonicalizer. - Tested a client connecting to a server using the old dom based implementation of the SignatureHandler?.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2"""WS-Security Digital Signature unit tests
3
4NERC Data Grid Project
5"""
6__author__ = "P J Kershaw"
7__date__ = "13/12/06"
8__copyright__ = "(C) 2009 Science and Technology Facilities Council"
9__license__ = "BSD - see LICENSE file in top-level directory"
10__contact__ = "Philip.Kershaw@stfc.ac.uk"
11__revision__ = '$Id$'
12import logging
13logging.basicConfig(level=logging.DEBUG)
14
15import unittest
16import os
17import sys
18import getpass
19import traceback
20
21from os.path import expandvars as xpdVars
22from os.path import join as jnPath
23mkPath = lambda file: jnPath(os.environ['NDGSEC_WSSECLNT_UNITTEST_DIR'], file)
24from os.path import join, dirname, abspath
25from ConfigParser import SafeConfigParser
26
27from EchoService_services import EchoServiceLocator
28
29from ndg.security.test import BaseTestCase
30from ndg.security.common.wssecurity.foursuite import SignatureHandler
31from ndg.security.common.wssecurity.utils import DomletteReader, \
32    DomletteElementProxy
33
34class EchoClientTestCase(BaseTestCase):
35   
36    def setUp(self):
37        super(EchoClientTestCase, self).setUp()
38       
39        if 'NDGSEC_INT_DEBUG' in os.environ:
40            import pdb
41            pdb.set_trace()
42       
43        if 'NDGSEC_WSSECLNT_UNITTEST_DIR' not in os.environ:
44            os.environ['NDGSEC_WSSECLNT_UNITTEST_DIR'] = \
45                abspath(dirname(__file__))
46   
47        if 'NDGSEC_TEST_CONFIG_DIR' not in os.environ:
48            os.environ['NDGSEC_TEST_CONFIG_DIR'] = \
49                abspath(join(dirname(dirname(dirname(dirname(__file__)))),
50                             'config'))
51       
52        configFilePath = mkPath('echoClientTest.cfg')
53        self.cfg = SafeConfigParser()
54        self.cfg.read(configFilePath)
55        uri = self.cfg.get('setUp', 'uri')
56        signingPriKeyFilePath = \
57                        xpdVars(self.cfg.get('setUp', 'signingPriKeyFilePath'))
58        signingPriKeyPwd = self.cfg.get('setUp', 'signingPriKeyPwd')
59        signingCertFilePath = \
60                        xpdVars(self.cfg.get('setUp', 'signingCertFilePath'))
61        caCertFilePathList = [xpdVars(file) for file in \
62                              self.cfg.get('setUp', 
63                                          'caCertFilePathList').split()]
64       
65        # Signature handler object is passed to binding
66        sigHandler = SignatureHandler(
67                                 signingPriKeyFilePath=signingPriKeyFilePath,
68                                 signingPriKeyPwd=signingPriKeyPwd,
69                                 signingCertFilePath=signingCertFilePath,
70                                 caCertFilePathList=caCertFilePathList,
71                                 refC14nInclNS=[],
72                                 signedInfoC14nInclNS=[])
73
74        locator = EchoServiceLocator()
75        self.clnt = locator.getEcho(uri,
76                                    readerclass=DomletteReader,
77                                    writerclass=DomletteElementProxy, 
78                                    sig_handler=sigHandler,
79                                    tracefile=sys.stderr)
80       
81
82    def test1Echo(self):
83        '''test1Echo: test signed message and signed response from server'''
84           
85        try:
86            resp = self.clnt.Echo("Hello from client")
87            print "Message returned was: %s" % resp
88        except:
89            self.fail(traceback.print_exc())
90     
91#_____________________________________________________________________________       
92class EchoClientTestSuite(unittest.TestSuite):
93    def __init__(self):
94        map = map(EchoClientTestCase,
95                  (
96                    "test1Echo",
97                  ))
98        unittest.TestSuite.__init__(self, map)
99                                       
100if __name__ == "__main__":
101    unittest.main()
Note: See TracBrowser for help on using the repository browser.