Skip to content

Commit

Permalink
Make the WSGI publisher support the test browser's handleErrors = Fal…
Browse files Browse the repository at this point in the history
…se option

to raise exceptions rather than rendering a response.

Also make the repr of the Unauthorized exception raised by the WSGI publisher
backwards-compatible.
  • Loading branch information
davisagli committed Jan 31, 2017
1 parent e9a418e commit 9f0fa9a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Expand Up @@ -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
++++++++++++++

Expand Down
5 changes: 3 additions & 2 deletions src/ZPublisher/HTTPResponse.py
Expand Up @@ -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.'
Expand Down
3 changes: 3 additions & 0 deletions src/ZPublisher/WSGIPublisher.py
Expand Up @@ -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):
Expand Down

0 comments on commit 9f0fa9a

Please sign in to comment.