source: TI12-security/trunk/python/ndg.security.test/ndg/security/test/AttAuthority/AttAuthorityClientTest.py @ 2251

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.test/ndg/security/test/AttAuthority/AttAuthorityClientTest.py@2251
Revision 2251, 6.5 KB checked in by pjkersha, 13 years ago (diff)

ndg.security.server/setup.py:

ndg.security.server/setup.cfg:

  • removed EasyInstall? and build sections
  • reinstated tag_build - set to '_dews' - and tag_svn_revision

ndg.security.server/ndg/security/server/AttAuthority/server-config.tac:

  • removed socket import and added os
  • added M2Crypto SSL support - works with Python client unit tests (required setting SSL v2 and 3 support)

but problems with WebSphere? client

ndg.security.server/ndg/security/server/AttAuthority/init.py,
ndg.security.server/ndg/security/server/conf/attAuthorityProperties.xml,
ndg.security.test/ndg/security/test/AttAuthority/siteAAttAuthorityProperties.xml,
ndg.security.test/ndg/security/test/AttAuthority/siteBAttAuthorityProperties.xml:

  • added sslKeyPwd setting for properties

ndg.security.server/ndg/security/server/MyProxy.py:

  • ensure cnHostPfx is reinitialised to if equal to None

ndg.security.common/setup.py:

  • added M2Crypto, ZSI and 4Suite to dependencies
  • revised dependency links to use NDG site, http://ndg.nerc.ac.uk/dist and ZSI sourceforge link taken

from pyGridWare settings. Latter won't work for PyXML but does work from command line ??

ndg.security.common/ndg/security/common/wsSecurity.py:

  • IMPORTANT FIX * - removed strip() from signed info digest calc - NOT needed and caused some problems

