Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
erp5
Commits
eacea55f
Commit
eacea55f
authored
May 27, 2020
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SecurityTestCase: type annotations
parent
20408c24
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
17 deletions
+32
-17
product/ERP5Type/tests/SecurityTestCase.py
product/ERP5Type/tests/SecurityTestCase.py
+32
-17
No files found.
product/ERP5Type/tests/SecurityTestCase.py
View file @
eacea55f
...
...
@@ -51,10 +51,15 @@ def formatNameUnion(names):
Guard
.
formatNameUnion
=
formatNameUnion
from
Products.ERP5Type.Base
import
Base
from
typing
import
Callable
class
AssertPermissionMethod
(
object
):
"""A method object to check that a user have a permission on a document.
"""
def
__init__
(
self
,
permission_name
):
# type: (str) -> None
self
.
_permission_name
=
permission_name
def
__get__
(
self
,
instance
,
cls
=
None
):
...
...
@@ -62,6 +67,7 @@ class AssertPermissionMethod(object):
return
self
def
__call__
(
self
,
username
,
document
):
# type: (str, Base) -> None
sm
=
getSecurityManager
()
try
:
self
.
_instance
.
_loginAsUser
(
username
)
...
...
@@ -90,6 +96,7 @@ class AssertNoPermissionMethod(object):
document.
"""
def
__init__
(
self
,
permission_name
):
# type: (str) -> None
self
.
_permission_name
=
permission_name
def
__get__
(
self
,
instance
,
cls
=
None
):
...
...
@@ -97,6 +104,7 @@ class AssertNoPermissionMethod(object):
return
self
def
__call__
(
self
,
username
,
document
):
# type: (str, Base) -> None
sm
=
getSecurityManager
()
try
:
self
.
_instance
.
_loginAsUser
(
username
)
...
...
@@ -141,19 +149,20 @@ class SecurityTestCase(ERP5TypeTestCase):
# Permission methods
failIfUserCanViewDocument
=
assertUserCanNotViewDocument
=
AssertNoPermissionMethod
(
Permissions
.
View
)
Permissions
.
View
)
# type: Callable[[SecurityTestCase, str, Base], None]
failIfUserCanAccessDocument
=
assertUserCanNotAccessDocument
=
AssertNoPermissionMethod
(
Permissions
.
AccessContentsInformation
)
Permissions
.
AccessContentsInformation
)
# type: Callable[[SecurityTestCase, str, Base], None]
failIfUserCanModifyDocument
=
assertUserCanNotModifyDocument
=
AssertNoPermissionMethod
(
Permissions
.
ModifyPortalContent
)
Permissions
.
ModifyPortalContent
)
# type: Callable[[SecurityTestCase, str, Base], None]
failIfUserCanAddDocument
=
assertUserCanNotAddDocument
=
AssertNoPermissionMethod
(
Permissions
.
AddPortalContent
)
Permissions
.
AddPortalContent
)
# type: Callable[[SecurityTestCase, str, Base], None]
failIfUserCanChangeLocalRoles
=
assertUserCanNotChangeLocalRoles
=
AssertNoPermissionMethod
(
Permissions
.
ChangeLocalRoles
)
Permissions
.
ChangeLocalRoles
)
# type: Callable[[SecurityTestCase, str, Base], None]
failIfUserCanDeleteDocument
=
assertUserCanNotDeleteDocument
=
AssertNoPermissionMethod
(
Permissions
.
DeleteObjects
)
Permissions
.
DeleteObjects
)
# type: Callable[[SecurityTestCase, str, Base], None]
def
failIfUserHavePermissionOnDocument
(
self
,
permission_name
,
username
,
document
):
# type: (str, str, Base) -> None
"""Fail If the user have a permission on document.
XXX why isn't it a method object ?
"""
...
...
@@ -162,19 +171,20 @@ class SecurityTestCase(ERP5TypeTestCase):
return
method
(
username
,
document
)
failUnlessUserCanViewDocument
=
assertUserCanViewDocument
=
\
AssertPermissionMethod
(
Permissions
.
View
)
AssertPermissionMethod
(
Permissions
.
View
)
# type: Callable[[SecurityTestCase, str, Base], None]
failUnlessUserCanAccessDocument
=
assertUserCanAccessDocument
=
\
AssertPermissionMethod
(
Permissions
.
AccessContentsInformation
)
AssertPermissionMethod
(
Permissions
.
AccessContentsInformation
)
# type: Callable[[SecurityTestCase, str, Base], None]
failUnlessUserCanModifyDocument
=
assertUserCanModifyDocument
=
\
AssertPermissionMethod
(
Permissions
.
ModifyPortalContent
)
AssertPermissionMethod
(
Permissions
.
ModifyPortalContent
)
# type: Callable[[SecurityTestCase, str, Base], None]
failUnlessUserCanAddDocument
=
assertUserCanAddDocument
=
\
AssertPermissionMethod
(
Permissions
.
AddPortalContent
)
AssertPermissionMethod
(
Permissions
.
AddPortalContent
)
# type: Callable[[SecurityTestCase, str, Base], None]
failUnlessUserCanChangeLocalRoles
=
assertUserCanChangeLocalRoles
=
\
AssertPermissionMethod
(
Permissions
.
ChangeLocalRoles
)
AssertPermissionMethod
(
Permissions
.
ChangeLocalRoles
)
# type: Callable[[SecurityTestCase, str, Base], None]
failUnlessUserCanDeleteDocument
=
assertUserCanDeleteDocument
=
\
AssertPermissionMethod
(
Permissions
.
DeleteObjects
)
AssertPermissionMethod
(
Permissions
.
DeleteObjects
)
# type: Callable[[SecurityTestCase, str, Base], None]
def
failUnlessUserHavePermissionOnDocument
(
self
,
permission_name
,
username
,
document
):
# type: (str, str, Base) -> None
"""Fail Unless the user have a permission on document."""
method
=
AssertPermissionMethod
(
permission_name
)
method
.
_instance
=
self
...
...
@@ -183,6 +193,7 @@ class SecurityTestCase(ERP5TypeTestCase):
# Workflow Transition Methods
def
failIfUserCanPassWorkflowTransition
(
self
,
username
,
transition
,
document
):
# type: (str, str, Base) -> None
"""Fails if the user can pass the workflow transition on the document."""
sm
=
getSecurityManager
()
try
:
...
...
@@ -198,10 +209,11 @@ class SecurityTestCase(ERP5TypeTestCase):
finally
:
setSecurityManager
(
sm
)
assertUserCanNotPassWorkflowTransition
=
failIfUserCanPassWorkflowTransition
assertUserCanNotPassWorkflowTransition
=
failIfUserCanPassWorkflowTransition
# type: Callable[[SecurityTestCase, str, str, Base], None]
def
failUnlessUserCanPassWorkflowTransition
(
self
,
username
,
transition
,
document
):
# type: (str, str, Base) -> None
"""Fails unless the user can pass the workflow transition on the document."""
sm
=
getSecurityManager
()
try
:
...
...
@@ -244,9 +256,10 @@ class SecurityTestCase(ERP5TypeTestCase):
finally
:
setSecurityManager
(
sm
)
assertUserCanPassWorkflowTransition
=
failUnlessUserCanPassWorkflowTransition
assertUserCanPassWorkflowTransition
=
failUnlessUserCanPassWorkflowTransition
# type: Callable[[SecurityTestCase, str, str, Base], None]
def
assertUserHasWorklist
(
self
,
username
,
worklist_id
,
document_count
):
# type: (str, str, int) -> None
self
.
portal
.
portal_workflow
.
refreshWorklistCache
()
self
.
portal
.
portal_caches
.
clearAllCache
()
sm
=
getSecurityManager
()
...
...
@@ -268,6 +281,7 @@ class SecurityTestCase(ERP5TypeTestCase):
setSecurityManager
(
sm
)
def
assertUserHasNoWorklist
(
self
,
username
,
worklist_id
):
# type: (str, str) -> None
self
.
portal
.
portal_workflow
.
refreshWorklistCache
()
self
.
portal
.
portal_caches
.
clearAllCache
()
sm
=
getSecurityManager
()
...
...
@@ -283,6 +297,7 @@ class SecurityTestCase(ERP5TypeTestCase):
# Simple check for an user Role
def
failIfUserHaveRoleOnDocument
(
self
,
username
,
role
,
document
):
# type: (str, str, Base) -> None
"""Fails if the user have the role on the document."""
sm
=
getSecurityManager
()
try
:
...
...
@@ -294,9 +309,10 @@ class SecurityTestCase(ERP5TypeTestCase):
finally
:
setSecurityManager
(
sm
)
assertUserDoesNotHaveRoleOnDocument
=
failIfUserHaveRoleOnDocument
assertUserDoesNotHaveRoleOnDocument
=
failIfUserHaveRoleOnDocument
# type: Callable[[SecurityTestCase, str, str, Base], None]
def
failUnlessUserHaveRoleOnDocument
(
self
,
username
,
role
,
document
):
# type: (str, str, Base) -> None
"""Fails if the user does not have the role on the document."""
sm
=
getSecurityManager
()
try
:
...
...
@@ -310,5 +326,4 @@ class SecurityTestCase(ERP5TypeTestCase):
finally
:
setSecurityManager
(
sm
)
assertUserHaveRoleOnDocument
=
failUnlessUserHaveRoleOnDocument
assertUserHaveRoleOnDocument
=
failUnlessUserHaveRoleOnDocument
# type: Callable[[SecurityTestCase, str, str, Base], None]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment