blob: 8905fca7cd53ade79212c2d8b7c734fa61a0615c (
plain)
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
|
##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################
"""Test location support
"""
import unittest
def _skip_wo_zope_location(testfunc):
try:
import zope.location
except ImportError:
from functools import update_wrapper
def dummy(self):
pass
update_wrapper(dummy, testfunc)
return dummy
else:
return testfunc
class LocationSecurityProxyTests(unittest.TestCase):
@_skip_wo_zope_location
def test_locationproxy_security(self):
from zope.location.location import LocationProxy
from zope.security.checker import defineChecker
from zope.security.checker import NamesChecker
from zope.security.proxy import ProxyFactory
class Unlocated(object):
a = 'a'
unlocated = Unlocated()
located = LocationProxy(unlocated)
# define a checker for the unlocated object, which will also be
# used by the security proxy as the LocationProxy defines
# __Security_checker__:
unlocatedChecker = NamesChecker(['a'])
defineChecker(Unlocated, unlocatedChecker)
secure_located = ProxyFactory(located)
self.assertEqual(secure_located.a, 'a')
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(LocationSecurityProxyTests),
))
|