source: TI12-security/trunk/python/ndg_security_test/ndg/security/test/unit/wssecurity/foursuite/client/test_echoclient.py @ 6069

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

Re-release as rc1

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