paula.testing: test for finding txt files + minor bugfix
[paula/paual.testing.git] / paula.authutil / src / paula / authutil / README.txt
blobb4f01e03cabaf7232f097195cb754b775368f8e0
1 Currently unused
4 paula.authutil Package Readme
5 =============================
7 This file serves as an integration test of paula.authutil with
8 paula.authentication.
10 Our configure.zcml registered a global RWAuthProviders. Let's check,
11 whether it is there
13     >>> from paula.authutil.interfaces import IRWAuthProviders
14     >>> global_apu = getUtility(IRWAuthProviders)
15     >>> global_apu is not None
16     True
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',
25     ...         )
26     >>> global_ap is not None
27     True
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):
34     ...     pass
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")
66     >>> root['ap1'] = ap1
67     >>> len(global_apu)
68     0
69     >>> len(local_apu)
70     0
71     >>> del root['ap1']
73 Let it provide IAuthProvider...
75     >>> from paula.authentication.interfaces import IAuthProvider
76     >>> alsoProvides(ap1, IAuthProvider)
77     >>> root['ap1'] = ap1
78     >>> len(global_apu)
79     1
80     >>> len(local_apu)
81     0
83 Try to authenticate
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
89     True
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
96     >>> len(global_apu)
97     1
98     >>> len(local_apu)
99     0
100     >>> del root['subsite']['ap2']
102     >>> alsoProvides(ap2, IAuthProvider)
103     >>> root['subsite']['ap2'] = ap2
104     >>> len(global_apu)
105     1
106     >>> len(local_apu)
107     1
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
114     True
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
120     True
121     >>> local_ap.authenticateCredentials(loc_creds)
122     PrincipalInfo('local')
125 Removing them from the hierarchy needs to remove them from the utilities.
127     >>> del root['ap1']
128     >>> len(global_apu)
129     0
130     >>> len(local_apu)
131     1
132     >>> del root['subsite']['ap2']
133     >>> len(global_apu)
134     0
135     >>> len(local_apu)
136     0
138 The same should happen for IAuthProviderAdaptable, if there is an adapter
139 available.
141     >>> from paula.authutil.interfaces import IAuthProviderAdaptable
142     
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)
154     
155     >>> root['ap3'] = ap3 #doctest: +IGNORE_EXCEPTION_DETAIL
156     Traceback (most recent call last):
157         foo
158     TypeError: foo
159     >>> del root['ap3']
161     >>> provideAdapter(MockAdapter)
162     >>> root['ap3'] = ap3
163     >>> len(global_apu)
164     1
165     >>> len(local_apu)
166     0
167     >>> del root['ap3']
168     >>> len(global_apu)
169     0
170     >>> len(local_apu)
171     0
174 XXX: test persistency?