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

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

Refactored x509, xmlsec, XMLSecDoc and combinedservices unit tests separating out test files into the config dir.

  • 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 STFC"
9__license__ = \
10"""This software may be distributed under the terms of the Q Public
11License, version 1.0 or later."""
12__contact__ = "Philip.Kershaw@stfc.ac.uk"
13__revision__ = '$Id$'
14import logging
15logging.basicConfig(level=logging.DEBUG)
16
17import unittest
18import os
19import sys
20import getpass
21import traceback
22
23from os.path import expandvars as xpdVars
24from os.path import join as jnPath
25mkPath = lambda file: jnPath(os.environ['NDGSEC_WSSECLNT_UNITTEST_DIR'], file)
26from ConfigParser import SafeConfigParser
27
28from EchoService_services import EchoServiceLocator
29
30from ndg.security.test import BaseTestCase
31from ndg.security.common.wssecurity.dom import SignatureHandler
32
33class EchoClientTestCase(BaseTestCase):
34   
35    def setUp(self):
36        super(EchoClientTestCase, self).setUp()
37       
38        if 'NDGSEC_INT_DEBUG' in os.environ:
39            import pdb
40            pdb.set_trace()
41       
42        if 'NDGSEC_WSSECLNT_UNITTEST_DIR' not in os.environ:
43            os.environ['NDGSEC_WSSECLNT_UNITTEST_DIR'] = \
44                os.path.abspath(os.path.dirname(__file__))
45       
46        configFilePath = mkPath('echoClientTest.cfg')
47        self.cfg = SafeConfigParser()
48        self.cfg.read(configFilePath)
49        uri = self.cfg.get('setUp', 'uri')
50        signingPriKeyFilePath = \
51                        xpdVars(self.cfg.get('setUp', 'signingPriKeyFilePath'))
52        signingPriKeyPwd = self.cfg.get('setUp', 'signingPriKeyPwd')
53        signingCertFilePath = \
54                        xpdVars(self.cfg.get('setUp', 'signingCertFilePath'))
55        caCertFilePathList = [xpdVars(file) for file in \
56                              self.cfg.get('setUp', 
57                                          'caCertFilePathList').split()]
58       
59        # Signature handler object is passed to binding
60        sigHandler = SignatureHandler(
61                                 signingPriKeyFilePath=signingPriKeyFilePath,
62                                 signingPriKeyPwd=signingPriKeyPwd,
63                                 signingCertFilePath=signingCertFilePath,
64                                 caCertFilePathList=caCertFilePathList,
65                                 refC14nInclNS=[],
66                                 signedInfoC14nInclNS=[])
67
68        locator = EchoServiceLocator()
69        self.clnt = locator.getEcho(uri, 
70                                    sig_handler=sigHandler,
71                                    tracefile=sys.stderr)
72       
73
74    def test1Echo(self):
75        '''test1Echo: test signed message and signed response from server'''
76           
77        try:
78            resp = self.clnt.Echo("Hello from client")
79            print "Message returned was: %s" % resp
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.