[Zope3-checkins] SVN: Zope3/trunk/src/zope/security/ Now checkPermission is truly guaranteed to return True if

Dmitry Vasiliev dima at hlabs.spb.ru
Mon Jul 26 03:28:05 EDT 2004


Log message for revision 26753:
  Now checkPermission is truly guaranteed to return True if
  permission is CheckerPublic or None.
  


Changed:
  U   Zope3/trunk/src/zope/security/management.py
  U   Zope3/trunk/src/zope/security/tests/test_management.py


-=-
Modified: Zope3/trunk/src/zope/security/management.py
===================================================================
--- Zope3/trunk/src/zope/security/management.py	2004-07-25 14:20:25 UTC (rev 26752)
+++ Zope3/trunk/src/zope/security/management.py	2004-07-26 07:28:05 UTC (rev 26753)
@@ -117,6 +117,8 @@
     checkPermission is guaranteed to return True if permission is
     CheckerPublic or None.
     """
+    if permission is CheckerPublic or permission is None:
+        return True
     if interaction is None:
         interaction = thread_local.interaction
     return interaction.checkPermission(permission, object)
@@ -126,5 +128,6 @@
 
 # circular imports are not fun
 
+from zope.security.checker import CheckerPublic
 from zope.security.simplepolicies import ParanoidSecurityPolicy
 _defaultPolicy = ParanoidSecurityPolicy

Modified: Zope3/trunk/src/zope/security/tests/test_management.py
===================================================================
--- Zope3/trunk/src/zope/security/tests/test_management.py	2004-07-25 14:20:25 UTC (rev 26752)
+++ Zope3/trunk/src/zope/security/tests/test_management.py	2004-07-26 07:28:05 UTC (rev 26753)
@@ -68,9 +68,6 @@
         permission = 'zope.Test'
         obj = object()
 
-        class InteractionStub(object):
-            pass
-
         class PolicyStub(object):
 
             def checkPermission(s, p, o,):
@@ -84,7 +81,26 @@
         interaction = queryInteraction()
         self.assertEquals(checkPermission(permission, obj), True)
 
+    def test_checkPublicPermission(self):
+        from zope.security import checkPermission
+        from zope.security.checker import CheckerPublic
+        from zope.security.management import setSecurityPolicy
+        from zope.security.management import newInteraction
 
+        obj = object()
+
+        class ForbiddenPolicyStub(object):
+
+            def checkPermission(s, p, o):
+                return False
+
+        setSecurityPolicy(ForbiddenPolicyStub)
+        newInteraction()
+        self.assertEquals(checkPermission('zope.Test', obj), False)
+        self.assertEquals(checkPermission(None, obj), True)
+        self.assertEquals(checkPermission(CheckerPublic, obj), True)
+
+
 def test_suite():
     loader = unittest.TestLoader()
     return loader.loadTestsFromTestCase(Test)



More information about the Zope3-Checkins mailing list