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

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@5053
Revision 5053, 3.2 KB checked in by pjkersha, 11 years ago (diff)

Re-arrange WS-Security unittests to allow for new 4Suite based package.

  • 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 ConfigParser import SafeConfigParser
25
26from EchoService_services import EchoServiceLocator
27
28from ndg.security.test import BaseTestCase
29from ndg.security.common.wssecurity.foursuite import SignatureHandler
30
31class EchoClientTestCase(BaseTestCase):
32   
33    def setUp(self):
34        super(EchoClientTestCase, self).setUp()
35       
36        if 'NDGSEC_INT_DEBUG' in os.environ:
37            import pdb
38            pdb.set_trace()
39       
40        if 'NDGSEC_WSSECLNT_UNITTEST_DIR' not in os.environ:
41            os.environ['NDGSEC_WSSECLNT_UNITTEST_DIR'] = \
42                os.path.abspath(os.path.dirname(__file__))
43       
44        configFilePath = mkPath('echoClientTest.cfg')
45        self.cfg = SafeConfigParser()
46        self.cfg.read(configFilePath)
47        uri = self.cfg.get('setUp', 'uri')
48        signingPriKeyFilePath = \
49                        xpdVars(self.cfg.get('setUp', 'signingPriKeyFilePath'))
50        signingPriKeyPwd = self.cfg.get('setUp', 'signingPriKeyPwd')
51        signingCertFilePath = \
52                        xpdVars(self.cfg.get('setUp', 'signingCertFilePath'))
53        caCertFilePathList = [xpdVars(file) for file in \
54                              self.cfg.get('setUp', 
55                                          'caCertFilePathList').split()]
56       
57        # Signature handler object is passed to binding
58        sigHandler = SignatureHandler(
59                                 signingPriKeyFilePath=signingPriKeyFilePath,
60                                 signingPriKeyPwd=signingPriKeyPwd,
61                                 signingCertFilePath=signingCertFilePath,
62                                 caCertFilePathList=caCertFilePathList,
63                                 refC14nInclNS=[],
64                                 signedInfoC14nInclNS=[])
65
66        locator = EchoServiceLocator()
67        self.clnt = locator.getEcho(uri, 
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            print "Message returned was: %s" % resp
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.