4 paula.authutil Package Readme
5 =============================
7 This file serves as an integration test of paula.authutil with
10 Our configure.zcml registered a global RWAuthProviders. Let's check,
13 >>> from paula.authutil.interfaces import IRWAuthProviders
14 >>> global_apu = getUtility(IRWAuthProviders)
15 >>> global_apu is not None
18 Further, we included paula.authentication, so there should be a global
19 AuthenticatorPlugin available
21 >>> from paula.authentication.interfaces import IAuthenticatorPlugin
22 >>> global_ap = getUtility(
23 ... IAuthenticatorPlugin,
24 ... 'Paula Authenticator Plugin',
26 >>> global_ap is not None
29 Let's create a subsite
31 >>> from zope.app.component import site
32 >>> from zope.app.folder import Folder
33 >>> class SubSiteFolder(Folder, site.SiteManagerContainer):
35 >>> subsite = SubSiteFolder()
36 >>> subsm = site.LocalSiteManager(subsite)
37 >>> subsite.setSiteManager(subsm)
39 >>> root = getRootFolder()
40 >>> root['subsite'] = subsite
42 and add authenticator plugin and auth provider utility
44 >>> from paula.authentication import LocalAuthenticatorPlugin
45 >>> local_ap = LocalAuthenticatorPlugin()
46 >>> root['subsite']['local_ap'] = local_ap
48 >>> from paula.authutil import LocalRWAuthProviders
49 >>> local_apu = LocalRWAuthProviders()
50 >>> root['subsite']['local_apu'] = local_apu
51 >>> subsm.registerUtility(local_apu, IRWAuthProviders)
54 auth provider content added directly to the root folder, should only end up
55 in the global auth provider utility and not the subsite one, and content
56 added to the subsite should only end up there and not in the global.
58 The subscribers should be fine with objects that directly implement
59 IAuthProvider, further down, we will check, whether they also work with
60 IAuthProviderAdaptable.
62 an incomplete mockup auth provider is added nowhere
64 >>> ap1 = Mock(id="global", validate = lambda login=None,password=None: \
65 ... passord is "correct")
73 Let it provide IAuthProvider...
75 >>> from paula.authentication.interfaces import IAuthProvider
76 >>> alsoProvides(ap1, IAuthProvider)
85 >>> g_creds = dict(login = "global", password = "correct")
86 >>> global_ap.authenticateCredentials(g_creds)
87 PrincipalInfo('global')
88 >>> local_ap.authenticateCredentials(g_creds) is None
91 Let's add another one within the subsite
93 >>> ap2 = Mock(id="global", validate = lambda login=None,password=None: \
94 ... passord is "correct")
95 >>> root['subsite']['ap2'] = ap2
100 >>> del root['subsite']['ap2']
102 >>> alsoProvides(ap2, IAuthProvider)
103 >>> root['subsite']['ap2'] = ap2
109 The global is still only in the global
111 >>> global_ap.authenticateCredentials(g_creds)
112 PrincipalInfo('global')
113 >>> local_ap.authenticateCredentials(g_creds) is None
116 and the local is only in the local
118 >>> loc_creds = dict(login = "local", password = "correct")
119 >>> global_ap.authenticateCredentials(loc_creds) is None
121 >>> local_ap.authenticateCredentials(loc_creds)
122 PrincipalInfo('local')
125 Removing them from the hierarchy needs to remove them from the utilities.
132 >>> del root['subsite']['ap2']
138 The same should happen for IAuthProviderAdaptable, if there is an adapter
141 >>> from paula.authutil.interfaces import IAuthProviderAdaptable
143 >>> class MockAdapter(object):
144 ... adapts(IAuthProviderAdaptable)
145 ... implements(IAuthProvider)
146 ... def __init__(self, context):
147 ... self.context = context
148 ... def __getattr__(self, attr):
149 ... getattr(self.context, attr)
151 >>> ap3 = Mock(id="global", validate = lambda login=None,password=None: \
152 ... passord is "correct")
153 >>> alsoProvides(ap3, IAuthProviderAdaptable)
155 >>> root['ap3'] = ap3 #doctest: +IGNORE_EXCEPTION_DETAIL
156 Traceback (most recent call last):
161 >>> provideAdapter(MockAdapter)
162 >>> root['ap3'] = ap3
174 XXX: test persistency?