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

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

Added capability to allow for clock skew between client and server for WS-Security timestamp handling. This is included in the 4Suite and DOM based implementations.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2"""WS-Security Digital Signature unit tests
3
4NERC DataGrid 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 traceback
19
20from os.path import expandvars as xpdVars
21from os.path import join as jnPath
22mkPath = lambda file: jnPath(os.environ['NDGSEC_WSSECLNT_UNITTEST_DIR'], file)
23from ConfigParser import SafeConfigParser
24
25from EchoService_services import EchoServiceLocator
26
27from ndg.security.test.unit import BaseTestCase
28from ndg.security.common.wssecurity.signaturehandler.dom import \
29    SignatureHandler
30from ndg.security.common.wssecurity.signaturehandler import NoSignatureFound, \
31    TimestampError
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        cfg = SafeConfigParser()
48        cfg.read(configFilePath)
49        uri = cfg.get('setUp', 'uri')
50       
51        # Signature handler object is passed to binding
52        sigHandler = SignatureHandler(cfg=configFilePath,
53                                      cfgFileSection='setUp')
54        locator = EchoServiceLocator()
55        self.clnt = locator.getEcho(uri, 
56                                    sig_handler=sigHandler,
57                                    tracefile=sys.stderr)
58       
59    def test01Echo(self):
60           
61        resp = self.clnt.Echo("Hello from client")
62        print("Message returned was: %s" % resp)       
63
64    def test02ServerRaiseMissingTimestampError(self):
65        # Get server to catch that no timestamp was provided
66       
67        self.clnt.binding.sig_handler.addTimestamp = False
68        try:
69            resp = self.clnt.Echo("Hello again from client")
70           
71        except NoSignatureFound:
72            print "PASSED - server rejected client message with no timestamp"
73        else:
74            self.fail("Expecting error from server because client didn't set "
75                      "a timestamp element")
76
77    def test03ClientRaiseTimestampError(self):
78        # Get client to catch a mismatch in the created time for the server
79        # response by adding a clock skew to the client
80       
81        self.clnt.binding.sig_handler.timestampClockSkew = -300.0
82        try:
83            resp = self.clnt.Echo("Hello again from client")
84           
85        except TimestampError:
86            print "PASSED - client rejected server message created timestamp"
87        else:
88            self.fail("Expecting error from client because client set a "
89                      "a timestamp clock skew")
90                                       
91if __name__ == "__main__":
92    unittest.main()
Note: See TracBrowser for help on using the repository browser.