Commit 6a434a4f authored by Julien Muchembled's avatar Julien Muchembled

New 'user' parameter to ERP5TypeTestCase.publish()

In commit 89a17f04, disabling password
verification when passing an empty password was a bad idea, since it
wasn't possible to check fully the login form itself. Some tests broke
because of this change.

There was also a stupid mistake: `pw_validate` could call itself
instead of the original function.
parent 19266fce
...@@ -86,7 +86,8 @@ class TestWorklist(ERP5TypeTestCase): ...@@ -86,7 +86,8 @@ class TestWorklist(ERP5TypeTestCase):
Create a simple user in user_folder with manager rights. Create a simple user in user_folder with manager rights.
This user will be used to initialize data in the method afterSetup This user will be used to initialize data in the method afterSetup
""" """
self.getUserFolder()._doAddUser('manager', '', ['Manager'], []) self.getUserFolder()._doAddUser('manager', self.newPassword(),
['Manager'], [])
self.loginByUserName('manager') self.loginByUserName('manager')
def createERP5Users(self, user_dict): def createERP5Users(self, user_dict):
...@@ -215,7 +216,8 @@ class TestWorklist(ERP5TypeTestCase): ...@@ -215,7 +216,8 @@ class TestWorklist(ERP5TypeTestCase):
self.assertTrue(url, 'Can not check url parameters without url') self.assertTrue(url, 'Can not check url parameters without url')
url = '%s%s' % (self.portal.getId(), url[len(self.portal.absolute_url()):]) url = '%s%s' % (self.portal.getId(), url[len(self.portal.absolute_url()):])
# Touch URL to save worklist parameters in listbox selection # Touch URL to save worklist parameters in listbox selection
self.publish(url, 'manager:') # XXX which user ? # XXX which user ?
self.assertEqual(200, self.publish(url, user='manager').getStatus())
selection_parameter_dict = self.portal.portal_selections.getSelectionParamsFor( selection_parameter_dict = self.portal.portal_selections.getSelectionParamsFor(
self.module_selection_name) self.module_selection_name)
for parameter, value in url_parameter_dict.iteritems(): for parameter, value in url_parameter_dict.iteritems():
......
...@@ -681,7 +681,7 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase): ...@@ -681,7 +681,7 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
ZopeTestCase._print('\n%s ' % message) ZopeTestCase._print('\n%s ' % message)
LOG('Testing ... ', DEBUG, message) LOG('Testing ... ', DEBUG, message)
def publish(self, path, basic=None, env=None, extra=None, def publish(self, path, basic=None, env=None, extra=None, user=None,
request_method='GET', stdin=None, handle_errors=True): request_method='GET', stdin=None, handle_errors=True):
'''Publishes the object at 'path' returning a response object.''' '''Publishes the object at 'path' returning a response object.'''
...@@ -718,15 +718,19 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase): ...@@ -718,15 +718,19 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
raise TypeError, '' raise TypeError, ''
if basic: if basic:
assert not user, (basic, user)
env['HTTP_AUTHORIZATION'] = "Basic %s" % \ env['HTTP_AUTHORIZATION'] = "Basic %s" % \
base64.encodestring(basic).replace('\n', '') base64.encodestring(basic).replace('\n', '')
from AccessControl import AuthEncoding elif user:
PAS = self.portal.acl_users.__class__
orig_extractUserIds = PAS._extractUserIds
from thread import get_ident from thread import get_ident
me = get_ident() me = get_ident()
orig_pw_validate = AuthEncoding.pw_validate def _extractUserIds(pas, request, plugins):
def pw_validate(reference, password): if me == get_ident():
return (me == get_ident() and not password info = pas._verifyUser(plugins, user)
or pw_validate(reference, password)) return [(info['id'], info['login'])] if info else ()
return orig_extractUserIds(pas, request, plugins)
if stdin is None: if stdin is None:
stdin = StringIO() stdin = StringIO()
...@@ -735,8 +739,8 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase): ...@@ -735,8 +739,8 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
response = Response(stdout=outstream, stderr=sys.stderr) response = Response(stdout=outstream, stderr=sys.stderr)
try: try:
if basic: if user:
AuthEncoding.pw_validate = pw_validate PAS._extractUserIds = _extractUserIds
publish_module('Zope2', publish_module('Zope2',
response=response, response=response,
stdin=stdin, stdin=stdin,
...@@ -745,8 +749,8 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase): ...@@ -745,8 +749,8 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
debug=not handle_errors, debug=not handle_errors,
) )
finally: finally:
if basic: if user:
AuthEncoding.pw_validate = orig_pw_validate PAS._extractUserIds = orig_extractUserIds
# Restore security manager # Restore security manager
setSecurityManager(sm) setSecurityManager(sm)
......
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