source: TI12-security/trunk/python/ndg_security_test/ndg/security/test/unit/openid/provider/axinterface/test_axinterface.py @ 6062

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg_security_test/ndg/security/test/unit/openid/provider/axinterface/test_axinterface.py@6062
Revision 6062, 2.8 KB checked in by pjkersha, 11 years ago (diff)
  • Working SamlPIPMiddleware - the Policy Information Point with an interface to the SAML Attribute Authority. The PIP retrieves user credential information for the PDP.
  • Fixed ndg.security.test.unit.wsgi.authz.test_authz unit tests for the above.
Line 
1"""OpenID Provider AX Interface unit tests
2
3NERC DataGrid Project
4"""
5__author__ = "P J Kershaw"
6__date__ = "11/11/09"
7__copyright__ = "(C) 2009 Science and Technology Facilities Council"
8__license__ = "BSD - see LICENSE file in top-level directory"
9__contact__ = "Philip.Kershaw@stfc.ac.uk"
10__revision__ = '$Id$'
11from os import path
12
13from openid.extensions.ax import FetchRequest, FetchResponse, AttrInfo
14       
15from ndg.security.test.unit import BaseTestCase
16from ndg.security.server.wsgi.openid.provider.axinterface import (
17                                                        AXInterfaceConfigError)
18from ndg.security.server.wsgi.openid.provider.axinterface.sqlalchemy_ax import (
19                                                        SQLAlchemyAXInterface)
20
21
22
23class SQLAlchemyAXInterfaceTestCase(BaseTestCase):
24    DB_FILEPATH = path.join(path.dirname(__file__), BaseTestCase.DB_FILENAME)
25   
26    def __init__(self, *arg, **kw):
27        super(SQLAlchemyAXInterfaceTestCase, self).__init__(*arg, **kw)
28       
29        self.initDb()
30           
31    def test01InvalidQueryUsernameKey(self):
32        interface = SQLAlchemyAXInterface()
33        interface.connectionString = \
34            SQLAlchemyAXInterfaceTestCase.DB_CONNECTION_STR
35           
36        interface.sqlQuery = ("select firstname from users where username = "
37                              "'${invalidUsernameKey}'")
38       
39        axReq = FetchRequest()
40        axResp = FetchResponse()
41       
42        authnCtx = {
43            SQLAlchemyAXInterface.USERNAME_SESSION_KEYNAME: 
44                SQLAlchemyAXInterfaceTestCase.USERNAME
45        }
46       
47        try:
48            interface(axReq, axResp, None, authnCtx)
49           
50        except AXInterfaceConfigError:
51            pass
52        else:
53            self.fail("Expected AXInterfaceConfigError exception")
54       
55    def test02(self):
56        interface = SQLAlchemyAXInterface()
57        interface.connectionString = \
58            SQLAlchemyAXInterfaceTestCase.DB_CONNECTION_STR
59           
60        interface.attributeNames = ('firstName', 'lastName', 'emailAddress')
61       
62        interface.sqlQuery = ("select firstname, lastname, emailAddress from "
63                              "users where username = '${username}'")
64       
65        axReq = FetchRequest()
66       
67        for typeURI in interface.attributeNames:
68            axReq.add(AttrInfo(typeURI, required=True))
69           
70        axResp = FetchResponse()
71       
72        authnCtx = {
73            SQLAlchemyAXInterface.USERNAME_SESSION_KEYNAME: 
74                SQLAlchemyAXInterfaceTestCase.USERNAME
75        }
76       
77        interface(axReq, axResp, None, authnCtx)
78        axData = axResp.getExtensionArgs()
79        self.assert_(len(axData.keys()) > 0)
80        print(axData)
81                             
Note: See TracBrowser for help on using the repository browser.