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

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