with verify.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2"""NDG Attribute Authority client unit tests
3
4NERC Data Grid Project
5
6@author P J Kershaw 05/05/05, major update 16/01/07
7
8@copyright (C) 2007 CCLRC & NERC
9
10@license This software may be distributed under the terms of the Q Public
11License, version 1.0 or later.
12"""
13
14reposID = '$Id$'
15
16import unittest
17import os, sys, getpass
18from ConfigParser import SafeConfigParser
19
20from ndg.security.common.AttAuthority import AttAuthorityClient
21from ndg.security.common.AttCert import AttCertRead
22
23
24class AttAuthorityClientTestCase(unittest.TestCase):
25   
26    def setUp(self):
27
28        configParser = SafeConfigParser()
29        configParser.read("./attAuthorityClientTest.cfg")
30       
31        self.cfg = {}
32        for section in configParser.sections():
33            self.cfg[section] = dict(configParser.items(section))
34
35        tracefile = sys.stderr
36
37        # Instantiate WS proxy
38        self.clnt = AttAuthorityClient(uri=self.cfg['setUp']['uri'],
39               signingCertFilePath=self.cfg['setUp']['usercertfilepath'],
40               signingPriKeyFilePath=self.cfg['setUp']['userprikeyfilepath'],
41               tracefile=sys.stderr)
42           
43   
44    def test1GetX509Cert(self):
45        '''test1GetX509Cert: retrieve Attribute Authority's X.509 cert.'''
46        resp = self.clnt.getX509Cert()
47        print "Attribute Authority X.509 cert.:\n" + resp
48
49    def test2GetHostInfo(self):
50        """test2GetHostInfo: retrieve info for AA host"""
51        hostInfo = self.clnt.getHostInfo()
52        print "Host Info:\n %s" % hostInfo
53       
54
55    def test3GetTrustedHostInfo(self):
56        """test3GetTrustedHostInfo: retrieve trusted host info matching a
57        given role"""
58        trustedHostInfo = self.clnt.getTrustedHostInfo(\
59                                 self.cfg['test3GetTrustedHostInfo']['role'])
60        print "Trusted Host Info:\n %s" % trustedHostInfo
61
62
63    def test4GetTrustedHostInfoWithNoRole(self):
64        """test4GetTrustedHostInfoWithNoRole: retrieve trusted host info
65        irrespective of role"""
66        trustedHostInfo = self.clnt.getTrustedHostInfo()
67        print "Trusted Host Info:\n %s" % trustedHostInfo
68
69
70    def test5GetAttCert(self):       
71        """test5GetAttCert: Request attribute certificate from NDG Attribute
72        Authority Web Service."""
73   
74        # Read user Certificate into a string ready for passing via WS
75        try:
76            userCertFilePath = \
77                self.cfg['test5GetAttCert'].get('issuingusercertfilepath')
78            userCertTxt = open(userCertFilePath, 'r').read()
79       
80        except TypeError:
81            # No issuing cert set
82            userCertTxt = None
83               
84        except IOError, ioErr:
85            raise "Error reading certificate file \"%s\": %s" % \
86                                    (ioErr.filename, ioErr.strerror)
87
88        # Make attribute certificate request
89        attCert = self.clnt.getAttCert(userCert=userCertTxt)
90       
91        print "Attribute Certificate: \n\n:" + str(attCert)
92       
93        attCert.filePath = self.cfg['test5GetAttCert']['attcertfilepath']
94        attCert.write()
95       
96    def test6GetAttCertWithUserIdSet(self):       
97        """test6GetAttCertWithUserIdSet: Request attribute certificate from
98        NDG Attribute Authority Web Service setting a specific user Id
99        independent of the signer of the SOAP request."""
100   
101        # Read user Certificate into a string ready for passing via WS
102        try:
103            userCertFilePath = \
104    self.cfg['test6GetAttCertWithUserIdSet'].get('issuingusercertfilepath')
105            userCertTxt = open(userCertFilePath, 'r').read()
106       
107        except TypeError:
108            # No issuing cert set
109            userCertTxt = None
110               
111        except IOError, ioErr:
112            raise "Error reading certificate file \"%s\": %s" % \
113                                    (ioErr.filename, ioErr.strerror)
114
115        # Make attribute certificate request
116        userId = self.cfg['test6GetAttCertWithUserIdSet']['userid']
117        attCert = self.clnt.getAttCert(userId=userId,
118                                       userCert=userCertTxt)
119       
120        print "Attribute Certificate: \n\n:" + str(attCert)
121       
122        attCert.filePath = self.cfg['test5GetAttCert']['attcertfilepath']
123        attCert.write()
124
125    def test7GetMappedAttCert(self):       
126        """test7GetMappedAttCert: Request mapped attribute certificate from
127        NDG Attribute Authority Web Service."""
128   
129        # Read user Certificate into a string ready for passing via WS
130        try:
131            userCertFilePath = \
132            self.cfg['test7GetMappedAttCert'].get('issuingusercertfilepath')
133            userCertTxt = open(userCertFilePath, 'r').read()
134       
135        except TypeError:
136            # No issuing cert set
137            userCertTxt = None
138               
139        except IOError, ioErr:
140            raise "Error reading certificate file \"%s\": %s" % \
141                                    (ioErr.filename, ioErr.strerror)
142   
143   
144        # Simlarly for Attribute Certificate
145        try:
146            userAttCert = AttCertRead(\
147                self.cfg['test7GetMappedAttCert']['userattcertfilepath'])
148           
149        except IOError, ioErr:
150            raise "Error reading attribute certificate file \"%s\": %s" %\
151                                    (ioErr.filename, ioErr.strerror)
152       
153        # Make client to site B Attribute Authority   
154        clnt = AttAuthorityClient(
155uri=self.cfg['test7GetMappedAttCert']['uri'], 
156signingCertFilePath=self.cfg['test7GetMappedAttCert']['usercertfilepath'],
157signingPriKeyFilePath=self.cfg['test7GetMappedAttCert']['userprikeyfilepath'],
158tracefile=sys.stderr)
159   
160        # Make attribute certificate request
161        attCert = clnt.getAttCert(userCert=userCertTxt,
162                                  userAttCert=userAttCert)
163        print "Attribute Certificate: \n\n:" + str(attCert)
164 
165 
166#_____________________________________________________________________________       
167class AttAuthorityClientTestSuite(unittest.TestSuite):
168    def __init__(self):
169        map = map(AttAuthorityClientTestCase,
170                  (
171                    "test1GetX509Cert",
172                    "test2GetHostInfo",
173                    "test3GetTrustedHostInfo",
174                    "test4GetTrustedHostInfoWithNoRole",
175                    "test5GetAttCert",
176                    "test6GetAttCertWithUserIdSet",
177                    "test7GetMappedAttCert",
178                  ))
179        unittest.TestSuite.__init__(self, map)
180                                       
181if __name__ == "__main__":
182    unittest.main()
Note: See TracBrowser for help on using the repository browser.