paula.pasplugins: pas plugins communicate with pau, next login
[paula.git] / paula.pasplugins / src / paula / pasplugins / tests / fake_pau_ap.py
blob1dffb26646336ae26acad4ab93ea57d467059c7c
1 # Copyright (c) 2008 by Florian Friesdorf
3 # GNU Affero General Public License (AGPL)
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as
7 # published by the Free Software Foundation; either version 3 of the
8 # License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
15 # You should have received a copy of the GNU Affero General Public
16 # License along with this program. If not, see
17 # <http://www.gnu.org/licenses/>.
18 """
19 """
20 __author__ = "Florian Friesdorf <flo@chaoflow.net>"
21 __docformat__ = "plaintext"
23 from UserDict import UserDict
25 # this should be moved from zope.app.authentication to zope.authentication
26 from zope.app.authentication.interfaces import IAuthenticatorPlugin
27 from zope.app.authentication.principalfolder import PrincipalInfo
29 from zope.interface import implements, alsoProvides
30 from zope.publisher.interfaces import IRequest
32 FAKE_LOGIN = 'fakelogin'
33 FAKE_PASSWORD = 'fakepassword'
34 FAKE_CREDS = {'login':FAKE_LOGIN, 'password':FAKE_PASSWORD}
35 FAKE_REQUEST = UserDict(FAKE_CREDS)
36 alsoProvides(FAKE_REQUEST, IRequest)
38 AUTHPLUG_NAME = "Paula: Fake PAU AuthenticatorPlugin - Do not use!"
41 class AuthenticatorPlugin(object):
42 """Authenticate a fixed fake user
44 >>> ap = AuthenticatorPlugin()
46 >>> p = ap.authenticateCredentials(None)
47 >>> p is None
48 True
50 >>> credentials = {
51 ... 'login': FAKE_LOGIN,
52 ... }
53 >>> p = ap.authenticateCredentials(credentials)
54 >>> p is None
55 True
57 >>> credentials = {
58 ... 'password': FAKE_PASSWORD,
59 ... }
60 >>> p = ap.authenticateCredentials(credentials)
61 >>> p is None
62 True
64 >>> credentials = {
65 ... 'login': FAKE_LOGIN+'wrong',
66 ... 'password': FAKE_PASSWORD,
67 ... }
68 >>> p = ap.authenticateCredentials(credentials)
69 >>> p is None
70 True
72 >>> credentials['login'] = FAKE_LOGIN
73 >>> p = ap.authenticateCredentials(credentials)
74 >>> from zope.app.authentication.interfaces import IPrincipalInfo
75 >>> IPrincipalInfo.providedBy(p)
76 True
77 >>> p.id == FAKE_LOGIN
78 True
80 >>> credentials['password'] = FAKE_PASSWORD+'wrong'
81 >>> p = ap.authenticateCredentials(credentials)
82 >>> p is None
83 True
84 """
85 implements(IAuthenticatorPlugin)
87 def authenticateCredentials(self, creds):
88 try:
89 if not (creds.has_key('login') and creds.has_key('password')):
90 return None
91 except AttributeError:
92 return None
94 if not (creds['login'] == FAKE_LOGIN
95 and creds['password'] == FAKE_PASSWORD):
96 return None
98 id = FAKE_LOGIN
99 login = id
100 title = description = u"I am a fake user"
101 return PrincipalInfo( id, login, title, description)
103 def principalInfo(self, id):
104 if not id == FAKE_LOGIN:
105 return None
107 login = id
108 title = description = u"I am a fake user"
109 return PrincipalInfo( id, login, title, description)