source: TI12-security/trunk/python/ndg.security.test/ndg/security/test/sessionCookie/SessionCookieTest.py @ 3192

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

Working version of Session Manager unit tests with certs included in SVN issued from test CA.

security/python/ndg.security.test/ndg/security/test/attAuthority/README: added note about test config file.

security/python/ndg.security.test/ndg/security/test/attAuthority/siteAAttAuthorityProperties.xml,
security/python/ndg.security.test/ndg/security/test/attAuthority/siteBAttAuthorityProperties.xml:
added note about MyProxy? CA certificate inclusion for WSSE signature handler to trust requests authenticated by certs from MyProxy? CA. This is needed for running these services with Session Manager and Session Manager Cleint unit tests

security/python/ndg.security.test/ndg/security/test/ca/README: added note that this unit test is currently defunct.

security/python/ndg.security.test/ndg/security/test/gatekeeper/README,
security/python/ndg.security.test/ndg/security/test/Log: added

security/python/ndg.security.test/ndg/security/test/myProxy/README: added note about ensuring test creds are removed from the repository.

security/python/ndg.security.test/ndg/security/test/sessionCookie/README: note that this test is defunct. Pylons code can perform the same function

security/python/ndg.security.test/ndg/security/test/sessionCookie/SessionCookieTest.py,
security/python/ndg.security.test/ndg/security/test/sessionCookie/sessionCookieTest.cfg:
altered so that files are ref'd by env vars so that tests can be run from any dir

security/python/ndg.security.test/ndg/security/test/README: added

security/python/ndg.security.test/ndg/security/test/sessionMgr/sessionMgrProperties.xml,
security/python/ndg.security.test/ndg/security/test/sessionMgr/sessionMgrTest.cfg,
security/python/ndg.security.test/ndg/security/test/sessionMgr/test.py:

  • altered so that files are ref'd by env vars so that tests can be run from any dir
  • test1Connect PKI output is dumped to user.creds file.
  • Property svn:executable set to *
  • Property svn:keywords set to Id
Line 
1#!/usr/bin/env python
2
3"""Test harness for NDG Session Cookie
4
5NERC Data Grid Project
6"""
7__author__ = "P J Kershaw"
8__date__ = "28/11/06"
9__copyright__ = "(C) 2007 STFC & NERC"
10__license__ = \
11"""This software may be distributed under the terms of the Q Public
12License, version 1.0 or later."""
13__contact__ = "P.J.Kershaw@rl.ac.uk"
14__revision__ = '$Id$'
15
16import unittest
17import os, sys, getpass, base64
18 
19from ndg.security.common.sessionCookie import SessionCookie
20from datetime import datetime, timedelta
21from ConfigParser import SafeConfigParser, NoOptionError
22
23xpdVars = os.path.expandvars
24jnPath = os.path.join
25mkPath=lambda file:jnPath(os.environ['NDGSEC_SESSIONCOOKIE_UNITTEST_DIR'],file)
26
27
28class SessionCookieTestCase(unittest.TestCase):
29    raise NotImplementedError(\
30    "SessionCookie class not used in current implementation of NDG Security")
31    priKeyPwd = None
32       
33    def setUp(self):
34        if 'NDGSEC_INT_DEBUG' in os.environ:
35            import pdb
36            pdb.set_trace()
37       
38        if 'NDGSEC_SESSIONCOOKIE_UNITTEST_DIR' not in os.environ:
39            os.environ['NDGSEC_SESSIONCOOKIE_UNITTEST_DIR'] = \
40                os.path.abspath(os.path.dirname(__file__))
41
42        self.cookie = SessionCookie()
43       
44        configParser = SafeConfigParser()
45        configFilePath=jnPath(os.environ['NDGSEC_SESSIONCOOKIE_UNITTEST_DIR'],
46                              'sessionCookieTest.cfg')
47        configParser.read(configFilePath)
48       
49        self.cookie.x509CertFilePath = xpdVars(configParser.get('setUp', 
50                                                        'x509CertFilePath'))
51        if self.__class__.priKeyPwd is None:
52            try:
53                self.__class__.priKeyPwd = configParser.get('setUp', 
54                                                            'priKeyPwd')
55            except NoOptionError:
56                try:
57                    self.__class__.priKeyPwd = getpass.getpass(\
58                                prompt="\nsetUp - private key password: ")
59                except KeyboardInterrupt:
60                    raise SystemExit
61       
62        self.priKeyFilePath=xpdVars(configParser.get('setUp','priKeyFilePath'))
63       
64        self.cookie.x509CertFilePath = xpdVars(configParser.get('setUp', 
65                                                        'x509CertFilePath'))
66     
67        self.cookie.create('O=NDG/OU=BADC/CN=test',
68                           base64.encodestring(os.urandom(32)).strip(),
69                           'http://localhost:5000/SessionManager')
70       
71           
72    def test1GetSessID(self):
73        """test1GetSessID: check session ID attribute"""       
74        print "Test get session ID: \n%s" % self.cookie.sessID
75     
76    def test2GetUserDN(self):
77        """test2GetUserDN: check user DN attribute"""       
78        print "Test get user DN: \n%s" % self.cookie.userDN
79     
80    def test3GetSessMgrURI(self):
81        """test3GetSessMgrURI: check Session Manager URI attribute"""       
82        print "Test get Session Manager URI: \n%s" % self.cookie.sessMgrURI
83
84    def test4AsString(self):
85        """test4AsString: check conversion to string"""
86        print "Print as string: %s" % self.cookie
87       
88    def test5Parse(self):
89        """test5Parse: check parsing from string"""       
90        print "Test parse from string: \n"
91        newCookie = SessionCookie()
92        newCookie.priKeyPwd = self.__class__.priKeyPwd
93        newCookie.priKeyFilePath = self.priKeyFilePath
94       
95        cookie = newCookie.parse(str(self.cookie))
96        print "Session ID: \n%s" % newCookie.sessID
97        print "User DN: \n%s" % newCookie.userDN
98        print "Session Manager URI: \n%s" % newCookie.sessMgrURI
99                 
100           
101#_____________________________________________________________________________       
102class SessionCookieTestSuite(unittest.TestSuite):
103   
104    def __init__(self):
105        map = map(SessionCookieTestCase,
106                  (
107                    "test1GetSessID",
108                    "test2GetUserDN",
109                    "test3GetSessMgrURI",
110                    "test4AsString",
111                    "test5Parse",
112                  ))
113        unittest.TestSuite.__init__(self, map)
114           
115                                                   
116if __name__ == "__main__":
117    unittest.main()       
Note: See TracBrowser for help on using the repository browser.