Commit 99de00d9 authored by Rafael Monnerat's avatar Rafael Monnerat

Make possible test Security for Anonymous

 With this change, by using "None" instead username at any SecurityTestCase
 assertion, it test security as Anonymous. ie.:
   self.failIfUserCanViewDocument(None, document)
parent 8cece721
...@@ -33,6 +33,7 @@ from pprint import pformat ...@@ -33,6 +33,7 @@ from pprint import pformat
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import getSecurityManager from AccessControl.SecurityManagement import getSecurityManager
from AccessControl.SecurityManagement import setSecurityManager from AccessControl.SecurityManagement import setSecurityManager
from AccessControl import SpecialUsers
from Products.DCWorkflow.Transitions import TRIGGER_USER_ACTION from Products.DCWorkflow.Transitions import TRIGGER_USER_ACTION
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
...@@ -128,11 +129,15 @@ class SecurityTestCase(ERP5TypeTestCase): ...@@ -128,11 +129,15 @@ class SecurityTestCase(ERP5TypeTestCase):
def _loginAsUser(self, username): def _loginAsUser(self, username):
"""Login as a given username. The user must exist. """Login as a given username. The user must exist.
In case Username is None, we consider test as Anonymous.
""" """
uf = self.getPortal().acl_users if username is None:
user = uf.getUserById(username) newSecurityManager(None, SpecialUsers.nobody)
self.assertNotEquals(user, None, 'No user %s' % username) else:
newSecurityManager(None, user.__of__(uf)) uf = self.getPortal().acl_users
user = uf.getUserById(username)
self.assertNotEquals(user, None, 'No user %s' % username)
newSecurityManager(None, user.__of__(uf))
# Permission methods # Permission methods
failIfUserCanViewDocument = AssertNoPermissionMethod( failIfUserCanViewDocument = AssertNoPermissionMethod(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment