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

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