Skip to content

Commit

Permalink
Raise app exceptions without rendering response if wsgi.handleErrors …
Browse files Browse the repository at this point in the history
…is False
  • Loading branch information
davisagli committed Oct 15, 2017
1 parent 2e52c99 commit 48ff743
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ZPublisher/WSGIPublisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ def transaction_pubevents(request, response, tm=transaction.manager):
# Create new exc_info with the upgraded exception.
exc_info = (exc_type, exc, sys.exc_info()[2])

# Raise exception from app if handle-errors is False
# (set by zope.testbrowser in some cases)
if not request.environ.get('wsgi.handleErrors', True):
reraise(*exc_info)

if isinstance(exc, Unauthorized):
# _unauthorized modifies the response in-place. If this hook
# is used, an exception view for Unauthorized has to merge
Expand Down
11 changes: 11 additions & 0 deletions src/ZPublisher/tests/test_WSGIPublisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,17 @@ def testRedirectExceptionView(self):
headers = dict(headers)
self.assertEqual(headers['Location'], 'http://localhost:9/')

def testHandleErrorsFalseBypassesExceptionResponse(self):
from AccessControl import Unauthorized
environ = self._makeEnviron(**{
'wsgi.handleErrors': False,
})
start_response = DummyCallable()
_publish = DummyCallable()
_publish._raise = Unauthorized('argg')
with self.assertRaises(Unauthorized):
self._callFUT(environ, start_response, _publish)


class TestLoadApp(unittest.TestCase):

Expand Down

0 comments on commit 48ff743

Please sign in to comment.