Merge "Unregister "Exception" from flask handler"

This commit is contained in:
Zuul 2018-11-06 21:23:08 +00:00 committed by Gerrit Code Review
commit e54bbc1047
2 changed files with 19 additions and 3 deletions

View File

@ -140,10 +140,9 @@ def application_factory(name='public'):
app.register_error_handler(exc, _handle_keystone_exception)
# Register extra (python) exceptions with the proper exception handler,
# specifically TypeError and generic exception, these will render as
# 500 errors, but presented in a "web-ified" manner
# specifically TypeError. It will render as a 400 error, but presented in
# a "web-ified" manner
app.register_error_handler(TypeError, _handle_unknown_keystone_exception)
app.register_error_handler(Exception, _handle_unknown_keystone_exception)
# Add core before request functions
app.before_request(req_logging.log_request_info)

View File

@ -724,3 +724,20 @@ class TestKeystoneFlaskCommon(rest.RestfulTestCase):
r = TestResourceWithKey()
self.assertEqual(
TestResourceWithKey.member_key, r.member_key)
class TestKeystoneFlaskUnrouted404(rest.RestfulTestCase):
def setUp(self):
super(TestKeystoneFlaskUnrouted404, self).setUp()
# unregister the 404 handler we explicitly set in loadapp. This
# makes the 404 error fallback to a standard werkzeug handling.
self.public_app.app.error_handler_spec[None].pop(404)
def test_unrouted_path_is_not_jsonified_404(self):
with self.test_client() as c:
path = '/{unrouted_path}'.format(unrouted_path=uuid.uuid4())
resp = c.get(path, expected_status_code=404)
# Make sure we're emitting a html error
self.assertEqual('text/html', resp.headers['Content-Type'])
# Ensure the more generic flask/werkzeug 404 response is emitted
self.assertTrue(b'404 Not Found' in resp.data)