[Zope-Checkins] CVS: Zope/lib/python/AccessControl/tests -
testBindings.py:1.1.2.3
Brian Lloyd
brian at zope.com
Wed Jan 21 12:08:30 EST 2004
Update of /cvs-repository/Zope/lib/python/AccessControl/tests
In directory cvs.zope.org:/tmp/cvs-serv357/AccessControl/tests
Modified Files:
Tag: Zope-2_6-branch
testBindings.py
Log Message:
fix and tests for b/w compatibility workaround re: container binding checks
=== Zope/lib/python/AccessControl/tests/testBindings.py 1.1.2.2 => 1.1.2.3 ===
--- Zope/lib/python/AccessControl/tests/testBindings.py:1.1.2.2 Thu Jan 8 17:54:53 2004
+++ Zope/lib/python/AccessControl/tests/testBindings.py Wed Jan 21 12:08:29 2004
@@ -113,6 +113,21 @@
open.__roles__ = ( 'Anonymous', )
guarded._setOb('open', open)
+ bound_unused_container_ps = self._newPS('return 1')
+ guarded._setOb('bound_unused_container_ps', bound_unused_container_ps)
+
+ bound_used_container_ps = self._newPS('return container.id')
+ guarded._setOb('bound_used_container_ps', bound_used_container_ps)
+
+ bound_used_container_ok_ps = self._newPS('return container.id')
+ open._setOb('bound_used_container_ok_ps', bound_used_container_ok_ps)
+
+ bound_unused_context_ps = self._newPS('return 1')
+ guarded._setOb('bound_unused_context_ps', bound_unused_context_ps)
+
+ bound_used_context_ps = self._newPS('return context.id')
+ guarded._setOb('bound_used_context_ps', bound_used_context_ps)
+
container_ps = self._newPS('return container')
guarded._setOb('container_ps', container_ps)
@@ -129,29 +144,62 @@
ps._makeFunction()
return ps
- def test_fail_container(self):
+ # These test that the mere binding of context or container, when the
+ # user doesn't have access to them, doesn't raise an unauthorized. An
+ # exception *will* be raised if the script attempts to use them. This
+ # is a b/w compatibility hack: see Bindings.py for details.
+
+ def test_bound_unused_container(self):
+ from AccessControl.SecurityManagement import newSecurityManager
+ newSecurityManager(None, UnderprivilegedUser())
+ root = self._makeTree()
+ guarded = root._getOb('guarded')
+ ps = guarded._getOb('bound_unused_container_ps')
+ self.assertEqual(ps(), 1)
+
+ def test_bound_used_container(self):
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl import Unauthorized
newSecurityManager(None, UnderprivilegedUser())
root = self._makeTree()
guarded = root._getOb('guarded')
- container_ps = guarded._getOb('container_ps')
- self.assertRaises(Unauthorized, container_ps)
+ ps = guarded._getOb('bound_used_container_ps')
+ self.assertRaises(Unauthorized, ps)
- def test_fail_context(self):
+ def test_bound_used_container_allowed(self):
+ from AccessControl.SecurityManagement import newSecurityManager
+ newSecurityManager(None, UnderprivilegedUser())
+ root = self._makeTree()
+ guarded = root._getOb('guarded')
+ open = guarded._getOb('open')
+ ps = open.unrestrictedTraverse('bound_used_container_ok_ps')
+ self.assertEqual(ps(), 'open')
+
+ def test_bound_unused_context(self):
+ from AccessControl.SecurityManagement import newSecurityManager
+ newSecurityManager(None, UnderprivilegedUser())
+ root = self._makeTree()
+ guarded = root._getOb('guarded')
+ ps = guarded._getOb('bound_unused_context_ps')
+ self.assertEqual(ps(), 1)
+
+ def test_bound_used_context(self):
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl import Unauthorized
newSecurityManager(None, UnderprivilegedUser())
root = self._makeTree()
guarded = root._getOb('guarded')
+ ps = guarded._getOb('bound_used_context_ps')
+ self.assertRaises(Unauthorized, ps)
+
+ def test_bound_used_context_allowed(self):
+ from AccessControl.SecurityManagement import newSecurityManager
+ newSecurityManager(None, UnderprivilegedUser())
+ root = self._makeTree()
+ guarded = root._getOb('guarded')
open = guarded._getOb('open')
- context_ps = open.unrestrictedTraverse('context_ps')
- #
- # Note that we are raising here even though our context ('open')
- # would be allowed, because the default bindings include our
- # container ('guarded') which isn't.
- #
- self.assertRaises(Unauthorized, context_ps)
+ ps = open.unrestrictedTraverse('bound_used_context_ps')
+ self.assertEqual(ps(), 'open')
def test_ok_no_bindings(self):
from AccessControl.SecurityManagement import newSecurityManager
More information about the Zope-Checkins
mailing list