[Zope3-checkins] CVS: Zope3/src/zope/app/security/grants/tests - test_securitymap.py:1.1 test_annotationprincipalpermissionmanager.py:1.3 test_annotationprincipalrolemanager.py:1.3 test_annotationrolepermissionmanager.py:1.3 test_principalpermissionmanager.py:1.3 test_principalrolemanager.py:1.3 test_rolepermissionmanager.py:1.3 test_localsecuritymap.py:NONE test_persistentlocalsecuritymap.py:NONE
Jim Fulton
jim@zope.com
Thu, 26 Dec 2002 13:49:39 -0500
Update of /cvs-repository/Zope3/src/zope/app/security/grants/tests
In directory cvs.zope.org:/tmp/cvs-serv19745/grants/tests
Modified Files:
test_annotationprincipalpermissionmanager.py
test_annotationprincipalrolemanager.py
test_annotationrolepermissionmanager.py
test_principalpermissionmanager.py
test_principalrolemanager.py test_rolepermissionmanager.py
Added Files:
test_securitymap.py
Removed Files:
test_localsecuritymap.py test_persistentlocalsecuritymap.py
Log Message:
Added functions for checking validity of permission, role, and
principal ids.
Updated global grants to perform these chacks.
Renamed and consolidated a number of files in the ongoing quest to get
to single-line imports.
=== Added File Zope3/src/zope/app/security/grants/tests/test_securitymap.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
#############################################################################
import unittest
from zope.interface.verify import verifyClass
from zope.app.interfaces.security.grants.securitymap import ISecurityMap
from zope.app.security.grants.securitymap import SecurityMap
from zope.app.security.grants.securitymap import PersistentSecurityMap
class TestSecurityMap(unittest.TestCase):
def testInterface(self):
verifyClass(ISecurityMap, SecurityMap)
# XXX Test the map. Grrrrr.
class TestPersistentSecurityMap(TestSecurityMap):
def testInterface(self):
verifyClass(ISecurityMap, PersistentSecurityMap)
# XXX test persistence...
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestSecurityMap),
unittest.makeSuite(TestPersistentSecurityMap),
))
=== Zope3/src/zope/app/security/grants/tests/test_annotationprincipalpermissionmanager.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/security/grants/tests/test_annotationprincipalpermissionmanager.py:1.2 Wed Dec 25 09:13:17 2002
+++ Zope3/src/zope/app/security/grants/tests/test_annotationprincipalpermissionmanager.py Thu Dec 26 13:49:08 2002
@@ -24,7 +24,7 @@
import permissionRegistry as permregistry
from zope.app.security.registries.principalregistry \
import principalRegistry as prinregistry
-from zope.app.security.grants.annotationprincipalpermissionmanager \
+from zope.app.security.grants.principalpermission \
import AnnotationPrincipalPermissionManager
from zope.app.security.settings import Allow, Deny, Unset
from zope.app.tests.placelesssetup import PlacelessSetup
=== Zope3/src/zope/app/security/grants/tests/test_annotationprincipalrolemanager.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/security/grants/tests/test_annotationprincipalrolemanager.py:1.2 Wed Dec 25 09:13:17 2002
+++ Zope3/src/zope/app/security/grants/tests/test_annotationprincipalrolemanager.py Thu Dec 26 13:49:08 2002
@@ -23,7 +23,7 @@
from zope.app.security.registries.roleregistry import roleRegistry as rregistry
from zope.app.security.registries.principalregistry \
import principalRegistry as pregistry
-from zope.app.security.grants.annotationprincipalrolemanager \
+from zope.app.security.grants.principalrole \
import AnnotationPrincipalRoleManager
from zope.app.security.settings import Allow, Deny
from zope.app.services.tests.placefulsetup \
=== Zope3/src/zope/app/security/grants/tests/test_annotationrolepermissionmanager.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/security/grants/tests/test_annotationrolepermissionmanager.py:1.2 Wed Dec 25 09:13:17 2002
+++ Zope3/src/zope/app/security/grants/tests/test_annotationrolepermissionmanager.py Thu Dec 26 13:49:08 2002
@@ -11,7 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-from zope.app.security.grants.annotationrolepermissionmanager \
+from zope.app.security.grants.rolepermission \
import AnnotationRolePermissionManager
from zope.app.interfaces.annotation import IAttributeAnnotatable
from zope.app.interfaces.annotation import IAnnotations
=== Zope3/src/zope/app/security/grants/tests/test_principalpermissionmanager.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/security/grants/tests/test_principalpermissionmanager.py:1.2 Wed Dec 25 09:13:17 2002
+++ Zope3/src/zope/app/security/grants/tests/test_principalpermissionmanager.py Thu Dec 26 13:49:08 2002
@@ -16,17 +16,32 @@
import sys
import unittest
+from zope.component.service import serviceManager as services
+
+from zope.app.interfaces.security import IPermissionService
+from zope.app.interfaces.security import IAuthenticationService
+
from zope.app.security.registries.permissionregistry \
import permissionRegistry as permregistry
from zope.app.security.registries.principalregistry \
import principalRegistry as prinregistry
-from zope.app.security.grants.principalpermissionmanager \
+from zope.app.security.grants.principalpermission \
import principalPermissionManager as manager
from zope.app.security.settings import Allow, Deny, Unset
from zope.testing.cleanup import CleanUp # Base class w registry cleanup
class Test(CleanUp, unittest.TestCase):
+ def setUp(self):
+ CleanUp.setUp(self)
+
+ services.defineService('Permissions', IPermissionService)
+ services.provideService('Permissions', permregistry)
+
+ services.defineService('Authentication', IAuthenticationService)
+ services.provideService('Authentication', prinregistry)
+
+
def _make_principal(self, id=None, title=None):
p = prinregistry.definePrincipal(
id or 'APrincipal',
@@ -39,6 +54,23 @@
principal = self._make_principal()
self.assertEqual(manager.getPrincipalsForPermission(permission), [])
self.assertEqual(manager.getPermissionsForPrincipal(principal), [])
+
+
+ def test_invalidPermission(self):
+ self.assertRaises(ValueError,
+ manager.grantPermissionToPrincipal,
+ 'permission', 'principal')
+ principal = self._make_principal()
+ self.assertRaises(ValueError,
+ manager.grantPermissionToPrincipal,
+ 'permission', principal)
+
+ def test_invalidPrincipal(self):
+ permission = permregistry.definePermission('APerm', 'title').getId()
+ self.assertRaises(ValueError,
+ manager.grantPermissionToPrincipal,
+ permission, 'principal')
+
def testPrincipalPermission(self):
permission = permregistry.definePermission('APerm', 'title').getId()
=== Zope3/src/zope/app/security/grants/tests/test_principalrolemanager.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/security/grants/tests/test_principalrolemanager.py:1.2 Wed Dec 25 09:13:17 2002
+++ Zope3/src/zope/app/security/grants/tests/test_principalrolemanager.py Thu Dec 26 13:49:08 2002
@@ -16,17 +16,30 @@
import sys
import unittest
+from zope.component.service import serviceManager as services
+
+from zope.app.interfaces.security import IRoleService
+from zope.app.interfaces.security import IAuthenticationService
+
from zope.app.security.registries.roleregistry \
import roleRegistry as rregistry
from zope.app.security.registries.principalregistry \
import principalRegistry as pregistry
-from zope.app.security.grants.principalrolemanager \
- import principalRoleManager
+from zope.app.security.grants.principalrole import principalRoleManager
from zope.app.security.settings import Allow, Deny
from zope.testing.cleanup import CleanUp # Base class w registry cleanup
class Test(CleanUp, unittest.TestCase):
+ def setUp(self):
+ CleanUp.setUp(self)
+
+ services.defineService('Roles', IRoleService)
+ services.provideService('Roles', rregistry)
+
+ services.defineService('Authentication', IAuthenticationService)
+ services.provideService('Authentication', pregistry)
+
def _make_principal(self, id=None, title=None):
p = pregistry.definePrincipal(
id or 'APrincipal',
@@ -68,6 +81,23 @@
[])
self.assertEqual(principalRoleManager.getRolesForPrincipal(principal),
[])
+
+
+ def test_invalidPrincipal(self):
+ self.assertRaises(ValueError,
+ principalRoleManager.assignRoleToPrincipal,
+ 'role1', 'prin1')
+ role1 = rregistry.defineRole('Role One', 'Role #1').getId()
+ self.assertRaises(ValueError,
+ principalRoleManager.assignRoleToPrincipal,
+ role1, 'prin1')
+
+ def test_invalidRole(self):
+ prin1 = self._make_principal()
+ self.assertRaises(ValueError,
+ principalRoleManager.assignRoleToPrincipal,
+ 'role1', prin1)
+
def testManyRolesOnePrincipal(self):
role1 = rregistry.defineRole('Role One', 'Role #1').getId()
=== Zope3/src/zope/app/security/grants/tests/test_rolepermissionmanager.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/security/grants/tests/test_rolepermissionmanager.py:1.2 Wed Dec 25 09:13:17 2002
+++ Zope3/src/zope/app/security/grants/tests/test_rolepermissionmanager.py Thu Dec 26 13:49:08 2002
@@ -16,11 +16,16 @@
import sys
import unittest
+from zope.component.service import serviceManager as services
+
+from zope.app.interfaces.security import IPermissionService
+from zope.app.interfaces.security import IRoleService
+
from zope.app.security.registries.permissionregistry \
import permissionRegistry as pregistry
from zope.app.security.registries.roleregistry \
import roleRegistry as rregistry
-from zope.app.security.grants.rolepermissionmanager \
+from zope.app.security.grants.rolepermission \
import rolePermissionManager as manager
from zope.app.security.settings \
import Allow, Deny, Unset
@@ -28,6 +33,15 @@
class Test(CleanUp, unittest.TestCase):
+ def setUp(self):
+ CleanUp.setUp(self)
+
+ services.defineService('Permissions', IPermissionService)
+ services.provideService('Permissions', pregistry)
+
+ services.defineService('Roles', IRoleService)
+ services.provideService('Roles', rregistry)
+
def testUnboundRolePermission(self):
permission = pregistry.definePermission('APerm', 'aPerm title').getId()
role = rregistry.defineRole('ARole', 'A Role').getId()
@@ -83,6 +97,22 @@
roles = manager.getRolesForPermission(perm1)
self.assertEqual(len(roles), 1)
self.failUnless((role2,Allow) in roles)
+
+ def test_invalidRole(self):
+ self.assertRaises(ValueError,
+ manager.grantPermissionToRole, 'perm1', 'role1'
+ )
+ perm1 = pregistry.definePermission('Perm One', 'title').getId()
+ self.assertRaises(ValueError,
+ manager.grantPermissionToRole, perm1, 'role1'
+ )
+
+ def test_invalidPerm(self):
+ role1 = rregistry.defineRole('Role One', 'Role #1').getId()
+ self.assertRaises(ValueError,
+ manager.grantPermissionToRole, 'perm1', role1
+ )
+
def test_suite():
loader=unittest.TestLoader()
=== Removed File Zope3/src/zope/app/security/grants/tests/test_localsecuritymap.py ===
=== Removed File Zope3/src/zope/app/security/grants/tests/test_persistentlocalsecuritymap.py ===