[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security/tests - testSecurityManagement.py:1.1.2.3
Martijn Pieters
mj@zope.com
Tue, 4 Dec 2001 11:19:51 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security/tests
In directory cvs.zope.org:/tmp/cvs-serv13405/tests
Modified Files:
Tag: Zope-3x-branch
testSecurityManagement.py
Log Message:
Add name based security policy; base acces solely on the name used.
=== Zope3/lib/python/Zope/App/Security/tests/testSecurityManagement.py 1.1.2.2 => 1.1.2.3 ===
self._oldPolicy = setSecurityPolicy( ParanoidSecurityPolicy() )
+ def _setNameBased(self, nameChecker):
+ from Zope.App.Security.SecurityManagement import setSecurityPolicy
+ from Zope.App.Security.SimpleSecurityPolicies \
+ import NameBasedSecurityPolicy
+ self._oldPolicy = setSecurityPolicy( NameBasedSecurityPolicy(nameChecker) )
+
+
def test_setSecurityPolicy( self ):
from Zope.App.Security.SecurityManagement import noSecurityManager
@@ -114,3 +121,16 @@
self.assertRaises( Unauthorized, mgr.validate, None, None )
self.assertRaises( Unauthorized, mgr.validateValue, None )
self.failIf( mgr.checkPermission( None, None ) )
+
+ # test against name based policy
+ def allowFoo(name):
+ if name != 'foo': raise Unauthorized
+ self._restorePolicy()
+ self._setNameBased(allowFoo)
+ noSecurityManager()
+ mgr = getSecurityManager()
+ mgr.validate('foo', None)
+ self.assertRaises(Unauthorized, mgr.validate, 'bar', None)
+ self.assertRaises(Unauthorized, mgr.validateValue, None)
+ self.failUnless( mgr.checkPermission( None, None ) )
+