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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.test/ndg/security/test/unit/wssecurity/dom/client/test_echoclient.py@5359
Revision 5359, 3.5 KB checked in by pjkersha, 13 years ago (diff)
  • ndg.security.test.unit.wssecurity.foursuite: WS-Security signature handler - added a unit test case for a client not setting a timestamp in the input message and the server configured to catch it and raise an exception (using timestampMustBeSet config param)
  • 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.unit import BaseTestCase
29from ndg.security.common.wssecurity.signaturehandler.dom import \
30    SignatureHandler
31from ndg.security.common.wssecurity.signaturehandler import NoSignatureFound
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 test01Echo(self):
75           
76        try:
77            resp = self.clnt.Echo("Hello from client")
78            print "Message returned was: %s" % resp
79        except:
80            self.fail(traceback.print_exc())
81       
82
83    def test02ServerRaiseMissingTimestampError(self):
84        # Get server to catch that no timestamp was provided
85       
86        self.clnt.binding.sig_handler.addTimestamp = False
87        try:
88            resp = self.clnt.Echo("Hello again from client")
89           
90        except NoSignatureFound:
91            print "PASSED - server rejected client message with no timestamp"
92        else:
93            self.fail("Expecting error from server because client didn't set "
94                      "a timestamp element")
95                                       
96if __name__ == "__main__":
97    unittest.main()
Note: See TracBrowser for help on using the repository browser.