• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / Products.CMFCore / 6246931310

20 Sep 2023 09:54AM UTC coverage: 86.008% (-0.3%) from 86.266%
6246931310

Pull #131

github

mauritsvanrees
gha: don't need setup-python on 27 as we use the 27 container.
Pull Request #131: Make decodeFolderFilter and encodeFolderFilter non-public.

2466 of 3689 branches covered (0.0%)

Branch coverage included in aggregate %.

6 of 6 new or added lines in 1 file covered. (100.0%)

17297 of 19289 relevant lines covered (89.67%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.88
/src/Products/CMFCore/tests/base/security.py
1
##############################################################################
2
#
3
# Copyright (c) 2002 Zope Foundation and Contributors.
4
#
5
# This software is subject to the provisions of the Zope Public License,
6
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
7
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10
# FOR A PARTICULAR PURPOSE.
11
#
12
##############################################################################
13
""" Unit test security.
1✔
14
"""
15

16
import six
1✔
17

18
from AccessControl.interfaces import IUser
1✔
19
from AccessControl.PermissionRole import rolesForPermissionOn
1✔
20
from Acquisition import Implicit
1✔
21
from zope.interface import implementer
1✔
22

23

24
class PermissiveSecurityPolicy:
1✔
25

26
    """Very permissive security policy for unit testing purposes.
27
    """
28

29
    #
30
    #   Standard SecurityPolicy interface
31
    #
32
    def validate(self, accessed=None, container=None, name=None, value=None,
1✔
33
                 context=None, roles=None, *args, **kw):
34
        if name and name.startswith('hidden'):
1✔
35
            return False
1✔
36
        else:
37
            return True
1✔
38

39
    def checkPermission(self, permission, object, context):
1✔
40
        roles = rolesForPermissionOn(permission, object)
1✔
41
        if isinstance(roles, six.string_types):
1!
42
            roles = [roles]
×
43
        return context.user.allowed(object, roles)
1✔
44

45

46
@implementer(IUser)
1✔
47
class _BaseUser(Implicit):
1✔
48

49
    def getId(self):
1✔
50
        return self._id
1✔
51

52
    def getUserName(self):
1✔
53
        return self._name
1✔
54

55
    def getRoles(self):
1✔
56
        return self._roles
1✔
57

58
    def getRolesInContext(self, object):
1✔
59
        return self._roles
1✔
60

61
    def getDomains(self):
1✔
62
        return self._domains
1✔
63

64
    def allowed(self, object, object_roles=None):
1✔
65
        if object_roles is None or 'Anonymous' in object_roles:
1✔
66
            return True
1✔
67
        return any(r in self._roles for r in object_roles)
1✔
68

69
    def _check_context(self, object):
1✔
70
        return True
1✔
71

72

73
class OmnipotentUser(_BaseUser):
1✔
74

75
    """Omnipotent user for unit testing purposes.
76
    """
77

78
    _id = 'all_powerful_Oz'
1✔
79
    _name = 'All Powerful Oz'
1✔
80
    _roles = ('Manager',)
1✔
81

82
    def allowed(self, object, object_roles=None):
1✔
83
        return True
1✔
84

85

86
class UserWithRoles(_BaseUser):
1✔
87

88
    """User with roles specified in constructor for unit testing purposes.
89
    """
90

91
    _id = 'high_roller'
1✔
92
    _name = 'High Roller'
1✔
93

94
    def __init__(self, *roles):
1✔
95
        self._roles = roles
1✔
96

97

98
class DummyUser(_BaseUser):
1✔
99

100
    """ A dummy User.
101
    """
102

103
    _roles = ('Authenticated', 'Dummy', 'Member')
1✔
104

105
    def __init__(self, id='dummy'):
1✔
106
        self._id = id
1✔
107
        self._name = 'name of %s' % id
1✔
108

109

110
class AnonymousUser(_BaseUser):
1✔
111

112
    """Anonymous user for unit testing purposes.
113
    """
114

115
    _id = None
1✔
116
    _name = 'Anonymous User'
1✔
117
    _roles = ('Anonymous',)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc