source: TI12-security/trunk/WSSecurity/ndg/wssecurity/test/unit/signaturehandler/foursuite/client/test_echoclient.py @ 6396

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/WSSecurity/ndg/wssecurity/test/unit/signaturehandler/foursuite/client/test_echoclient.py@6396
Revision 6396, 3.4 KB checked in by pjkersha, 11 years ago (diff)
  • 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 os
16import sys
17
18from os.path import join, dirname, abspath
19mkPath = lambda file: join(os.environ['NDGSEC_WSSECLNT_UNITTEST_DIR'], file)
20
21from ConfigParser import SafeConfigParser
22
23from EchoService_services import EchoServiceLocator
24
25from ndg.wssecurity.test.unit import BaseTestCase
26from ndg.wssecurity.common import TimestampError
27from ndg.wssecurity.common.utils.zsi import DomletteReader, DomletteElementProxy
28from ndg.wssecurity.common.signaturehandler import (NoSignatureFound, 
29                                                    SignatureHandlerFactory)
30#from ndg.wssecurity.common.signaturehandler.foursuite import SignatureHandler
31
32
33class EchoClientTestCase(BaseTestCase):
34    """Test 4Suite-XML based WS-Security Signature Handler"""
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        configFilePath = mkPath('echoClientTest.cfg')
48        self.cfg = SafeConfigParser()
49        self.cfg.read(configFilePath)
50        uri = self.cfg.get('setUp', 'uri')
51       
52        # Signature handler object is passed to binding
53        sigHandler = SignatureHandlerFactory.fromConfigFile(configFilePath, 
54                                                            sectionName='setUp')
55
56        locator = EchoServiceLocator()
57        self.clnt = locator.getEcho(uri,
58                                    readerclass=DomletteReader,
59                                    writerclass=DomletteElementProxy, 
60                                    sig_handler=sigHandler,
61                                    tracefile=sys.stderr)
62       
63    def test01Echo(self):
64           
65        resp = self.clnt.Echo("Hello from client")
66        print("Message returned was: %s" % resp)
67
68    def test02ServerRaiseMissingTimestampError(self):
69        # Get server to catch that no timestamp was provided
70       
71        self.clnt.binding.sig_handler.addTimestamp = False
72        try:
73            resp = self.clnt.Echo("Hello again from client")
74           
75        except NoSignatureFound:
76            print("PASSED - server rejected client message with no timestamp")
77        else:
78            self.fail("Expecting error from server because client didn't set "
79                      "a timestamp element")
80
81    def test03ClientRaiseTimestampError(self):
82        # Get client to catch a mismatch in the created time for the server
83        # response by adding a clock skew to the client
84       
85        self.clnt.binding.sig_handler.timestampClockSkew = -300.0
86        try:
87            resp = self.clnt.Echo("Hello again from client")
88           
89        except TimestampError:
90            print "PASSED - client rejected server message created timestamp"
91        else:
92            self.fail("Expecting error from client because client set a "
93                      "a timestamp clock skew")
94
95if __name__ == "__main__":
96    unittest.main()
Note: See TracBrowser for help on using the repository browser.