summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSidnei da Silva <sidnei.da.silva@gmail.com>2010-02-22 22:48:31 +0000
committerSidnei da Silva <sidnei.da.silva@gmail.com>2010-02-22 22:48:31 +0000
commit5e906fa3f5a783e10e8a7866424341122362c6fe (patch)
treea6b87e9fe5ee37de5925a44422c33b7c0bf6209a /src
parentd0841ca4a8b39af8195a48896158378b7a66ac72 (diff)
downloadzope-component-5e906fa3f5a783e10e8a7866424341122362c6fe.tar.gz
- Fixed a bug introduced by recent refactoring, where passing
CheckerPublic to securityAdapterFactory wrongly wrapped the factory into a LocatingUntrustedAdapterFactory.
Diffstat (limited to 'src')
-rw-r--r--src/zope/component/security.py80
-rw-r--r--src/zope/component/tests.py1
-rw-r--r--src/zope/component/zcml.txt1
3 files changed, 81 insertions, 1 deletions
diff --git a/src/zope/component/security.py b/src/zope/component/security.py
index 742db3b..65f00bd 100644
--- a/src/zope/component/security.py
+++ b/src/zope/component/security.py
@@ -86,7 +86,85 @@ def protectedFactory(original_factory, provides, permission):
return factory
def securityAdapterFactory(factory, permission, locate, trusted):
- if locate or (permission is not None and permission != PublicPermission):
+ """
+ If a permission is provided when wrapping the adapter, it will be
+ wrapped in a LocatingAdapterFactory.
+
+ >>> class Factory:
+ ... pass
+
+ If both locate and trusted are False and a non-public
+ permission is provided, then the factory is wrapped into a
+ LocatingUntrustedAdapterFactory:
+
+ >>> factory = securityAdapterFactory(Factory, 'zope.AnotherPermission',
+ ... locate=False, trusted=False)
+
+ >>> isinstance(factory, LocatingUntrustedAdapterFactory)
+ True
+
+ If a PublicPermission is provided, then the factory is not touched.
+
+ >>> factory = securityAdapterFactory(Factory, PublicPermission,
+ ... locate=False, trusted=False)
+
+ >>> factory is Factory
+ True
+
+ Same for CheckerPublic:
+
+ >>> factory = securityAdapterFactory(Factory, CheckerPublic,
+ ... locate=False, trusted=False)
+
+ >>> factory is Factory
+ True
+
+ If the permission is None, the factory isn't touched:
+
+ >>> factory = securityAdapterFactory(Factory, None,
+ ... locate=False, trusted=False)
+
+ >>> factory is Factory
+ True
+
+ If the factory is trusted and a no permission is provided then the
+ adapter is wrapped into a TrustedAdapterFactory:
+
+ >>> factory = securityAdapterFactory(Factory, None,
+ ... locate=False, trusted=True)
+
+ >>> isinstance(factory, TrustedAdapterFactory)
+ True
+
+ Same for PublicPermission:
+
+ >>> factory = securityAdapterFactory(Factory, PublicPermission,
+ ... locate=False, trusted=True)
+
+ >>> isinstance(factory, TrustedAdapterFactory)
+ True
+
+ Same for CheckerPublic:
+
+ >>> factory = securityAdapterFactory(Factory, CheckerPublic,
+ ... locate=False, trusted=True)
+
+ >>> isinstance(factory, TrustedAdapterFactory)
+ True
+
+ If the factory is trusted and a locate is true, then the
+ adapter is wrapped into a LocatingTrustedAdapterFactory:
+
+ >>> factory = securityAdapterFactory(Factory, 'zope.AnotherPermission',
+ ... locate=True, trusted=True)
+
+ >>> isinstance(factory, LocatingTrustedAdapterFactory)
+ True
+
+ """
+ if permission == PublicPermission:
+ permission = CheckerPublic
+ if locate or (permission is not None and permission is not CheckerPublic):
if trusted:
return LocatingTrustedAdapterFactory(factory)
else:
diff --git a/src/zope/component/tests.py b/src/zope/component/tests.py
index a5c5e06..0407b3d 100644
--- a/src/zope/component/tests.py
+++ b/src/zope/component/tests.py
@@ -1704,6 +1704,7 @@ def test_suite():
setUp=setUp, tearDown=tearDown),
doctest.DocFileSuite('event.txt',
setUp=setUp, tearDown=tearDown),
+ doctest.DocTestSuite('zope.component.security'),
doctest.DocFileSuite('zcml.txt', checker=checker,
setUp=setUp, tearDown=tearDown),
doctest.DocFileSuite('testlayer.txt',
diff --git a/src/zope/component/zcml.txt b/src/zope/component/zcml.txt
index f54e30c..ca66286 100644
--- a/src/zope/component/zcml.txt
+++ b/src/zope/component/zcml.txt
@@ -126,6 +126,7 @@ Of course, if no factory is provided at all, we will get an error:
ZopeXMLConfigurationError: File "<string>", line 4.2-8.8
ValueError: No factory specified
+
Declaring ``for`` and ``provides`` in Python
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~