source: TI12-security/trunk/python/ndg.security.test/ndg/security/test/MyProxy/MyProxyClientTest.py @ 1881

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

server/MyProxy.py:

  • added _HostCheck class - derived from M2Crypto.SSL.Checker.Checker. It

enables check of host identity but adapted to enable check of host
Distinguished Name against MYPROXY_SERVER_DN environment variable if set.

  • Moved generic connection code into _initConnection method.

conf/myProxyProperties.xml / test/MyProxy/myProxyProperties.xml: added
serverDN element - equivalent to MYPROXY_SERVER_DN environment variable setting.
test/MyProxy/myProxyClientTest.cfg / MyProxy/MyProxyClientTest?.py: various
fixes to tests.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2"""NDG MyProxy client unit tests
3
4NERC Data Grid Project
5
6P J Kershaw 13/12/06
7
8Copyright (C) 2006 CCLRC & NERC
9
10This software may be distributed under the terms of the Q Public License,
11version 1.0 or later.
12"""
13import unittest
14import os
15import sys
16import getpass
17import traceback
18
19from ConfigParser import SafeConfigParser
20from ndg.security.server.MyProxy import MyProxyClient
21
22class MyProxyClientTestCase(unittest.TestCase):
23   
24    def setUp(self):
25       
26        configParser = SafeConfigParser()
27        configParser.read("./myProxyClientTest.cfg")
28       
29        self.cfg = {}
30        for section in configParser.sections():
31            self.cfg[section] = dict(configParser.items(section))
32           
33        self.clnt = MyProxyClient(\
34                          propFilePath=self.cfg['setUp']['propfilepath'])
35       
36
37    def test1Store(self):
38        '''test1Store: upload X509 cert and private key to repository'''
39        ownerPassphrase = self.cfg['test1Store']['ownerpassphrase'] or \
40            getpass.getpass(prompt="\ntest1Store cred. owner pass-phrase: ")
41           
42        try:
43            self.clnt.store(self.cfg['test1Store']['username'],
44                        self.cfg['test1Store']['ownercertfile'],
45                        self.cfg['test1Store']['ownerkeyfile'],
46                        ownerCertFile=self.cfg['test1Store']['ownercertfile'],
47                        ownerKeyFile=self.cfg['test1Store']['ownerkeyfile'],
48                        ownerPassphrase=ownerPassphrase,
49                        force=False)
50            print "Store creds for user %s" % \
51                    self.cfg['test1Store']['username']
52        except:
53            self.fail(traceback.print_exc())
54   
55   
56    def test2GetDelegation(self):
57        '''test2GetDelegation: retrieve proxy cert./private key'''
58        passphrase = self.cfg['test2GetDelegation']['passphrase'] or \
59            getpass.getpass(prompt="\ntest2GetDelegation pass-phrase: ")
60         
61        try:   
62            creds = self.clnt.getDelegation(\
63                                  self.cfg['test2GetDelegation']['username'], 
64                                  passphrase)
65            print "proxy credentials:" 
66            print ''.join(creds)
67            open('proxy-cert.pem', 'w').write(creds[0]+''.join(creds[2:]))
68            open('proxy-key.pem', 'w').write(creds[1])
69        except:
70            self.fail(traceback.print_exc())
71
72
73    def test3Info(self):
74        '''test3Info: Retrieve information about a given credential'''
75        ownerpassphrase = self.cfg['test3Info']['ownerpassphrase'] or \
76            getpass.getpass(prompt="\ntest3Info owner creds pass-phrase: ")
77
78        ownerpassphrase = (ownerpassphrase == 'None') and None
79       
80        try:
81            credExists, errorTxt, fields = self.clnt.info(
82                                 self.cfg['test3Info']['username'],
83                                 self.cfg['test3Info']['ownercertfile'],
84                                 self.cfg['test3Info']['ownerkeyfile'],
85                                 ownerPassphrase=ownerpassphrase)
86            print "test3Info... "
87            print "credExists: %s" % credExists
88            print "errorTxt: " + errorTxt
89            print "fields: %s" % fields
90        except:
91            self.fail(traceback.print_exc())
92
93
94    def test4ChangePassphrase(self):       
95        """test4ChangePassphrase: change pass-phrase protecting a given
96        credential"""
97        passphrase = \
98            self.cfg['test4ChangePassphrase']['ownerpassphrase'] or \
99            getpass.getpass(prompt="\test4ChangePassphrase - pass-phrase: ")
100           
101        newPassphrase = \
102        self.cfg['test4ChangePassphrase']['ownerpassphrase'] or \
103        getpass.getpass(prompt="\test4ChangePassphrase - new pass-phrase: ")
104
105        confirmNewPassphrase = \
106        self.cfg['test4ChangePassphrase']['ownerpassphrase'] or \
107            getpass.getpass(\
108                prompt="\test4ChangePassphrase - confirm new pass-phrase: ")
109
110        ownerPassphrase = (ownerPassphrase == 'None') and passphrase
111   
112        try:
113            self.clnt.changePassphrase(
114                         self.cfg['test4ChangePassphrase']['username'],
115                         passphrase,
116                         newPassphrase, 
117                         self.cfg['test4ChangePassphrase']['ownercertfile'],
118                         self.cfg['test4ChangePassphrase']['ownerkeyfile'],
119                         ownerPassphrase=ownerPassphrase)
120            print "Change pass-phrase"
121        except:
122            self.fail(traceback.print_exc())
123
124
125    def test5Destroy(self):
126        '''test5Destroy: destroy credentials for a given user'''
127
128        ownerPassphrase = self.cfg['test5Destroy']['ownerpassphrase'] or \
129            getpass.getpass(prompt="\ntest5Destroy cred. owner pass-phrase: ")
130
131        ownerPassphrase = (ownerPassphrase == 'None') and None
132
133        try:
134            self.clnt.destroy(self.cfg['test5Destroy']['username'], 
135                    ownerCertFile=self.cfg['test5Destroy']['ownercertfile'],
136                    ownerKeyFile=self.cfg['test5Destroy']['ownerkeyfile'],
137                    ownerPassphrase=ownerPassphrase)
138            print "Destroy creds for user %s" % \
139                                        self.cfg['test5Destroy']['username']
140        except:
141            self.fail(traceback.print_exc())
142       
143 
144#_____________________________________________________________________________       
145class MyProxyClientTestSuite(unittest.TestSuite):
146    def __init__(self):
147        map = map(MyProxyClientTestCase,
148                  (
149                    "test1Store",
150                    "test2GetDelegation",
151                    "test3Info",
152                    "test4ChangePassphrase",
153                    "test5Destroy",
154                  ))
155        unittest.TestSuite.__init__(self, map)
156                                       
157if __name__ == "__main__":
158    unittest.main()
Note: See TracBrowser for help on using the repository browser.