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):
Create a simple user in user_folder with manager rights.
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')
def createERP5Users(self, user_dict):
......@@ -215,7 +216,8 @@ class TestWorklist(ERP5TypeTestCase):
self.assertTrue(url, 'Can not check url parameters without url')
url = '%s%s' % (self.portal.getId(), url[len(self.portal.absolute_url()):])
# 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(
self.module_selection_name)
for parameter, value in url_parameter_dict.iteritems():
......
......@@ -681,7 +681,7 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
ZopeTestCase._print('\n%s ' % 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):
'''Publishes the object at 'path' returning a response object.'''
......@@ -718,15 +718,19 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
raise TypeError, ''
if basic:
assert not user, (basic, user)
env['HTTP_AUTHORIZATION'] = "Basic %s" % \
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
me = get_ident()
orig_pw_validate = AuthEncoding.pw_validate
def pw_validate(reference, password):
return (me == get_ident() and not password
or pw_validate(reference, password))
def _extractUserIds(pas, request, plugins):
if me == get_ident():
info = pas._verifyUser(plugins, user)
return [(info['id'], info['login'])] if info else ()
return orig_extractUserIds(pas, request, plugins)
if stdin is None:
stdin = StringIO()
......@@ -735,8 +739,8 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
response = Response(stdout=outstream, stderr=sys.stderr)
try:
if basic:
AuthEncoding.pw_validate = pw_validate
if user:
PAS._extractUserIds = _extractUserIds
publish_module('Zope2',
response=response,
stdin=stdin,
......@@ -745,8 +749,8 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
debug=not handle_errors,
)
finally:
if basic:
AuthEncoding.pw_validate = orig_pw_validate
if user:
PAS._extractUserIds = orig_extractUserIds
# Restore security manager
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