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

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@5359
Revision 5359, 3.9 KB checked in by pjkersha, 12 years ago (diff)
  • ndg.security.test.unit.wssecurity.foursuite: WS-Security signature handler - added a unit test case for a client not setting a timestamp in the input message and the server configured to catch it and raise an exception (using timestampMustBeSet config param)
  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2"""WS-Security Digital Signature unit tests
3
4NERC Data Grid 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 getpass
19import traceback
20
21from os.path import expandvars as xpdVars
22from os.path import join as jnPath
23mkPath = lambda file: jnPath(os.environ['NDGSEC_WSSECLNT_UNITTEST_DIR'], file)
24from os.path import join, dirname, abspath
25from ConfigParser import SafeConfigParser
26
27from EchoService_services import EchoServiceLocator
28
29from ndg.security.test.unit import BaseTestCase
30from ndg.security.common.wssecurity.signaturehandler.foursuite import \
31    SignatureHandler
32from ndg.security.common.wssecurity.signaturehandler import NoSignatureFound
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        signingPriKeyFilePath = \
59                        xpdVars(self.cfg.get('setUp', 'signingPriKeyFilePath'))
60        signingPriKeyPwd = self.cfg.get('setUp', 'signingPriKeyPwd')
61        signingCertFilePath = \
62                        xpdVars(self.cfg.get('setUp', 'signingCertFilePath'))
63        caCertFilePathList = [xpdVars(file) for file in \
64                              self.cfg.get('setUp', 
65                                          'caCertFilePathList').split()]
66       
67        # Signature handler object is passed to binding
68        sigHandler = SignatureHandler(
69                                 signingPriKeyFilePath=signingPriKeyFilePath,
70                                 signingPriKeyPwd=signingPriKeyPwd,
71                                 signingCertFilePath=signingCertFilePath,
72                                 caCertFilePathList=caCertFilePathList,
73                                 refC14nInclNS=[],
74                                 signedInfoC14nInclNS=[])
75
76        locator = EchoServiceLocator()
77        self.clnt = locator.getEcho(uri,
78                                    readerclass=DomletteReader,
79                                    writerclass=DomletteElementProxy, 
80                                    sig_handler=sigHandler,
81                                    tracefile=sys.stderr)
82       
83
84    def test01Echo(self):
85           
86        try:
87            resp = self.clnt.Echo("Hello from client")
88            print "Message returned was: %s" % resp
89        except:
90            self.fail(traceback.print_exc())
91
92
93    def test02ServerRaiseMissingTimestampError(self):
94        # Get server to catch that no timestamp was provided
95       
96        self.clnt.binding.sig_handler.addTimestamp = False
97        try:
98            resp = self.clnt.Echo("Hello again from client")
99           
100        except NoSignatureFound:
101            print "PASSED - server rejected client message with no timestamp"
102        else:
103            self.fail("Expecting error from server because client didn't set "
104                      "a timestamp element")
105
106if __name__ == "__main__":
107    unittest.main()
Note: See TracBrowser for help on using the repository browser.