paula.pasplugins: implementation of many interface - unclean working code
[paula.git] / paula.pasplugins / src / paula / pasplugins / tests / fake_pau_ap.py
blob4ec31c00e904765ee0f1cfd8f23cdbf2cc79599e
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 Globals import Acquisition
24 from UserDict import UserDict
26 # this should be moved from zope.app.authentication to zope.authentication
27 from zope.app.authentication.interfaces import IAuthenticatorPlugin
28 from zope.app.authentication.principalfolder import PrincipalInfo
30 from zope.interface import implements, alsoProvides
31 from zope.publisher.interfaces import IRequest
33 FAKE_LOGIN = 'fakelogin'
34 FAKE_PASSWORD = 'fakepassword'
35 FAKE_CREDS = {'login':FAKE_LOGIN, 'password':FAKE_PASSWORD}
36 FAKE_REQUEST = UserDict(FAKE_CREDS)
37 alsoProvides(FAKE_REQUEST, IRequest)
39 AUTHPLUG_NAME = "Paula: Fake PAU AuthenticatorPlugin - Do not use!"
42 class AuthenticatorPlugin(Acquisition.Explicit):
43 """Authenticate a fixed fake user
45 >>> ap = AuthenticatorPlugin()
47 >>> p = ap.authenticateCredentials(None)
48 >>> p is None
49 True
51 >>> credentials = {
52 ... 'login': FAKE_LOGIN,
53 ... }
54 >>> p = ap.authenticateCredentials(credentials)
55 >>> p is None
56 True
58 >>> credentials = {
59 ... 'password': FAKE_PASSWORD,
60 ... }
61 >>> p = ap.authenticateCredentials(credentials)
62 >>> p is None
63 True
65 >>> credentials = {
66 ... 'login': FAKE_LOGIN+'wrong',
67 ... 'password': FAKE_PASSWORD,
68 ... }
69 >>> p = ap.authenticateCredentials(credentials)
70 >>> p is None
71 True
73 >>> credentials['login'] = FAKE_LOGIN
74 >>> p = ap.authenticateCredentials(credentials)
75 >>> from zope.app.authentication.interfaces import IPrincipalInfo
76 >>> IPrincipalInfo.providedBy(p)
77 True
78 >>> p.id == FAKE_LOGIN
79 True
81 >>> credentials['password'] = FAKE_PASSWORD+'wrong'
82 >>> p = ap.authenticateCredentials(credentials)
83 >>> p is None
84 True
85 """
86 implements(IAuthenticatorPlugin)
88 def authenticateCredentials(self, creds):
89 try:
90 if not (creds.has_key('login') and creds.has_key('password')):
91 return None
92 except AttributeError:
93 return None
95 if not (creds['login'] == FAKE_LOGIN
96 and creds['password'] == FAKE_PASSWORD):
97 return None
99 id = FAKE_LOGIN
100 login = id
101 title = description = u"I am a fake user"
102 return PrincipalInfo( id, login, title, description)
104 def principalInfo(self, id):
105 if not id == FAKE_LOGIN:
106 return None
108 login = id
109 title = description = u"I am a fake user"
110 return PrincipalInfo( id, login, title, description)
113 #XXX: not part of any interface at the moment
114 def addUser(self, login, password):
115 return login == FAKE_LOGIN
117 def delPrincipal(self, id):
118 return id == FAKE_LOGIN
120 def allowDeletePrincipal(self, id):
121 return id == FAKE_LOGIN
123 def allowPasswordSet(self, id):
124 return id == FAKE_LOGIN
126 def doChangeUser(self, login, password, **kws):
127 return login == FAKE_LOGIN
129 def setPropertiesForUser(self, login, **props):
130 return login == FAKE_LOGIN