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

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

python/ndg.security.test/ndg/security/test/AttAuthority/AttAuthorityClientTest.py: added config parser so that params can be set from a configuration file.

python/ndg.security.test/ndg/security/test/SessionMgr/SessionMgrClientTest.
py and python/ndg.security.test/ndg/security/test/SessionMgr/sessionMgrClientTest.cfg: added config parser + prompt for passwords where not set in config.

python/ndg.security.common/ndg/security/common/AttAuthority/init.py:
AA client code - added documentation and changed getAttCert so that an AttCert?
type can be passed in as well as a string for userAttCert arg.

  • 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
7
8@copyright (C) 2006 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
21
22class AttAuthorityClientTestCase(unittest.TestCase):
23   
24    def setUp(self):
25       
26        configParser = SafeConfigParser()
27        configParser.read("./attAuthorityClientTest.cfg")
28       
29        self.cfg = {}
30        for section in configParser.sections():
31            self.cfg[section] = dict(configParser.items(section))
32
33        # Instantiate WS proxy
34        self.clnt = AttAuthorityClient(self.cfg['setUp']['uri'], 
35                                       tracefile=sys.stderr)
36   
37   
38    def testGetPubKey(self):
39        '''testGetPubKey: retrieve Attribute Authority's X.509 cert.'''
40        #import pdb;pdb.set_trace()
41        resp = self.clnt.getPubKey()
42        print "Attribute Authority public key:\n" + resp
43       
44
45    def testGetTrustedHostInfo(self):
46        """testGetTrustedHostInfo: retrieve trusted host info matching a
47        given role"""
48        role = 'role'
49        self.clnt.getTrustedHostInfo(role)
50
51
52    def testGetTrustedHostInfoWithNoRole(self):
53        """testGetTrustedHostInfoWithNoRole: retrieve trusted host info
54        irrespective of role"""
55        self.clnt.getTrustedHostInfo()
56
57    def testGetHostInfo(self):
58        """testGetHostInfo: retrieve info for AA host"""
59        self.clnt.getHostInfo()
60
61
62    def testGetAttCert(self):       
63        """testGetAttCert: Request attribute certificate from NDG Attribute
64        Authority Web Service."""
65   
66        # User's proxy certificate
67        userCertFilePath = "/tmp/x509up_u1001"
68   
69        # Existing Attribute Certificate held in user's CredentialWallet. 
70        # This is available for use with trusted data centres to make new
71        # mapped Attribute Certificates
72        userAttCertFilePath = None
73   
74        # Read user Proxy Certificate into a string ready for passing via WS
75        try:
76            userCertFileTxt = open(userCertFilePath, 'r').read()
77           
78        except IOError, ioErr:
79            raise "Error reading proxy certificate file \"%s\": %s" % \
80                                    (ioErr.filename, ioErr.strerror)
81   
82   
83        # Simlarly for Attribute Certificate if present ...
84        if userAttCertFilePath is not None:
85           
86            try:
87                userAttCertFileTxt = open(userAttCertFilePath, 'r').read()
88               
89            except IOError, ioErr:
90                raise "Error reading attribute certificate file \"%s\": %s" %\
91                                        (ioErr.filename, ioErr.strerror)
92        else:
93            userAttCertFileTxt = None
94           
95   
96        # Make attribute certificate request
97        resp = self.clnt.getAttCert(userCertFileTxt)
98        return resp
99       
100 
101#_____________________________________________________________________________       
102class AttAuthorityClientTestSuite(unittest.TestSuite):
103    def __init__(self):
104        map = map(AttAuthorityClientTestCase,
105                  (
106                    "testGetHostInfo",
107                    "testGetTrustedHostInfo",
108                    "testGetTrustedHostInfoWithNoRole",
109                    "testGetAttCert",
110                    "testGetPubKey",
111                  ))
112        unittest.TestSuite.__init__(self, map)
113                                       
114if __name__ == "__main__":
115    unittest.main()
Note: See TracBrowser for help on using the repository browser.