[Zope3-checkins] SVN: Zope3/trunk/src/zope/security/ Make
end/restore interaction a bit more careful. Expand tests to
cover restore generally and this case specifically.
Gary Poster
gary at zope.com
Mon Nov 14 14:14:01 EST 2005
Log message for revision 40098:
Make end/restore interaction a bit more careful. Expand tests to cover restore generally and this case specifically.
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 2005-11-14 17:41:45 UTC (rev 40097)
+++ Zope3/trunk/src/zope/security/management.py 2005-11-14 19:14:00 UTC (rev 40098)
@@ -97,12 +97,26 @@
try:
thread_local.previous_interaction = thread_local.interaction
except AttributeError:
- pass
+ # if someone does a restore later, it should be restored to not having
+ # an interaction. If there was a previous interaction from a previous
+ # call to endInteraction, it should be removed.
+ try:
+ del thread_local.previous_interaction
+ except AttributeError:
+ pass
else:
del thread_local.interaction
def restoreInteraction():
- thread_local.interaction = thread_local.previous_interaction
+ try:
+ previous = thread_local.previous_interaction
+ except AttributeError:
+ try:
+ del thread_local.interaction
+ except AttributeError:
+ pass
+ else:
+ thread_local.interaction = previous
def checkPermission(permission, object, interaction=None):
"""Return whether security policy allows permission on object.
Modified: Zope3/trunk/src/zope/security/tests/test_management.py
===================================================================
--- Zope3/trunk/src/zope/security/tests/test_management.py 2005-11-14 17:41:45 UTC (rev 40097)
+++ Zope3/trunk/src/zope/security/tests/test_management.py 2005-11-14 19:14:00 UTC (rev 40098)
@@ -41,7 +41,7 @@
setSecurityPolicy(policy)
self.assert_(getSecurityPolicy() is policy)
- def test_query_new_end_Interaction(self):
+ def test_query_new_end_restore_Interaction(self):
from zope.security.management import queryInteraction
self.assertEquals(queryInteraction(), None)
@@ -49,16 +49,30 @@
newInteraction()
- self.assert_(queryInteraction() is not None)
+ interaction = queryInteraction()
+ self.assert_(interaction is not None)
self.assertRaises(AssertionError, newInteraction)
from zope.security.management import endInteraction
+ endInteraction()
+ self.assertEquals(queryInteraction(), None)
+ from zope.security.management import restoreInteraction
+ restoreInteraction()
+ self.assert_(interaction is queryInteraction())
+
endInteraction()
self.assertEquals(queryInteraction(), None)
+
endInteraction()
self.assertEquals(queryInteraction(), None)
+ newInteraction()
+ self.assert_(queryInteraction() is not None)
+
+ restoreInteraction() # restore to no interaction
+ self.assert_(queryInteraction() is None)
+
def test_checkPermission(self):
from zope.security import checkPermission
from zope.security.management import setSecurityPolicy
More information about the Zope3-Checkins
mailing list