source: TI12-security/trunk/python/Tests/AttAuthorityClientTest.py @ 848

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/Tests/AttAuthorityClientTest.py@848
Revision 848, 4.2 KB checked in by pjkersha, 14 years ago (diff)

Testing AttAuthorityClient? from SecurityClient?.py. Applied fixes to AttAuthority?
getTrustedHostInfo to ensure unique roles are returned.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2
3"""NDG Attribute Authority client - makes requests for authorisation
4
5NERC Data Grid Project
6
7P J Kershaw 05/05/05
8
9Copyright (C) 2006 CCLRC & NERC
10
11This software may be distributed under the terms of the Q Public License,
12version 1.0 or later.
13"""
14import unittest
15import os
16import sys
17
18from ZSI import ServiceProxy
19
20from NDG.AttAuthorityIO import *
21
22
23class attAuthorityClientTestCase(unittest.TestCase):
24   
25    def setUp(self):
26        try:
27            # Session Manager WSDL
28            aaWSDL = 'http://glue.badc.rl.ac.uk/attAuthority.wsdl'
29   
30            # Instantiate WS proxy
31            self.aaSrv = ServiceProxy(aaWSDL, 
32                                      use_wsdl=True, 
33                                      tracefile=sys.stderr)
34        except Exception, e:
35            self.fail(str(e))
36           
37           
38    def tearDown(self):
39        pass
40   
41   
42    def getPubKeyTest(self):
43        try:
44            # Request an attribute certificate from an Attribute Authority
45            # using the proxyCert returned from connect()
46#            import pdb
47#            pdb.set_trace()
48            pubKeyReq = PubKeyReq()
49            resp = self.aaSrv.getPubKey(pubKeyReq=pubKeyReq())
50            pubKeyResp = PubKeyResp(xmlTxt=resp['pubKeyResp'])
51   
52            if 'errMsg' in pubKeyResp and pubKeyResp['errMsg']:
53                raise Exception(pubKeyResp['errMsg'])
54           
55            print "Attribute Authority public key:\n" + pubKeyResp['pubKey']
56                         
57        except Exception, e:
58            self.fail(str(e))
59
60
61    def getTrustedHostInfoTest(self):
62       
63        try:
64            pass
65        except Exception, e:
66            self.fail(str(e))
67
68
69    def reqAuthorisationTest(self):       
70        """Request authorisation from NDG Attribute Authority Web Service."""
71   
72        # Attribute Authority WSDL
73        aaWSDL = './attAuthority.wsdl'
74       
75        # User's proxy certificate
76        usrProxyCertFilePath = "./certs/pjkproxy.pem"
77   
78        # Existing Attribute Certificate held in user's CredentialWallet. 
79        # This is available for use with trusted data centres to make new
80        # mapped Attribute Certificates
81        usrAttCertFilePath = "./attCert/attCert-pjk-BADC.xml"
82   
83        # Make Attribute Authority raise an exception
84        #usrAttCertFilePath = "attCert-tampered.xml"
85   
86   
87        print "Requesting authorisation for user cert file: \"%s\"" % \
88              usrProxyCertFilePath
89   
90   
91        # Read user Proxy Certificate into a string ready for passing via WS
92        try:
93            usrProxyCertFileTxt = open(usrProxyCertFilePath, 'r').read()
94           
95        except IOError, ioErr:
96            raise "Error reading proxy certificate file \"%s\": %s" % \
97                                    (ioErr.filename, ioErr.strerror)
98   
99   
100        # Simlarly for Attribute Certificate if present ...
101        if usrAttCertFilePath is not None:
102           
103            try:
104                usrAttCertFileTxt = open(usrAttCertFilePath, 'r').read()
105               
106            except IOError, ioErr:
107                raise "Error reading attribute certificate file \"%s\": %s" % \
108                                        (ioErr.filename, ioErr.strerror)
109        else:
110            usrAttCertFileTxt = None
111           
112   
113        # Make authorsation request
114        try:   
115            resp = self.aaSrv.reqAuthorisation(\
116                                          usrProxyCert=usrProxyCertFileTxt,
117                                          usrAttCert=usrAttCertFileTxt)
118            if resp['errMsg']:
119                raise Exception(resp['errMsg'])
120           
121            return resp['attCert']
122           
123        except Exception, e:
124            self.fail(str(e))
125       
126 
127#_____________________________________________________________________________       
128class attAuthorityClientTestSuite(unittest.TestSuite):
129    def __init__(self):
130        map = map(attAuthorityClientTestCase,
131                  (
132                    "getTrustedHostInfoTest",
133                    "reqAuthorisationTest",
134                    "getPubKeyTest",
135                  ))
136        unittest.TestSuite.__init__(self, map)
137                                       
138if __name__ == "__main__":
139    unittest.main()
Note: See TracBrowser for help on using the repository browser.