1 | #!/usr/bin/env python |
---|
2 | """WS-Security Digital Signature unit tests |
---|
3 | |
---|
4 | NERC 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$' |
---|
12 | import logging |
---|
13 | logging.basicConfig(level=logging.DEBUG) |
---|
14 | |
---|
15 | import unittest |
---|
16 | import os |
---|
17 | import sys |
---|
18 | import getpass |
---|
19 | import traceback |
---|
20 | |
---|
21 | from os.path import expandvars as xpdVars |
---|
22 | from os.path import join as jnPath |
---|
23 | mkPath = lambda file: jnPath(os.environ['NDGSEC_WSSECLNT_UNITTEST_DIR'], file) |
---|
24 | from ConfigParser import SafeConfigParser |
---|
25 | |
---|
26 | from EchoService_services import EchoServiceLocator |
---|
27 | |
---|
28 | from ndg.security.test import BaseTestCase |
---|
29 | from ndg.security.common.wssecurity.foursuite import SignatureHandler |
---|
30 | |
---|
31 | class EchoClientTestCase(BaseTestCase): |
---|
32 | |
---|
33 | def setUp(self): |
---|
34 | super(EchoClientTestCase, self).setUp() |
---|
35 | |
---|
36 | if 'NDGSEC_INT_DEBUG' in os.environ: |
---|
37 | import pdb |
---|
38 | pdb.set_trace() |
---|
39 | |
---|
40 | if 'NDGSEC_WSSECLNT_UNITTEST_DIR' not in os.environ: |
---|
41 | os.environ['NDGSEC_WSSECLNT_UNITTEST_DIR'] = \ |
---|
42 | os.path.abspath(os.path.dirname(__file__)) |
---|
43 | |
---|
44 | configFilePath = mkPath('echoClientTest.cfg') |
---|
45 | self.cfg = SafeConfigParser() |
---|
46 | self.cfg.read(configFilePath) |
---|
47 | uri = self.cfg.get('setUp', 'uri') |
---|
48 | signingPriKeyFilePath = \ |
---|
49 | xpdVars(self.cfg.get('setUp', 'signingPriKeyFilePath')) |
---|
50 | signingPriKeyPwd = self.cfg.get('setUp', 'signingPriKeyPwd') |
---|
51 | signingCertFilePath = \ |
---|
52 | xpdVars(self.cfg.get('setUp', 'signingCertFilePath')) |
---|
53 | caCertFilePathList = [xpdVars(file) for file in \ |
---|
54 | self.cfg.get('setUp', |
---|
55 | 'caCertFilePathList').split()] |
---|
56 | |
---|
57 | # Signature handler object is passed to binding |
---|
58 | sigHandler = SignatureHandler( |
---|
59 | signingPriKeyFilePath=signingPriKeyFilePath, |
---|
60 | signingPriKeyPwd=signingPriKeyPwd, |
---|
61 | signingCertFilePath=signingCertFilePath, |
---|
62 | caCertFilePathList=caCertFilePathList, |
---|
63 | refC14nInclNS=[], |
---|
64 | signedInfoC14nInclNS=[]) |
---|
65 | |
---|
66 | locator = EchoServiceLocator() |
---|
67 | self.clnt = locator.getEcho(uri, |
---|
68 | sig_handler=sigHandler, |
---|
69 | tracefile=sys.stderr) |
---|
70 | |
---|
71 | |
---|
72 | def test1Echo(self): |
---|
73 | '''test1Echo: test signed message and signed response from server''' |
---|
74 | |
---|
75 | try: |
---|
76 | resp = self.clnt.Echo("Hello from client") |
---|
77 | print "Message returned was: %s" % resp |
---|
78 | except: |
---|
79 | self.fail(traceback.print_exc()) |
---|
80 | |
---|
81 | #_____________________________________________________________________________ |
---|
82 | class EchoClientTestSuite(unittest.TestSuite): |
---|
83 | def __init__(self): |
---|
84 | map = map(EchoClientTestCase, |
---|
85 | ( |
---|
86 | "test1Echo", |
---|
87 | )) |
---|
88 | unittest.TestSuite.__init__(self, map) |
---|
89 | |
---|
90 | if __name__ == "__main__": |
---|
91 | unittest.main() |
---|