From 9f0fa9a98d00eeaca61187b53ae151d8d0e4edcd Mon Sep 17 00:00:00 2001 From: David Glick Date: Tue, 31 Jan 2017 15:55:07 +0100 Subject: [PATCH] Make the WSGI publisher support the test browser's handleErrors = False option to raise exceptions rather than rendering a response. Also make the repr of the Unauthorized exception raised by the WSGI publisher backwards-compatible. --- CHANGES.rst | 5 +++++ src/ZPublisher/HTTPResponse.py | 5 +++-- src/ZPublisher/WSGIPublisher.py | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 7cc0eb255b..5a6d5b1935 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -20,6 +20,11 @@ Bugs Fixed - Don't copy items the user is not allowed to view. From Products.PloneHotfix20161129. [maurits] +- Don't render exception views when WSGI publisher is called + by the test browser (when 'wsgi.handleErrors' in the request + environ is False). This makes it behave more similarly + to the ZServer publisher for compatibility with existing tests. [davisagli] + Features Added ++++++++++++++ diff --git a/src/ZPublisher/HTTPResponse.py b/src/ZPublisher/HTTPResponse.py index 9867871dec..91487b6258 100644 --- a/src/ZPublisher/HTTPResponse.py +++ b/src/ZPublisher/HTTPResponse.py @@ -1007,8 +1007,9 @@ def _unauthorized(self, exc=None): 'basic realm="%s"' % self.realm, 1) def unauthorized(self): - exc = Unauthorized() - exc.title = 'You are not authorized to access this resource.' + message = 'You are not authorized to access this resource.' + exc = Unauthorized(message) + exc.title = message if self.debug_mode: if self._auth: exc.detail = 'Username and password are not correct.' diff --git a/src/ZPublisher/WSGIPublisher.py b/src/ZPublisher/WSGIPublisher.py index ffeda09a96..5ae3ac1d71 100644 --- a/src/ZPublisher/WSGIPublisher.py +++ b/src/ZPublisher/WSGIPublisher.py @@ -169,6 +169,9 @@ def _publish_response(request, response, module_info, _publish=publish): with transaction_pubevents(request): response = _publish(request, module_info) except Exception as exc: + if not request.environ.get('wsgi.handleErrors', True): + raise + if isinstance(exc, HTTPRedirection): response._redirect(exc) elif isinstance(exc, Unauthorized):