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
Ekaterina
erp5
Commits
9f8885b3
Commit
9f8885b3
authored
May 27, 2020
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SecurityTestCase: type annotations
parent
ccbb9ec2
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 @
9f8885b3
...
@@ -51,10 +51,15 @@ def formatNameUnion(names):
...
@@ -51,10 +51,15 @@ def formatNameUnion(names):
Guard
.
formatNameUnion
=
formatNameUnion
Guard
.
formatNameUnion
=
formatNameUnion
from
Products.ERP5Type.Base
import
Base
from
typing
import
Callable
class
AssertPermissionMethod
(
object
):
class
AssertPermissionMethod
(
object
):
"""A method object to check that a user have a permission on a document.
"""A method object to check that a user have a permission on a document.
"""
"""
def
__init__
(
self
,
permission_name
):
def
__init__
(
self
,
permission_name
):
# type: (str) -> None
self
.
_permission_name
=
permission_name
self
.
_permission_name
=
permission_name
def
__get__
(
self
,
instance
,
cls
=
None
):
def
__get__
(
self
,
instance
,
cls
=
None
):
...
@@ -62,6 +67,7 @@ class AssertPermissionMethod(object):
...
@@ -62,6 +67,7 @@ class AssertPermissionMethod(object):
return
self
return
self
def
__call__
(
self
,
username
,
document
):
def
__call__
(
self
,
username
,
document
):
# type: (str, Base) -> None
sm
=
getSecurityManager
()
sm
=
getSecurityManager
()
try
:
try
:
self
.
_instance
.
_loginAsUser
(
username
)
self
.
_instance
.
_loginAsUser
(
username
)
...
@@ -90,6 +96,7 @@ class AssertNoPermissionMethod(object):
...
@@ -90,6 +96,7 @@ class AssertNoPermissionMethod(object):
document.
document.
"""
"""
def
__init__
(
self
,
permission_name
):
def
__init__
(
self
,
permission_name
):
# type: (str) -> None
self
.
_permission_name
=
permission_name
self
.
_permission_name
=
permission_name
def
__get__
(
self
,
instance
,
cls
=
None
):
def
__get__
(
self
,
instance
,
cls
=
None
):
...
@@ -97,6 +104,7 @@ class AssertNoPermissionMethod(object):
...
@@ -97,6 +104,7 @@ class AssertNoPermissionMethod(object):
return
self
return
self
def
__call__
(
self
,
username
,
document
):
def
__call__
(
self
,
username
,
document
):
# type: (str, Base) -> None
sm
=
getSecurityManager
()
sm
=
getSecurityManager
()
try
:
try
:
self
.
_instance
.
_loginAsUser
(
username
)
self
.
_instance
.
_loginAsUser
(
username
)
...
@@ -141,19 +149,20 @@ class SecurityTestCase(ERP5TypeTestCase):
...
@@ -141,19 +149,20 @@ class SecurityTestCase(ERP5TypeTestCase):
# Permission methods
# Permission methods
failIfUserCanViewDocument
=
assertUserCanNotViewDocument
=
AssertNoPermissionMethod
(
failIfUserCanViewDocument
=
assertUserCanNotViewDocument
=
AssertNoPermissionMethod
(
Permissions
.
View
)
Permissions
.
View
)
# type: Callable[[SecurityTestCase, str, Base], None]
failIfUserCanAccessDocument
=
assertUserCanNotAccessDocument
=
AssertNoPermissionMethod
(
failIfUserCanAccessDocument
=
assertUserCanNotAccessDocument
=
AssertNoPermissionMethod
(
Permissions
.
AccessContentsInformation
)
Permissions
.
AccessContentsInformation
)
# type: Callable[[SecurityTestCase, str, Base], None]
failIfUserCanModifyDocument
=
assertUserCanNotModifyDocument
=
AssertNoPermissionMethod
(
failIfUserCanModifyDocument
=
assertUserCanNotModifyDocument
=
AssertNoPermissionMethod
(
Permissions
.
ModifyPortalContent
)
Permissions
.
ModifyPortalContent
)
# type: Callable[[SecurityTestCase, str, Base], None]
failIfUserCanAddDocument
=
assertUserCanNotAddDocument
=
AssertNoPermissionMethod
(
failIfUserCanAddDocument
=
assertUserCanNotAddDocument
=
AssertNoPermissionMethod
(
Permissions
.
AddPortalContent
)
Permissions
.
AddPortalContent
)
# type: Callable[[SecurityTestCase, str, Base], None]
failIfUserCanChangeLocalRoles
=
assertUserCanNotChangeLocalRoles
=
AssertNoPermissionMethod
(
failIfUserCanChangeLocalRoles
=
assertUserCanNotChangeLocalRoles
=
AssertNoPermissionMethod
(
Permissions
.
ChangeLocalRoles
)
Permissions
.
ChangeLocalRoles
)
# type: Callable[[SecurityTestCase, str, Base], None]
failIfUserCanDeleteDocument
=
assertUserCanNotDeleteDocument
=
AssertNoPermissionMethod
(
failIfUserCanDeleteDocument
=
assertUserCanNotDeleteDocument
=
AssertNoPermissionMethod
(
Permissions
.
DeleteObjects
)
Permissions
.
DeleteObjects
)
# type: Callable[[SecurityTestCase, str, Base], None]
def
failIfUserHavePermissionOnDocument
(
self
,
permission_name
,
username
,
document
):
def
failIfUserHavePermissionOnDocument
(
self
,
permission_name
,
username
,
document
):
# type: (str, str, Base) -> None
"""Fail If the user have a permission on document.
"""Fail If the user have a permission on document.
XXX why isn't it a method object ?
XXX why isn't it a method object ?
"""
"""
...
@@ -162,19 +171,20 @@ class SecurityTestCase(ERP5TypeTestCase):
...
@@ -162,19 +171,20 @@ class SecurityTestCase(ERP5TypeTestCase):
return
method
(
username
,
document
)
return
method
(
username
,
document
)
failUnlessUserCanViewDocument
=
assertUserCanViewDocument
=
\
failUnlessUserCanViewDocument
=
assertUserCanViewDocument
=
\
AssertPermissionMethod
(
Permissions
.
View
)
AssertPermissionMethod
(
Permissions
.
View
)
# type: Callable[[SecurityTestCase, str, Base], None]
failUnlessUserCanAccessDocument
=
assertUserCanAccessDocument
=
\
failUnlessUserCanAccessDocument
=
assertUserCanAccessDocument
=
\
AssertPermissionMethod
(
Permissions
.
AccessContentsInformation
)
AssertPermissionMethod
(
Permissions
.
AccessContentsInformation
)
# type: Callable[[SecurityTestCase, str, Base], None]
failUnlessUserCanModifyDocument
=
assertUserCanModifyDocument
=
\
failUnlessUserCanModifyDocument
=
assertUserCanModifyDocument
=
\
AssertPermissionMethod
(
Permissions
.
ModifyPortalContent
)
AssertPermissionMethod
(
Permissions
.
ModifyPortalContent
)
# type: Callable[[SecurityTestCase, str, Base], None]
failUnlessUserCanAddDocument
=
assertUserCanAddDocument
=
\
failUnlessUserCanAddDocument
=
assertUserCanAddDocument
=
\
AssertPermissionMethod
(
Permissions
.
AddPortalContent
)
AssertPermissionMethod
(
Permissions
.
AddPortalContent
)
# type: Callable[[SecurityTestCase, str, Base], None]
failUnlessUserCanChangeLocalRoles
=
assertUserCanChangeLocalRoles
=
\
failUnlessUserCanChangeLocalRoles
=
assertUserCanChangeLocalRoles
=
\
AssertPermissionMethod
(
Permissions
.
ChangeLocalRoles
)
AssertPermissionMethod
(
Permissions
.
ChangeLocalRoles
)
# type: Callable[[SecurityTestCase, str, Base], None]
failUnlessUserCanDeleteDocument
=
assertUserCanDeleteDocument
=
\
failUnlessUserCanDeleteDocument
=
assertUserCanDeleteDocument
=
\
AssertPermissionMethod
(
Permissions
.
DeleteObjects
)
AssertPermissionMethod
(
Permissions
.
DeleteObjects
)
# type: Callable[[SecurityTestCase, str, Base], None]
def
failUnlessUserHavePermissionOnDocument
(
self
,
permission_name
,
username
,
document
):
def
failUnlessUserHavePermissionOnDocument
(
self
,
permission_name
,
username
,
document
):
# type: (str, str, Base) -> None
"""Fail Unless the user have a permission on document."""
"""Fail Unless the user have a permission on document."""
method
=
AssertPermissionMethod
(
permission_name
)
method
=
AssertPermissionMethod
(
permission_name
)
method
.
_instance
=
self
method
.
_instance
=
self
...
@@ -183,6 +193,7 @@ class SecurityTestCase(ERP5TypeTestCase):
...
@@ -183,6 +193,7 @@ class SecurityTestCase(ERP5TypeTestCase):
# Workflow Transition Methods
# Workflow Transition Methods
def
failIfUserCanPassWorkflowTransition
(
self
,
username
,
transition
,
document
):
def
failIfUserCanPassWorkflowTransition
(
self
,
username
,
transition
,
document
):
# type: (str, str, Base) -> None
"""Fails if the user can pass the workflow transition on the document."""
"""Fails if the user can pass the workflow transition on the document."""
sm
=
getSecurityManager
()
sm
=
getSecurityManager
()
try
:
try
:
...
@@ -198,10 +209,11 @@ class SecurityTestCase(ERP5TypeTestCase):
...
@@ -198,10 +209,11 @@ class SecurityTestCase(ERP5TypeTestCase):
finally
:
finally
:
setSecurityManager
(
sm
)
setSecurityManager
(
sm
)
assertUserCanNotPassWorkflowTransition
=
failIfUserCanPassWorkflowTransition
assertUserCanNotPassWorkflowTransition
=
failIfUserCanPassWorkflowTransition
# type: Callable[[SecurityTestCase, str, str, Base], None]
def
failUnlessUserCanPassWorkflowTransition
(
self
,
username
,
def
failUnlessUserCanPassWorkflowTransition
(
self
,
username
,
transition
,
document
):
transition
,
document
):
# type: (str, str, Base) -> None
"""Fails unless the user can pass the workflow transition on the document."""
"""Fails unless the user can pass the workflow transition on the document."""
sm
=
getSecurityManager
()
sm
=
getSecurityManager
()
try
:
try
:
...
@@ -244,9 +256,10 @@ class SecurityTestCase(ERP5TypeTestCase):
...
@@ -244,9 +256,10 @@ class SecurityTestCase(ERP5TypeTestCase):
finally
:
finally
:
setSecurityManager
(
sm
)
setSecurityManager
(
sm
)
assertUserCanPassWorkflowTransition
=
failUnlessUserCanPassWorkflowTransition
assertUserCanPassWorkflowTransition
=
failUnlessUserCanPassWorkflowTransition
# type: Callable[[SecurityTestCase, str, str, Base], None]
def
assertUserHasWorklist
(
self
,
username
,
worklist_id
,
document_count
):
def
assertUserHasWorklist
(
self
,
username
,
worklist_id
,
document_count
):
# type: (str, str, int) -> None
self
.
portal
.
portal_workflow
.
refreshWorklistCache
()
self
.
portal
.
portal_workflow
.
refreshWorklistCache
()
self
.
portal
.
portal_caches
.
clearAllCache
()
self
.
portal
.
portal_caches
.
clearAllCache
()
sm
=
getSecurityManager
()
sm
=
getSecurityManager
()
...
@@ -268,6 +281,7 @@ class SecurityTestCase(ERP5TypeTestCase):
...
@@ -268,6 +281,7 @@ class SecurityTestCase(ERP5TypeTestCase):
setSecurityManager
(
sm
)
setSecurityManager
(
sm
)
def
assertUserHasNoWorklist
(
self
,
username
,
worklist_id
):
def
assertUserHasNoWorklist
(
self
,
username
,
worklist_id
):
# type: (str, str) -> None
self
.
portal
.
portal_workflow
.
refreshWorklistCache
()
self
.
portal
.
portal_workflow
.
refreshWorklistCache
()
self
.
portal
.
portal_caches
.
clearAllCache
()
self
.
portal
.
portal_caches
.
clearAllCache
()
sm
=
getSecurityManager
()
sm
=
getSecurityManager
()
...
@@ -283,6 +297,7 @@ class SecurityTestCase(ERP5TypeTestCase):
...
@@ -283,6 +297,7 @@ class SecurityTestCase(ERP5TypeTestCase):
# Simple check for an user Role
# Simple check for an user Role
def
failIfUserHaveRoleOnDocument
(
self
,
username
,
role
,
document
):
def
failIfUserHaveRoleOnDocument
(
self
,
username
,
role
,
document
):
# type: (str, str, Base) -> None
"""Fails if the user have the role on the document."""
"""Fails if the user have the role on the document."""
sm
=
getSecurityManager
()
sm
=
getSecurityManager
()
try
:
try
:
...
@@ -294,9 +309,10 @@ class SecurityTestCase(ERP5TypeTestCase):
...
@@ -294,9 +309,10 @@ class SecurityTestCase(ERP5TypeTestCase):
finally
:
finally
:
setSecurityManager
(
sm
)
setSecurityManager
(
sm
)
assertUserDoesNotHaveRoleOnDocument
=
failIfUserHaveRoleOnDocument
assertUserDoesNotHaveRoleOnDocument
=
failIfUserHaveRoleOnDocument
# type: Callable[[SecurityTestCase, str, str, Base], None]
def
failUnlessUserHaveRoleOnDocument
(
self
,
username
,
role
,
document
):
def
failUnlessUserHaveRoleOnDocument
(
self
,
username
,
role
,
document
):
# type: (str, str, Base) -> None
"""Fails if the user does not have the role on the document."""
"""Fails if the user does not have the role on the document."""
sm
=
getSecurityManager
()
sm
=
getSecurityManager
()
try
:
try
:
...
@@ -310,5 +326,4 @@ class SecurityTestCase(ERP5TypeTestCase):
...
@@ -310,5 +326,4 @@ class SecurityTestCase(ERP5TypeTestCase):
finally
:
finally
:
setSecurityManager
(
sm
)
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