/usr/share/pyshared/zope/security/tests/test_management.py is in python-zope.security 3.8.3-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | ##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
""" Unit tests for SecurityManagement
"""
import unittest
from zope.interface.verify import verifyObject
from zope.testing.cleanup import CleanUp
class Test(CleanUp, unittest.TestCase):
def test_import(self):
from zope.security import management
from zope.security.interfaces import ISecurityManagement
from zope.security.interfaces import IInteractionManagement
verifyObject(ISecurityManagement, management)
verifyObject(IInteractionManagement, management)
def test_securityPolicy(self):
from zope.security.management import setSecurityPolicy
from zope.security.management import getSecurityPolicy
from zope.security.simplepolicies import PermissiveSecurityPolicy
policy = PermissiveSecurityPolicy
setSecurityPolicy(policy)
self.assert_(getSecurityPolicy() is policy)
def test_query_new_end_restore_Interaction(self):
from zope.security.management import queryInteraction
self.assertEquals(queryInteraction(), None)
from zope.security.management import newInteraction
newInteraction()
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
from zope.security.management import queryInteraction
from zope.security.management import newInteraction, endInteraction
from zope.security.interfaces import NoInteraction
permission = 'zope.Test'
obj = object()
class PolicyStub(object):
def checkPermission(s, p, o,):
self.assert_(p is permission)
self.assert_(o is obj)
self.assert_(s is queryInteraction() or s is interaction)
return s is interaction
setSecurityPolicy(PolicyStub)
newInteraction()
interaction = queryInteraction()
self.assertEquals(checkPermission(permission, obj), True)
endInteraction()
self.assertRaises(NoInteraction, checkPermission, permission, obj)
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_system_user(self):
from zope.security.management import system_user
self.assertEquals(system_user.id,
u'zope.security.management.system_user')
self.assertEquals(system_user.title, u'System')
for name in 'id', 'title', 'description':
self.assert_(isinstance(getattr(system_user, name), unicode))
def test_suite():
loader = unittest.TestLoader()
return loader.loadTestsFromTestCase(Test)
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())
|