Commit b1628009 authored by Julien Muchembled's avatar Julien Muchembled Committed by Klaus Wölfel

Make ERP5TypeTestCase.publish() usable in live tests

A change that also applies to traditional tests is that the password does not
need to be known when logging with basic authentication. If the given password
is empty (e.g. 'ERP5TypeTestCase:'), password validation passes regardless the
actual password: to keep things secure, this exception is only valid for the
test thread and during the call to publish(). This is a simple way to deal with
random passwords in live tests.
parent cffe35e1
...@@ -164,6 +164,15 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin): ...@@ -164,6 +164,15 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin):
''' '''
pass pass
def publish(self, *args, **kw):
from zope.security.management import thread_local
interaction = thread_local.interaction
try:
del thread_local.interaction
return super(ERP5TypeLiveTestCase, self).publish(*args, **kw)
finally:
thread_local.interaction = interaction
from Products.ERP5Type.dynamic.component_package import ComponentDynamicPackage from Products.ERP5Type.dynamic.component_package import ComponentDynamicPackage
from Products.ERP5Type.tests.runUnitTest import ERP5TypeTestLoader from Products.ERP5Type.tests.runUnitTest import ERP5TypeTestLoader
......
...@@ -665,7 +665,15 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase): ...@@ -665,7 +665,15 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
raise TypeError, '' raise TypeError, ''
if basic: if basic:
env['HTTP_AUTHORIZATION'] = "Basic %s" % base64.encodestring(basic).replace('\012', '') env['HTTP_AUTHORIZATION'] = "Basic %s" % \
base64.encodestring(basic).replace('\n', '')
from AccessControl import AuthEncoding
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))
if stdin is None: if stdin is None:
stdin = StringIO() stdin = StringIO()
...@@ -673,6 +681,9 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase): ...@@ -673,6 +681,9 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
outstream = StringIO() outstream = StringIO()
response = Response(stdout=outstream, stderr=sys.stderr) response = Response(stdout=outstream, stderr=sys.stderr)
try:
if basic:
AuthEncoding.pw_validate = pw_validate
publish_module('Zope2', publish_module('Zope2',
response=response, response=response,
stdin=stdin, stdin=stdin,
...@@ -680,7 +691,9 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase): ...@@ -680,7 +691,9 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase):
extra=extra, extra=extra,
debug=not handle_errors, debug=not handle_errors,
) )
finally:
if basic:
AuthEncoding.pw_validate = orig_pw_validate
# 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