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

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

Refactoring base signature handler

  • 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 unittest
19
20from os.path import join, dirname, abspath
21mkPath = lambda file: join(os.environ['NDGSEC_WSSECLNT_UNITTEST_DIR'], file)
22
23from ConfigParser import SafeConfigParser
24
25from EchoService_services import EchoServiceLocator
26
27from ndg.security.common.wssecurity.signaturehandler.foursuite import \
28    SignatureHandler
29from ndg.security.common.wssecurity.signaturehandler import NoSignatureFound, \
30    TimestampError
31from ndg.security.common.wssecurity.utils import DomletteReader, \
32    DomletteElementProxy
33
34
35class EchoClientTestCase(unittest.TestCase):
36   
37    def setUp(self):
38        super(EchoClientTestCase, self).setUp()
39       
40        if 'NDGSEC_INT_DEBUG' in os.environ:
41            import pdb
42            pdb.set_trace()
43       
44        if 'NDGSEC_WSSECLNT_UNITTEST_DIR' not in os.environ:
45            os.environ['NDGSEC_WSSECLNT_UNITTEST_DIR'] = \
46                abspath(dirname(__file__))
47   
48        if 'NDGSEC_TEST_CONFIG_DIR' not in os.environ:
49            os.environ['NDGSEC_TEST_CONFIG_DIR'] = \
50                abspath(join(dirname(dirname(dirname(dirname(__file__)))),
51                             'config'))
52       
53        configFilePath = mkPath('echoClientTest.cfg')
54        self.cfg = SafeConfigParser()
55        self.cfg.read(configFilePath)
56        uri = self.cfg.get('setUp', 'uri')
57       
58        # Signature handler object is passed to binding
59        sigHandler = SignatureHandler.fromConfigFile(configFilePath,
60                                                     section='setUp')
61
62        locator = EchoServiceLocator()
63        self.clnt = locator.getEcho(uri,
64                                    readerclass=DomletteReader,
65                                    writerclass=DomletteElementProxy, 
66                                    sig_handler=sigHandler,
67                                    tracefile=sys.stderr)
68       
69
70    def test01Echo(self):
71           
72        resp = self.clnt.Echo("Hello from client")
73        print "Message returned was: %s" % resp
74
75
76    def test02ServerRaiseMissingTimestampError(self):
77        # Get server to catch that no timestamp was provided
78       
79        self.clnt.binding.sig_handler.addTimestamp = False
80        try:
81            resp = self.clnt.Echo("Hello again from client")
82           
83        except NoSignatureFound:
84            print("PASSED - server rejected client message with no timestamp")
85        else:
86            self.fail("Expecting error from server because client didn't set "
87                      "a timestamp element")
88
89    def test03ClientRaiseTimestampError(self):
90        # Get client to catch a mismatch in the created time for the server
91        # response by adding a clock skew to the client
92       
93        self.clnt.binding.sig_handler.timestampClockSkew = -300.0
94        try:
95            resp = self.clnt.Echo("Hello again from client")
96           
97        except TimestampError:
98            print "PASSED - client rejected server message created timestamp"
99        else:
100            self.fail("Expecting error from client because client set a "
101                      "a timestamp clock skew")
102
103if __name__ == "__main__":
104    unittest.main()
Note: See TracBrowser for help on using the repository browser.