[Checkins] SVN: zope.pluggableauth/trunk/ Cleaned up. Configure.zcml has gone away.
Souheil CHELFOUH
souheil at chelfouh.com
Sat Jan 23 18:32:38 EST 2010
Log message for revision 108413:
Cleaned up. Configure.zcml has gone away.
Tests pass (except README.txt).
No plugin is registered by default. The zcml are available.
They might just stay in zope.app.authentication.
Changed:
U zope.pluggableauth/trunk/buildout.cfg
U zope.pluggableauth/trunk/setup.py
U zope.pluggableauth/trunk/src/zope/pluggableauth/__init__.py
U zope.pluggableauth/trunk/src/zope/pluggableauth/authentication.py
U zope.pluggableauth/trunk/src/zope/pluggableauth/configure.zcml
U zope.pluggableauth/trunk/src/zope/pluggableauth/ftesting.zcml
D zope.pluggableauth/trunk/src/zope/pluggableauth/idpicker.py
U zope.pluggableauth/trunk/src/zope/pluggableauth/interfaces.py
A zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/__init__.py
U zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/ftpplugins.py
U zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/ftpplugins.zcml
U zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/generic.py
A zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/generic.zcml
U zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/httpplugins.py
U zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/httpplugins.zcml
A zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/session.py
A zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/session.zcml
D zope.pluggableauth/trunk/src/zope/pluggableauth/session.py
D zope.pluggableauth/trunk/src/zope/pluggableauth/session.zcml
U zope.pluggableauth/trunk/src/zope/pluggableauth/testing.py
U zope.pluggableauth/trunk/src/zope/pluggableauth/tests.py
-=-
Modified: zope.pluggableauth/trunk/buildout.cfg
===================================================================
--- zope.pluggableauth/trunk/buildout.cfg 2010-01-23 21:28:55 UTC (rev 108412)
+++ zope.pluggableauth/trunk/buildout.cfg 2010-01-23 23:32:38 UTC (rev 108413)
@@ -4,4 +4,4 @@
[test]
recipe = zc.recipe.testrunner
-eggs = zope.app.authentication [test]
+eggs = zope.pluggableauth [test]
Modified: zope.pluggableauth/trunk/setup.py
===================================================================
--- zope.pluggableauth/trunk/setup.py 2010-01-23 21:28:55 UTC (rev 108412)
+++ zope.pluggableauth/trunk/setup.py 2010-01-23 23:32:38 UTC (rev 108413)
@@ -22,12 +22,8 @@
'Detailed Documentation\n' +
'----------------------\n'
+ '\n' +
- read('src', 'zope', 'authentication', 'README.txt')
+ read('src', 'zope', 'pluggableauth', 'README.txt')
+ '\n\n' +
- read('src', 'zope', 'authentication', 'principalfolder.txt')
- + '\n\n' +
- read('src', 'zope', 'authentication', 'vocabulary.txt')
- + '\n\n' +
read('CHANGES.txt')
),
url='http://pypi.python.org/pypi/zope.pluggableauth',
@@ -47,19 +43,13 @@
package_dir = {'': 'src'},
extras_require=dict(test=['zope.app.testing',
'zope.app.securitypolicy',
- 'zope.app.zcmlfiles',
'zope.securitypolicy',
- 'zope.testbrowser',
'zope.login',]),
namespace_packages=['zope'],
install_requires=['setuptools',
'zope.component',
'zope.container',
- 'zope.formlib',
'zope.authentication',
- 'zope.dublincore',
- 'zope.event',
- 'zope.exceptions',
'zope.i18n',
'zope.i18nmessageid',
'zope.interface',
Modified: zope.pluggableauth/trunk/src/zope/pluggableauth/__init__.py
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/__init__.py 2010-01-23 21:28:55 UTC (rev 108412)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/__init__.py 2010-01-23 23:32:38 UTC (rev 108413)
@@ -16,5 +16,5 @@
$Id$
"""
-import interfaces
-from zope.app.authentication.authentication import PluggableAuthentication
+from zope.pluggableauth import interfaces
+from zope.pluggableauth.authentication import PluggableAuthentication
Modified: zope.pluggableauth/trunk/src/zope/pluggableauth/authentication.py
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/authentication.py 2010-01-23 21:28:55 UTC (rev 108412)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/authentication.py 2010-01-23 23:32:38 UTC (rev 108413)
@@ -15,21 +15,24 @@
$Id$
"""
-import zope.interface
+from zope.interface import implements
from zope import component
from zope.schema.interfaces import ISourceQueriables
from zope.location.interfaces import ILocation
from zope.site.next import queryNextUtility
+from zope.annotation.interfaces import IAttributeAnnotatable
from zope.authentication.interfaces import IAuthentication, PrincipalLookupError
-import zope.container.btree
+from zope.container.btree import BTreeContainer
-from zope.app.authentication import interfaces
+from zope.pluggableauth import interfaces
-class PluggableAuthentication(zope.container.btree.BTreeContainer):
- zope.interface.implements(
+class PluggableAuthentication(BTreeContainer):
+
+ implements(
IAuthentication,
+ IAttributeAnnotatable,
interfaces.IPluggableAuthentication,
ISourceQueriables)
@@ -138,39 +141,3 @@
next = queryNextUtility(self, IAuthentication)
if next is not None:
next.logout(request)
-
-
-class QuerySchemaSearchAdapter(object):
- """Performs schema-based principal searches on behalf of a PAU.
-
- Delegates the search to the adapted authenticator (which also provides
- IQuerySchemaSearch) and prepends the PAU prefix to the resulting principal
- IDs.
- """
- component.adapts(
- interfaces.IQuerySchemaSearch,
- interfaces.IPluggableAuthentication)
-
- zope.interface.implements(
- interfaces.IQueriableAuthenticator,
- interfaces.IQuerySchemaSearch,
- ILocation)
-
- def __init__(self, authplugin, pau):
- if (ILocation.providedBy(authplugin) and
- authplugin.__parent__ is not None):
- # Checking explicitly for the parent, because providing ILocation
- # basically means that the object *could* be located. It doesn't
- # say the object must be located.
- self.__parent__ = authplugin.__parent__
- self.__name__ = authplugin.__name__
- else:
- self.__parent__ = pau
- self.__name__ = ""
- self.authplugin = authplugin
- self.pau = pau
- self.schema = authplugin.schema
-
- def search(self, query, start=None, batch_size=None):
- for id in self.authplugin.search(query, start, batch_size):
- yield self.pau.prefix + id
Modified: zope.pluggableauth/trunk/src/zope/pluggableauth/configure.zcml
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/configure.zcml 2010-01-23 21:28:55 UTC (rev 108412)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/configure.zcml 2010-01-23 23:32:38 UTC (rev 108413)
@@ -1,33 +1,10 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
- i18n_domain="zope"
- >
+ i18n_domain="zope">
- <class class=".PluggableAuthentication">
- <implements
- interface="zope.annotation.interfaces.IAttributeAnnotatable"
- />
- <require
- permission="zope.ManageSite"
- interface=".interfaces.IPluggableAuthentication"
- set_schema=".interfaces.IPluggableAuthentication"
- />
- </class>
- <adapter
- for=".interfaces.IQuerySchemaSearch
- .interfaces.IPluggableAuthentication"
- provides=".interfaces.IQueriableAuthenticator"
- factory=".authentication.QuerySchemaSearchAdapter"
- />
- <utility
- name="No Challenge if Authenticated"
- factory=".generic.NoChallengeCredentialsPlugin"
- provides=".interfaces.ICredentialsPlugin"
- />
-
<!-- Registering documentation with API doc -->
<configure
xmlns:apidoc="http://namespaces.zope.org/apidoc"
@@ -43,13 +20,8 @@
</configure>
- <include file="password.zcml" />
- <include file="session.zcml" />
- <include file="httpplugins.zcml" />
- <include file="principalfolder.zcml" />
- <include file="groupfolder.zcml" />
- <include file="ftpplugins.zcml" />
+ <include package=".plugins" file="session.zcml" />
+ <include package=".plugins" file="httpplugins.zcml" />
+ <include package=".plugins" file="ftpplugins.zcml" />
- <include package=".browser" />
-
</configure>
Modified: zope.pluggableauth/trunk/src/zope/pluggableauth/ftesting.zcml
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/ftesting.zcml 2010-01-23 21:28:55 UTC (rev 108412)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/ftesting.zcml 2010-01-23 23:32:38 UTC (rev 108413)
@@ -1,18 +1,21 @@
<configure
xmlns="http://namespaces.zope.org/zope"
i18n_domain="zope"
- package="zope.app.authentication"
+ package="zope.pluggableauth"
>
<!-- This file is the equivalent of site.zcml and it is -->
<!-- used for functional testing setup -->
+ <include package="zope.component" file="meta.zcml" />
+ <include package="zope.security" file="meta.zcml" />
<include package="zope.securitypolicy" file="meta.zcml" />
+ <include package="zope.principalregistry" file="meta.zcml" />
- <include package="zope.formlib" />
+ <include package="zope.security" />
+ <include package="zope.principalregistry" />
<include package="zope.session" />
<include package="zope.pluggableauth" />
- <include package="zope.app.securitypolicy" />
<include package="zope.login" />
<securityPolicy
@@ -28,8 +31,6 @@
<grantAll role="zope.Manager" />
- <include package="zope.app.securitypolicy.browser.tests" file="functional.zcml" />
-
<!-- Principals -->
<unauthenticatedPrincipal
Deleted: zope.pluggableauth/trunk/src/zope/pluggableauth/idpicker.py
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/idpicker.py 2010-01-23 21:28:55 UTC (rev 108412)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/idpicker.py 2010-01-23 23:32:38 UTC (rev 108413)
@@ -1,109 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Helper base class that picks principal ids
-
-$Id$
-"""
-__docformat__ = 'restructuredtext'
-
-import re
-from zope.exceptions.interfaces import UserError
-from zope.container.contained import NameChooser
-from zope.app.authentication.i18n import ZopeMessageFactory as _
-
-ok = re.compile('[!-~]+$').match
-class IdPicker(NameChooser):
- """Helper base class that picks principal ids.
-
- Add numbers to ids given by users to make them unique.
-
- The Id picker is a variation on the name chooser that picks numeric
- ids when no name is given.
-
- >>> from zope.app.authentication.idpicker import IdPicker
- >>> IdPicker({}).chooseName('', None)
- u'1'
-
- >>> IdPicker({'1': 1}).chooseName('', None)
- u'2'
-
- >>> IdPicker({'2': 1}).chooseName('', None)
- u'1'
-
- >>> IdPicker({'1': 1}).chooseName('bob', None)
- u'bob'
-
- >>> IdPicker({'bob': 1}).chooseName('bob', None)
- u'bob1'
-
- """
- def chooseName(self, name, object):
- i = 0
- name = unicode(name)
- orig = name
- while (not name) or (name in self.context):
- i += 1
- name = orig+str(i)
-
- self.checkName(name, object)
- return name
-
- def checkName(self, name, object):
- """Limit ids
-
- Ids can only contain printable, non-space, 7-bit ASCII strings:
-
- >>> from zope.app.authentication.idpicker import IdPicker
- >>> IdPicker({}).checkName(u'1', None)
- True
-
- >>> IdPicker({}).checkName(u'bob', None)
- True
-
- >>> IdPicker({}).checkName(u'bob\xfa', None)
- ... # doctest: +NORMALIZE_WHITESPACE
- Traceback (most recent call last):
- ...
- UserError: Ids must contain only printable
- 7-bit non-space ASCII characters
-
- >>> IdPicker({}).checkName(u'big bob', None)
- ... # doctest: +NORMALIZE_WHITESPACE
- Traceback (most recent call last):
- ...
- UserError: Ids must contain only printable
- 7-bit non-space ASCII characters
-
- Ids also can't be over 100 characters long:
-
- >>> IdPicker({}).checkName(u'x' * 100, None)
- True
-
- >>> IdPicker({}).checkName(u'x' * 101, None)
- Traceback (most recent call last):
- ...
- UserError: Ids can't be more than 100 characters long.
-
- """
- NameChooser.checkName(self, name, object)
- if not ok(name):
- raise UserError(
- _("Ids must contain only printable 7-bit non-space"
- " ASCII characters")
- )
- if len(name) > 100:
- raise UserError(
- _("Ids can't be more than 100 characters long.")
- )
- return True
Modified: zope.pluggableauth/trunk/src/zope/pluggableauth/interfaces.py
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/interfaces.py 2010-01-23 21:28:55 UTC (rev 108412)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/interfaces.py 2010-01-23 23:32:38 UTC (rev 108413)
@@ -18,23 +18,22 @@
__docformat__ = "reStructuredText"
import zope.interface
-import zope.schema
-import zope.security.interfaces
-from zope.app.authentication.i18n import ZopeMessageFactory as _
+from zope.i18nmessageid import MessageFactory
from zope.authentication.interfaces import ILogout
+from zope.schema import Choice, List, TextLine
from zope.container.constraints import contains, containers
from zope.container.interfaces import IContainer
-# BBB: the password managers were moved into zope.password package.
-from zope.password.interfaces import IPasswordManager
+_ = MessageFactory('zope')
+
class IPlugin(zope.interface.Interface):
"""A plugin for a pluggable authentication component."""
class IPluggableAuthentication(ILogout, IContainer):
"""Provides authentication services with the help of various plugins.
-
+
IPluggableAuthentication implementations will also implement
zope.authentication.interfaces.IAuthentication. The `authenticate` method
of this interface in an IPluggableAuthentication should annotate the
@@ -50,7 +49,7 @@
description=_("""Used for extracting credentials.
Names may be of ids of non-utility ICredentialsPlugins contained in
the IPluggableAuthentication, or names of registered
- ICredentialsPlugins utilities. Contained non-utility ids mask
+ ICredentialsPlugins utilities. Contained non-utility ids mask
utility names."""),
value_type=zope.schema.Choice(vocabulary='CredentialsPlugins'),
default=[],
@@ -126,6 +125,7 @@
If a logout was performed, return True, otherwise return False.
"""
+
class IAuthenticatorPlugin(IPlugin):
"""Authenticates a principal using credentials.
@@ -160,184 +160,13 @@
credentialsPlugin = zope.interface.Attribute(
"""Plugin used to generate the credentials for this principal info.
-
+
Optional. Should be set in IPluggableAuthentication.authenticate.
""")
authenticatorPlugin = zope.interface.Attribute(
"""Plugin used to authenticate the credentials for this principal info.
-
+
Optional. Should be set in IPluggableAuthentication.authenticate and
IPluggableAuthentication.getPrincipal.
""")
-
-class IPrincipal(zope.security.interfaces.IGroupClosureAwarePrincipal):
-
- groups = zope.schema.List(
- title=_("Groups"),
- description=_(
- """ids of groups to which the principal directly belongs.
-
- Plugins may append to this list. Mutating the list only affects
- the life of the principal object, and does not persist (so
- persistently adding groups to a principal should be done by working
- with a plugin that mutates this list every time the principal is
- created, like the group folder in this package.)
- """),
- value_type=zope.schema.TextLine(),
- required=False)
-
-class IPrincipalFactory(zope.interface.Interface):
- """A principal factory."""
-
- def __call__(authentication):
- """Creates a principal.
-
- The authentication utility that called the factory is passed
- and should be included in the principal-created event.
- """
-
-
-class IFoundPrincipalFactory(IPrincipalFactory):
- """A found principal factory."""
-
-
-class IAuthenticatedPrincipalFactory(IPrincipalFactory):
- """An authenticated principal factory."""
-
-
-class IPrincipalCreated(zope.interface.Interface):
- """A principal has been created."""
-
- principal = zope.interface.Attribute("The principal that was created")
-
- authentication = zope.interface.Attribute(
- "The authentication utility that created the principal")
-
- info = zope.interface.Attribute("An object providing IPrincipalInfo.")
-
-
-class IAuthenticatedPrincipalCreated(IPrincipalCreated):
- """A principal has been created by way of an authentication operation."""
-
- request = zope.interface.Attribute(
- "The request the user was authenticated against")
-
-
-class AuthenticatedPrincipalCreated:
- """
- >>> from zope.interface.verify import verifyObject
- >>> event = AuthenticatedPrincipalCreated("authentication", "principal",
- ... "info", "request")
- >>> verifyObject(IAuthenticatedPrincipalCreated, event)
- True
- """
-
- zope.interface.implements(IAuthenticatedPrincipalCreated)
-
- def __init__(self, authentication, principal, info, request):
- self.authentication = authentication
- self.principal = principal
- self.info = info
- self.request = request
-
-
-class IFoundPrincipalCreated(IPrincipalCreated):
- """A principal has been created by way of a search operation."""
-
-
-class FoundPrincipalCreated:
- """
- >>> from zope.interface.verify import verifyObject
- >>> event = FoundPrincipalCreated("authentication", "principal",
- ... "info")
- >>> verifyObject(IFoundPrincipalCreated, event)
- True
- """
-
- zope.interface.implements(IFoundPrincipalCreated)
-
- def __init__(self, authentication, principal, info):
- self.authentication = authentication
- self.principal = principal
- self.info = info
-
-
-class IQueriableAuthenticator(zope.interface.Interface):
- """Indicates the authenticator provides a search UI for principals."""
-
-
-class IQuerySchemaSearch(zope.interface.Interface):
- """An interface for searching using schema-constrained input."""
-
- schema = zope.interface.Attribute("""
- The schema that constrains the input provided to the search method.
-
- A mapping of name/value pairs for each field in this schema is used
- as the query argument in the search method.
- """)
-
- def search(query, start=None, batch_size=None):
- """Returns an iteration of principal IDs matching the query.
-
- query is a mapping of name/value pairs for fields specified by the
- schema.
-
- If the start argument is provided, then it should be an
- integer and the given number of initial items should be
- skipped.
-
- If the batch_size argument is provided, then it should be an
- integer and no more than the given number of items should be
- returned.
- """
-
-class IGroupAdded(zope.interface.Interface):
- """A group has been added."""
-
- group = zope.interface.Attribute("""The group that was defined""")
-
-
-class GroupAdded:
- """
- >>> from zope.interface.verify import verifyObject
- >>> event = GroupAdded("group")
- >>> verifyObject(IGroupAdded, event)
- True
- """
-
- zope.interface.implements(IGroupAdded)
-
- def __init__(self, group):
- self.group = group
-
- def __repr__(self):
- return "<GroupAdded %r>" % self.group.id
-
-class IPrincipalsAddedToGroup(zope.interface.Interface):
- group_id = zope.interface.Attribute(
- 'the id of the group to which the principal was added')
- principal_ids = zope.interface.Attribute(
- 'an iterable of one or more ids of principals added')
-
-class IPrincipalsRemovedFromGroup(zope.interface.Interface):
- group_id = zope.interface.Attribute(
- 'the id of the group from which the principal was removed')
- principal_ids = zope.interface.Attribute(
- 'an iterable of one or more ids of principals removed')
-
-class AbstractMembersChanged(object):
-
- def __init__(self, principal_ids, group_id):
- self.principal_ids = principal_ids
- self.group_id = group_id
-
- def __repr__(self):
- return "<%s %r %r>" % (
- self.__class__.__name__, sorted(self.principal_ids), self.group_id)
-
-class PrincipalsAddedToGroup(AbstractMembersChanged):
- zope.interface.implements(IPrincipalsAddedToGroup)
-
-class PrincipalsRemovedFromGroup(AbstractMembersChanged):
- zope.interface.implements(IPrincipalsRemovedFromGroup)
Modified: zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/ftpplugins.py
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/ftpplugins.py 2010-01-23 21:28:55 UTC (rev 108412)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/ftpplugins.py 2010-01-23 23:32:38 UTC (rev 108413)
@@ -16,9 +16,9 @@
__docformat__ = 'restructuredtext'
from zope.interface import implements
+from zope.pluggableauth import interfaces
from zope.publisher.interfaces.ftp import IFTPRequest
-from zope.app.authentication import interfaces
class FTPCredentialsPlugin(object):
Modified: zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/ftpplugins.zcml
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/ftpplugins.zcml 2010-01-23 21:28:55 UTC (rev 108412)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/ftpplugins.zcml 2010-01-23 23:32:38 UTC (rev 108413)
@@ -1,12 +1,11 @@
<configure
xmlns="http://namespaces.zope.org/zope"
- i18n_domain="zope"
- >
+ i18n_domain="zope">
<utility
name="FTP Credentials"
- provides=".interfaces.ICredentialsPlugin"
factory=".ftpplugins.FTPCredentialsPlugin"
+ provides="zope.pluggableauth.interfaces.ICredentialsPlugin"
/>
</configure>
Modified: zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/generic.py
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/generic.py 2010-01-23 21:28:55 UTC (rev 108412)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/generic.py 2010-01-23 23:32:38 UTC (rev 108413)
@@ -16,12 +16,12 @@
$Id$
"""
__docformat__ = "reStructuredText"
+
+from zope.authentication.interfaces import IUnauthenticatedPrincipal
from zope.interface import implements
-from zope.authentication.interfaces import IUnauthenticatedPrincipal
+from zope.pluggableauth import interfaces
-from zope.app.authentication import interfaces
-
class NoChallengeCredentialsPlugin(object):
"""A plugin that doesn't challenge if the principal is authenticated.
Added: zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/generic.zcml
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/generic.zcml (rev 0)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/generic.zcml 2010-01-23 23:32:38 UTC (rev 108413)
@@ -0,0 +1,11 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ i18n_domain="zope">
+
+ <utility
+ name="No Challenge if Authenticated"
+ factory=".generic.NoChallengeCredentialsPlugin"
+ provides="zope.pluggableauth.interfaces.ICredentialsPlugin"
+ />
+
+</configure>
\ No newline at end of file
Modified: zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/httpplugins.py
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/httpplugins.py 2010-01-23 21:28:55 UTC (rev 108412)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/httpplugins.py 2010-01-23 23:32:38 UTC (rev 108413)
@@ -16,16 +16,14 @@
$Id$
"""
__docformat__ = "reStructuredText"
+
import base64
-from persistent import Persistent
from zope.interface import implements, Interface
from zope.publisher.interfaces.http import IHTTPRequest
from zope.schema import TextLine
+from zope.pluggableauth import interfaces
-from zope.container.contained import Contained
-from zope.app.authentication import interfaces
-
class IHTTPBasicAuthRealm(Interface):
"""HTTP Basic Auth Realm
@@ -38,7 +36,7 @@
default=u'Zope')
-class HTTPBasicAuthCredentialsPlugin(Persistent, Contained):
+class HTTPBasicAuthCredentialsPlugin(object):
implements(interfaces.ICredentialsPlugin, IHTTPBasicAuthRealm)
Modified: zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/httpplugins.zcml
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/httpplugins.zcml 2010-01-23 21:28:55 UTC (rev 108412)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/httpplugins.zcml 2010-01-23 23:32:38 UTC (rev 108413)
@@ -1,25 +1,11 @@
<configure
xmlns="http://namespaces.zope.org/zope"
- i18n_domain="zope"
- >
+ i18n_domain="zope">
<utility
name="Zope Realm Basic-Auth"
- provides=".interfaces.ICredentialsPlugin"
factory=".httpplugins.HTTPBasicAuthCredentialsPlugin"
+ provides="zope.pluggableauth.interfaces.ICredentialsPlugin"
/>
- <class class=".httpplugins.HTTPBasicAuthCredentialsPlugin">
- <implements
- interface="zope.annotation.interfaces.IAttributeAnnotatable"
- />
- <require
- permission="zope.ManageServices"
- interface=".httpplugins.IHTTPBasicAuthRealm"
- set_schema=".httpplugins.IHTTPBasicAuthRealm"
- />
- </class>
-
- <include package=".browser" file="httpplugins.zcml" />
-
</configure>
Copied: zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/session.py (from rev 108412, zope.pluggableauth/trunk/src/zope/pluggableauth/session.py)
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/session.py (rev 0)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/session.py 2010-01-23 23:32:38 UTC (rev 108413)
@@ -0,0 +1,300 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+""" Implementations of the session-based and cookie-based extractor and
+ challenge plugins.
+
+$Id$
+"""
+__docformat__ = 'restructuredtext'
+
+import transaction
+from urllib import urlencode
+
+from zope.interface import implements, Interface
+from zope.schema import TextLine
+from zope.publisher.interfaces.http import IHTTPRequest
+from zope.session.interfaces import ISession
+from zope.traversing.browser.absoluteurl import absoluteURL
+
+from zope.site import hooks
+from zope.pluggableauth.interfaces import ICredentialsPlugin
+
+
+class ISessionCredentials(Interface):
+ """Interface for storing and accessing credentials in a session.
+
+ We use a real class with interface here to prevent unauthorized
+ access to the credentials.
+ """
+
+ def __init__(login, password):
+ pass
+
+ def getLogin():
+ """Return login name."""
+
+ def getPassword():
+ """Return password."""
+
+
+class SessionCredentials(object):
+ """Credentials class for use with sessions.
+
+ A session credential is created with a login and a password:
+
+ >>> cred = SessionCredentials('scott', 'tiger')
+
+ Logins are read using getLogin:
+ >>> cred.getLogin()
+ 'scott'
+
+ and passwords with getPassword:
+
+ >>> cred.getPassword()
+ 'tiger'
+
+ """
+ implements(ISessionCredentials)
+
+ def __init__(self, login, password):
+ self.login = login
+ self.password = password
+
+ def getLogin(self): return self.login
+
+ def getPassword(self): return self.password
+
+ def __str__(self): return self.getLogin() + ':' + self.getPassword()
+
+
+class IBrowserFormChallenger(Interface):
+ """A challenger that uses a browser form to collect user credentials."""
+
+ loginpagename = TextLine(
+ title=u'Loginpagename',
+ description=u"""Name of the login form used by challenger.
+
+ The form must provide 'login' and 'password' input fields.
+ """,
+ default=u'loginForm.html')
+
+ loginfield = TextLine(
+ title=u'Loginfield',
+ description=u"Field of the login page in which is looked for the login user name.",
+ default=u"login")
+
+ passwordfield = TextLine(
+ title=u'Passwordfield',
+ description=u"Field of the login page in which is looked for the password.",
+ default=u"password")
+
+
+class SessionCredentialsPlugin(object):
+ """A credentials plugin that uses Zope sessions to get/store credentials.
+
+ To illustrate how a session plugin works, we'll first setup some session
+ machinery:
+
+ >>> from zope.session.session import RAMSessionDataContainer
+ >>> from zope.pluggableauth.tests import sessionSetUp
+ >>> sessionSetUp(RAMSessionDataContainer)
+
+ This lets us retrieve the same session info from any test request, which
+ simulates what happens when a user submits a session ID as a cookie.
+
+ We also need a session plugin:
+
+ >>> plugin = SessionCredentialsPlugin()
+
+ A session plugin uses an ISession component to store the last set of
+ credentials it gets from a request. Credentials can be retrieved from
+ subsequent requests using the session-stored credentials.
+
+ Our test environment is initially configured without credentials:
+
+ >>> from zope.pluggableauth.tests import sessionSetUp
+ >>> from zope.publisher.browser import TestRequest
+ >>> request = TestRequest()
+ >>> print plugin.extractCredentials(request)
+ None
+
+ We must explicitly provide credentials once so the plugin can store
+ them in a session:
+
+ >>> request = TestRequest(login='scott', password='tiger')
+ >>> plugin.extractCredentials(request)
+ {'login': 'scott', 'password': 'tiger'}
+
+ Subsequent requests now have access to the credentials even if they're
+ not explicitly in the request:
+
+ >>> plugin.extractCredentials(TestRequest())
+ {'login': 'scott', 'password': 'tiger'}
+
+ We can always provide new credentials explicitly in the request:
+
+ >>> plugin.extractCredentials(TestRequest(
+ ... login='harry', password='hirsch'))
+ {'login': 'harry', 'password': 'hirsch'}
+
+ and these will be used on subsequent requests:
+
+ >>> plugin.extractCredentials(TestRequest())
+ {'login': 'harry', 'password': 'hirsch'}
+
+ We can also change the fields from which the credentials are extracted:
+
+ >>> plugin.loginfield = "my_new_login_field"
+ >>> plugin.passwordfield = "my_new_password_field"
+
+ Now we build a request that uses the new fields:
+
+ >>> request = TestRequest(my_new_login_field='luke', my_new_password_field='the_force')
+
+ The plugin now extracts the credentials information from these new fields:
+
+ >>> plugin.extractCredentials(request)
+ {'login': 'luke', 'password': 'the_force'}
+
+ Finally, we clear the session credentials using the logout method:
+
+ >>> plugin.logout(TestRequest())
+ True
+ >>> print plugin.extractCredentials(TestRequest())
+ None
+
+ """
+ implements(ICredentialsPlugin, IBrowserFormChallenger)
+
+ loginpagename = 'loginForm.html'
+ loginfield = 'login'
+ passwordfield = 'password'
+
+ def extractCredentials(self, request):
+ """Extracts credentials from a session if they exist."""
+ if not IHTTPRequest.providedBy(request):
+ return None
+ session = ISession(request)
+ sessionData = session.get(
+ 'zope.pluggableauth.browserplugins')
+ login = request.get(self.loginfield, None)
+ password = request.get(self.passwordfield, None)
+ credentials = None
+
+ if login and password:
+ credentials = SessionCredentials(login, password)
+ elif not sessionData:
+ return None
+ sessionData = session[
+ 'zope.pluggableauth.browserplugins']
+ if credentials:
+ sessionData['credentials'] = credentials
+ else:
+ credentials = sessionData.get('credentials', None)
+ if not credentials:
+ return None
+ return {'login': credentials.getLogin(),
+ 'password': credentials.getPassword()}
+
+ def challenge(self, request):
+ """Challenges by redirecting to a login form.
+
+ To illustrate, we'll create a test request:
+
+ >>> from zope.publisher.browser import TestRequest
+ >>> request = TestRequest()
+
+ and confirm its response's initial status and 'location' header:
+
+ >>> request.response.getStatus()
+ 599
+ >>> request.response.getHeader('location')
+
+ When we issue a challenge using a session plugin:
+
+ >>> plugin = SessionCredentialsPlugin()
+ >>> plugin.challenge(request)
+ True
+
+ we get a redirect:
+
+ >>> request.response.getStatus()
+ 302
+ >>> request.response.getHeader('location')
+ 'http://127.0.0.1/@@loginForm.html?camefrom=%2F'
+
+ The plugin redirects to the page defined by the loginpagename
+ attribute:
+
+ >>> plugin.loginpagename = 'mylogin.html'
+ >>> plugin.challenge(request)
+ True
+ >>> request.response.getHeader('location')
+ 'http://127.0.0.1/@@mylogin.html?camefrom=%2F'
+
+ It also provides the request URL as a 'camefrom' GET style parameter.
+ To illustrate, we'll pretend we've traversed a couple names:
+
+ >>> env = {
+ ... 'REQUEST_URI': '/foo/bar/folder/page%201.html?q=value',
+ ... 'QUERY_STRING': 'q=value'
+ ... }
+ >>> request = TestRequest(environ=env)
+ >>> request._traversed_names = [u'foo', u'bar']
+ >>> request._traversal_stack = [u'page 1.html', u'folder']
+ >>> request['REQUEST_URI']
+ '/foo/bar/folder/page%201.html?q=value'
+
+ When we challenge:
+
+ >>> plugin.challenge(request)
+ True
+
+ We see the 'camefrom' points to the requested URL:
+
+ >>> request.response.getHeader('location') # doctest: +ELLIPSIS
+ '.../@@mylogin.html?camefrom=%2Ffoo%2Fbar%2Ffolder%2Fpage+1.html%3Fq%3Dvalue'
+
+ This can be used by the login form to redirect the user back to the
+ originating URL upon successful authentication.
+ """
+ if not IHTTPRequest.providedBy(request):
+ return False
+
+ site = hooks.getSite()
+ # We need the traversal stack to complete the 'camefrom' parameter
+ stack = request.getTraversalStack()
+ stack.reverse()
+ # Better to add the query string, if present
+ query = request.get('QUERY_STRING')
+
+ camefrom = '/'.join([request.getURL(path_only=True)] + stack)
+ if query:
+ camefrom = camefrom + '?' + query
+ url = '%s/@@%s?%s' % (absoluteURL(site, request),
+ self.loginpagename,
+ urlencode({'camefrom': camefrom}))
+ request.response.redirect(url)
+ return True
+
+ def logout(self, request):
+ """Performs logout by clearing session data credentials."""
+ if not IHTTPRequest.providedBy(request):
+ return False
+
+ sessionData = ISession(request)[
+ 'zope.pluggableauth.browserplugins']
+ sessionData['credentials'] = None
+ transaction.commit()
+ return True
Copied: zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/session.zcml (from rev 108412, zope.pluggableauth/trunk/src/zope/pluggableauth/session.zcml)
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/session.zcml (rev 0)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/plugins/session.zcml 2010-01-23 23:32:38 UTC (rev 108413)
@@ -0,0 +1,11 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ i18n_domain="zope">
+
+ <utility
+ name="Session Credentials"
+ factory=".session.SessionCredentialsPlugin"
+ provides="zope.pluggableauth.interfaces.ICredentialsPlugin"
+ />
+
+</configure>
Deleted: zope.pluggableauth/trunk/src/zope/pluggableauth/session.py
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/session.py 2010-01-23 21:28:55 UTC (rev 108412)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/session.py 2010-01-23 23:32:38 UTC (rev 108413)
@@ -1,301 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-""" Implementations of the session-based and cookie-based extractor and
- challenge plugins.
-
-$Id$
-"""
-__docformat__ = 'restructuredtext'
-
-import transaction
-from persistent import Persistent
-from urllib import urlencode
-
-from zope.interface import implements, Interface
-from zope.schema import TextLine
-from zope.publisher.interfaces.http import IHTTPRequest
-from zope.session.interfaces import ISession
-from zope.traversing.browser.absoluteurl import absoluteURL
-
-from zope.site import hooks
-from zope.container.contained import Contained
-from zope.app.authentication.interfaces import ICredentialsPlugin
-
-class ISessionCredentials(Interface):
- """ Interface for storing and accessing credentials in a session.
-
- We use a real class with interface here to prevent unauthorized
- access to the credentials.
- """
-
- def __init__(login, password):
- pass
-
- def getLogin():
- """Return login name."""
-
- def getPassword():
- """Return password."""
-
-
-class SessionCredentials(object):
- """Credentials class for use with sessions.
-
- A session credential is created with a login and a password:
-
- >>> cred = SessionCredentials('scott', 'tiger')
-
- Logins are read using getLogin:
- >>> cred.getLogin()
- 'scott'
-
- and passwords with getPassword:
-
- >>> cred.getPassword()
- 'tiger'
-
- """
- implements(ISessionCredentials)
-
- def __init__(self, login, password):
- self.login = login
- self.password = password
-
- def getLogin(self): return self.login
-
- def getPassword(self): return self.password
-
- def __str__(self): return self.getLogin() + ':' + self.getPassword()
-
-
-class IBrowserFormChallenger(Interface):
- """A challenger that uses a browser form to collect user credentials."""
-
- loginpagename = TextLine(
- title=u'Loginpagename',
- description=u"""Name of the login form used by challenger.
-
- The form must provide 'login' and 'password' input fields.
- """,
- default=u'loginForm.html')
-
- loginfield = TextLine(
- title=u'Loginfield',
- description=u"Field of the login page in which is looked for the login user name.",
- default=u"login")
-
- passwordfield = TextLine(
- title=u'Passwordfield',
- description=u"Field of the login page in which is looked for the password.",
- default=u"password")
-
-
-class SessionCredentialsPlugin(Persistent, Contained):
- """A credentials plugin that uses Zope sessions to get/store credentials.
-
- To illustrate how a session plugin works, we'll first setup some session
- machinery:
-
- >>> from zope.session.session import RAMSessionDataContainer
- >>> from tests import sessionSetUp
- >>> sessionSetUp(RAMSessionDataContainer)
-
- This lets us retrieve the same session info from any test request, which
- simulates what happens when a user submits a session ID as a cookie.
-
- We also need a session plugin:
-
- >>> plugin = SessionCredentialsPlugin()
-
- A session plugin uses an ISession component to store the last set of
- credentials it gets from a request. Credentials can be retrieved from
- subsequent requests using the session-stored credentials.
-
- Our test environment is initially configured without credentials:
-
- >>> from tests import sessionSetUp
- >>> from zope.publisher.browser import TestRequest
- >>> request = TestRequest()
- >>> print plugin.extractCredentials(request)
- None
-
- We must explicitly provide credentials once so the plugin can store
- them in a session:
-
- >>> request = TestRequest(login='scott', password='tiger')
- >>> plugin.extractCredentials(request)
- {'login': 'scott', 'password': 'tiger'}
-
- Subsequent requests now have access to the credentials even if they're
- not explicitly in the request:
-
- >>> plugin.extractCredentials(TestRequest())
- {'login': 'scott', 'password': 'tiger'}
-
- We can always provide new credentials explicitly in the request:
-
- >>> plugin.extractCredentials(TestRequest(
- ... login='harry', password='hirsch'))
- {'login': 'harry', 'password': 'hirsch'}
-
- and these will be used on subsequent requests:
-
- >>> plugin.extractCredentials(TestRequest())
- {'login': 'harry', 'password': 'hirsch'}
-
- We can also change the fields from which the credentials are extracted:
-
- >>> plugin.loginfield = "my_new_login_field"
- >>> plugin.passwordfield = "my_new_password_field"
-
- Now we build a request that uses the new fields:
-
- >>> request = TestRequest(my_new_login_field='luke', my_new_password_field='the_force')
-
- The plugin now extracts the credentials information from these new fields:
-
- >>> plugin.extractCredentials(request)
- {'login': 'luke', 'password': 'the_force'}
-
- Finally, we clear the session credentials using the logout method:
-
- >>> plugin.logout(TestRequest())
- True
- >>> print plugin.extractCredentials(TestRequest())
- None
-
- """
- implements(ICredentialsPlugin, IBrowserFormChallenger)
-
- loginpagename = 'loginForm.html'
- loginfield = 'login'
- passwordfield = 'password'
-
- def extractCredentials(self, request):
- """Extracts credentials from a session if they exist."""
- if not IHTTPRequest.providedBy(request):
- return None
- session = ISession(request)
- sessionData = session.get(
- 'zope.app.authentication.browserplugins')
- login = request.get(self.loginfield, None)
- password = request.get(self.passwordfield, None)
- credentials = None
-
- if login and password:
- credentials = SessionCredentials(login, password)
- elif not sessionData:
- return None
- sessionData = session[
- 'zope.app.authentication.browserplugins']
- if credentials:
- sessionData['credentials'] = credentials
- else:
- credentials = sessionData.get('credentials', None)
- if not credentials:
- return None
- return {'login': credentials.getLogin(),
- 'password': credentials.getPassword()}
-
- def challenge(self, request):
- """Challenges by redirecting to a login form.
-
- To illustrate, we'll create a test request:
-
- >>> from zope.publisher.browser import TestRequest
- >>> request = TestRequest()
-
- and confirm its response's initial status and 'location' header:
-
- >>> request.response.getStatus()
- 599
- >>> request.response.getHeader('location')
-
- When we issue a challenge using a session plugin:
-
- >>> plugin = SessionCredentialsPlugin()
- >>> plugin.challenge(request)
- True
-
- we get a redirect:
-
- >>> request.response.getStatus()
- 302
- >>> request.response.getHeader('location')
- 'http://127.0.0.1/@@loginForm.html?camefrom=%2F'
-
- The plugin redirects to the page defined by the loginpagename
- attribute:
-
- >>> plugin.loginpagename = 'mylogin.html'
- >>> plugin.challenge(request)
- True
- >>> request.response.getHeader('location')
- 'http://127.0.0.1/@@mylogin.html?camefrom=%2F'
-
- It also provides the request URL as a 'camefrom' GET style parameter.
- To illustrate, we'll pretend we've traversed a couple names:
-
- >>> env = {
- ... 'REQUEST_URI': '/foo/bar/folder/page%201.html?q=value',
- ... 'QUERY_STRING': 'q=value'
- ... }
- >>> request = TestRequest(environ=env)
- >>> request._traversed_names = [u'foo', u'bar']
- >>> request._traversal_stack = [u'page 1.html', u'folder']
- >>> request['REQUEST_URI']
- '/foo/bar/folder/page%201.html?q=value'
-
- When we challenge:
-
- >>> plugin.challenge(request)
- True
-
- We see the 'camefrom' points to the requested URL:
-
- >>> request.response.getHeader('location') # doctest: +ELLIPSIS
- '.../@@mylogin.html?camefrom=%2Ffoo%2Fbar%2Ffolder%2Fpage+1.html%3Fq%3Dvalue'
-
- This can be used by the login form to redirect the user back to the
- originating URL upon successful authentication.
- """
- if not IHTTPRequest.providedBy(request):
- return False
-
- site = hooks.getSite()
- # We need the traversal stack to complete the 'camefrom' parameter
- stack = request.getTraversalStack()
- stack.reverse()
- # Better to add the query string, if present
- query = request.get('QUERY_STRING')
-
- camefrom = '/'.join([request.getURL(path_only=True)] + stack)
- if query:
- camefrom = camefrom + '?' + query
- url = '%s/@@%s?%s' % (absoluteURL(site, request),
- self.loginpagename,
- urlencode({'camefrom': camefrom}))
- request.response.redirect(url)
- return True
-
- def logout(self, request):
- """Performs logout by clearing session data credentials."""
- if not IHTTPRequest.providedBy(request):
- return False
-
- sessionData = ISession(request)[
- 'zope.app.authentication.browserplugins']
- sessionData['credentials'] = None
- transaction.commit()
- return True
Deleted: zope.pluggableauth/trunk/src/zope/pluggableauth/session.zcml
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/session.zcml 2010-01-23 21:28:55 UTC (rev 108412)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/session.zcml 2010-01-23 23:32:38 UTC (rev 108413)
@@ -1,28 +0,0 @@
-<configure
- xmlns="http://namespaces.zope.org/zope"
- i18n_domain="zope"
- >
-
- <utility
- name="Session Credentials"
- provides=".interfaces.ICredentialsPlugin"
- factory=".session.SessionCredentialsPlugin"
- />
-
- <class class=".session.SessionCredentialsPlugin">
-
- <implements
- interface="zope.annotation.interfaces.IAttributeAnnotatable"
- />
-
- <require
- permission="zope.ManageServices"
- interface=".session.IBrowserFormChallenger"
- set_schema=".session.IBrowserFormChallenger"
- />
-
- </class>
-
- <include package=".browser" file="session.zcml" />
-
-</configure>
Modified: zope.pluggableauth/trunk/src/zope/pluggableauth/testing.py
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/testing.py 2010-01-23 21:28:55 UTC (rev 108412)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/testing.py 2010-01-23 23:32:38 UTC (rev 108413)
@@ -1,26 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2007 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""zope.app.authentication common test related classes/functions/objects.
-
-$Id$
-"""
-
-__docformat__ = "reStructuredText"
-
-import os
-from zope.app.testing.functional import ZCMLLayer
-
-AppAuthenticationLayer = ZCMLLayer(
- os.path.join(os.path.split(__file__)[0], 'ftesting.zcml'),
- __name__, 'AppAuthenticationLayer', allow_teardown=True)
Modified: zope.pluggableauth/trunk/src/zope/pluggableauth/tests.py
===================================================================
--- zope.pluggableauth/trunk/src/zope/pluggableauth/tests.py 2010-01-23 21:28:55 UTC (rev 108412)
+++ zope.pluggableauth/trunk/src/zope/pluggableauth/tests.py 2010-01-23 23:32:38 UTC (rev 108413)
@@ -17,9 +17,8 @@
"""
__docformat__ = "reStructuredText"
-import unittest
+import doctest, unittest
-from zope.testing import doctest
from zope.interface import implements
from zope.component import provideUtility, provideAdapter, provideHandler
from zope.component.eventtesting import getEvents, clearEvents
@@ -34,20 +33,31 @@
from zope.session.http import CookieClientIdManager
from zope.publisher import base
-from zope.app.authentication.session import SessionCredentialsPlugin
+from zope.pluggableauth.plugins.session import SessionCredentialsPlugin
+import os
+from zope.app.testing.functional import ZCMLLayer
+AppAuthenticationLayer = ZCMLLayer(
+ os.path.join(os.path.split(__file__)[0], 'ftesting.zcml'),
+ __name__, 'AppAuthenticationLayer', allow_teardown=True)
+
+
+
class TestClientId(object):
implements(IClientId)
def __new__(cls, request):
return 'dummyclientidfortesting'
+
def siteSetUp(test):
placefulSetUp(site=True)
+
def siteTearDown(test):
placefulTearDown()
+
def sessionSetUp(session_data_container_class=PersistentSessionDataContainer):
placelesssetup.setUp()
provideAdapter(TestClientId, [IRequest], IClientId)
@@ -56,6 +66,7 @@
sdc = session_data_container_class()
provideUtility(sdc, ISessionDataContainer, '')
+
def nonHTTPSessionTestCaseSetUp(sdc_class=PersistentSessionDataContainer):
# I am getting an error with ClientId and not TestClientId
placelesssetup.setUp()
@@ -92,42 +103,31 @@
def test_suite():
- return unittest.TestSuite((
- doctest.DocTestSuite('zope.app.authentication.interfaces'),
- doctest.DocTestSuite('zope.app.authentication.password'),
- doctest.DocTestSuite('zope.app.authentication.generic'),
- doctest.DocTestSuite('zope.app.authentication.httpplugins'),
- doctest.DocTestSuite('zope.app.authentication.ftpplugins'),
- doctest.DocTestSuite('zope.app.authentication.groupfolder'),
- doctest.DocFileSuite('principalfolder.txt',
- setUp=placelesssetup.setUp,
- tearDown=placelesssetup.tearDown),
- doctest.DocTestSuite('zope.app.authentication.principalfolder',
- setUp=placelesssetup.setUp,
- tearDown=placelesssetup.tearDown),
- doctest.DocTestSuite('zope.app.authentication.idpicker'),
- doctest.DocTestSuite('zope.app.authentication.session',
- setUp=siteSetUp,
- tearDown=siteTearDown),
- doctest.DocFileSuite('README.txt',
- setUp=siteSetUp,
- tearDown=siteTearDown,
- globs={'provideUtility': provideUtility,
- 'provideAdapter': provideAdapter,
- 'provideHandler': provideHandler,
- 'getEvents': getEvents,
- 'clearEvents': clearEvents,
- }),
- doctest.DocFileSuite('groupfolder.txt',
- setUp=placelesssetup.setUp,
- tearDown=placelesssetup.tearDown,
- ),
- doctest.DocFileSuite('vocabulary.txt',
- setUp=placelesssetup.setUp,
- tearDown=placelesssetup.tearDown,
- ),
- unittest.makeSuite(NonHTTPSessionTestCase),
- ))
+ suite = unittest.TestSuite()
+ suite.addTest(doctest.DocTestSuite('zope.pluggableauth.interfaces'))
+ suite.addTest(doctest.DocTestSuite('zope.pluggableauth.plugins.generic'))
+ suite.addTest(doctest.DocTestSuite('zope.pluggableauth.plugins.ftpplugins'))
+ suite.addTest(doctest.DocTestSuite(
+ 'zope.pluggableauth.plugins.httpplugins'))
+
+ session = doctest.DocTestSuite('zope.pluggableauth.plugins.session',
+ setUp=siteSetUp,
+ tearDown=siteTearDown)
+
+ suite.addTest(session)
+ suite.addTest(unittest.makeSuite(NonHTTPSessionTestCase))
+
+ return suite
+ #doctest.DocFileSuite('README.txt',
+ # setUp=siteSetUp,
+ # tearDown=siteTearDown,
+ # globs={'provideUtility': provideUtility,
+ # 'provideAdapter': provideAdapter,
+ # 'provideHandler': provideHandler,
+ # 'getEvents': getEvents,
+ # 'clearEvents': clearEvents,
+ # }),
+
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
More information about the checkins
mailing list