1 | """OpenID Provider Authentication Interface unit tests |
---|
2 | |
---|
3 | NERC DataGrid Project |
---|
4 | """ |
---|
5 | __author__ = "P J Kershaw" |
---|
6 | __date__ = "12/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$' |
---|
11 | from os import path |
---|
12 | import unittest |
---|
13 | |
---|
14 | from ndg.security.test.unit import BaseTestCase |
---|
15 | from ndg.security.server.wsgi.openid.provider.authninterface import ( |
---|
16 | AuthNInterfaceConfigError) |
---|
17 | from ndg.security.server.wsgi.openid.provider.authninterface.sqlalchemy_authn \ |
---|
18 | import SQLAlchemyAuthnInterface |
---|
19 | |
---|
20 | |
---|
21 | class SQLAlchemyAuthnInterfaceTestCase(BaseTestCase): |
---|
22 | LOGON_SQLQUERY = ("select count(*) from users where username = " |
---|
23 | "'${username}' and md5password = '${password}'") |
---|
24 | |
---|
25 | USERNAME2USERIDENTIFIER_SQLQUERY = ("select openid_identifier from users " |
---|
26 | "where username = '${username}'") |
---|
27 | |
---|
28 | def __init__(self, *arg, **kw): |
---|
29 | super(SQLAlchemyAuthnInterfaceTestCase, self).__init__(*arg, **kw) |
---|
30 | self.__interface = None |
---|
31 | |
---|
32 | self.initDb() |
---|
33 | |
---|
34 | def setUp(self): |
---|
35 | self.__interface = SQLAlchemyAuthnInterface( |
---|
36 | connectionString=SQLAlchemyAuthnInterfaceTestCase.DB_CONNECTION_STR, |
---|
37 | logonSqlQuery=SQLAlchemyAuthnInterfaceTestCase.LOGON_SQLQUERY, |
---|
38 | username2UserIdentifierSqlQuery=\ |
---|
39 | SQLAlchemyAuthnInterfaceTestCase.USERNAME2USERIDENTIFIER_SQLQUERY, |
---|
40 | isMD5EncodedPwd=True |
---|
41 | ) |
---|
42 | |
---|
43 | def test01Logon(self): |
---|
44 | self.__interface.logon({}, |
---|
45 | None, |
---|
46 | SQLAlchemyAuthnInterfaceTestCase.USERNAME, |
---|
47 | SQLAlchemyAuthnInterfaceTestCase.PASSWORD) |
---|
48 | |
---|
49 | def test02Username2UserIdentifier(self): |
---|
50 | self.__interface.username2UserIdentifiers({}, |
---|
51 | SQLAlchemyAuthnInterfaceTestCase.USERNAME) |
---|
52 | |
---|
53 | |
---|
54 | if __name__ == "__main__": |
---|
55 | unittest.main() |
---|