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

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

python/ndg.security.server/ndg/security/server/SessionMgr/init.py:
started integration of new MyProxyClient? class.

python/ndg.security.server/ndg/security/server/MyProxy.py:
Added new MyProxyClient? class and removed old code that mdae system calls
to MyProxy? executables.

python/ndg.security.test/ndg/security/test/MyProxy/myProxyProperties.xml and
python/conf/myProxyProperties.xml: added comments to the effect that elements
corresponding to environment variables must be removed in order for the
environment variable setting to take effect and not be overridden.

python/ndg.security.test/ndg/security/test/MyProxy/myProxyClientTest.cfg:
ownerCertFile and ownerKeyFile pick up a proxy cert / key stored from get
delegation test.

python/ndg.security.test/ndg/security/test/MyProxy/MyProxyClientTest.py:
fixes to test4ChangePassphrase and test3Info tests.
architecture/uml/ndg2-dews-security-beta.eap

  • 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        try:
98            passphrase = self.cfg['test4ChangePassphrase']['passphrase'] or \
99            getpass.getpass(prompt="test4ChangePassphrase - pass-phrase: ")
100           
101            if not self.cfg['test4ChangePassphrase']['newpassphrase']:
102                newPassphrase = getpass.getpass(\
103                        prompt="test4ChangePassphrase - new pass-phrase: ")
104   
105                confirmNewPassphrase = getpass.getpass(\
106                prompt="test4ChangePassphrase - confirm new pass-phrase: ")
107   
108                if newPassphrase != confirmNewPassphrase:
109                    self.fail("New and confirmed new password don't match")
110                   
111            ownerPassphrase = \
112                self.cfg['test4ChangePassphrase'].get('ownerpassphrase') or \
113                passphrase
114   
115            self.clnt.changePassphrase(
116                         self.cfg['test4ChangePassphrase']['username'],
117                         passphrase,
118                         newPassphrase, 
119                         self.cfg['test4ChangePassphrase']['ownercertfile'],
120                         self.cfg['test4ChangePassphrase']['ownerkeyfile'],
121                         ownerPassphrase=ownerPassphrase)
122            print "Change pass-phrase"
123        except:
124            self.fail(traceback.print_exc())
125
126
127    def test5Destroy(self):
128        '''test5Destroy: destroy credentials for a given user'''
129
130        ownerPassphrase = self.cfg['test5Destroy']['ownerpassphrase'] or \
131            getpass.getpass(prompt="\ntest5Destroy cred. owner pass-phrase: ")
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.