Merge "middleware: return HTTPBadRequest when path is invalid"

This commit is contained in:
Zuul 2018-09-12 15:13:16 +00:00 committed by Gerrit Code Review
commit 062d04e685
2 changed files with 16 additions and 0 deletions

View File

@ -41,6 +41,13 @@ class VersionNegotiationFilter(wsgi.Middleware):
return the correct API controller, otherwise, if we
find an Accept: header, process it
"""
# Make sure the request path is valid UTF-8
try:
req.path
except UnicodeDecodeError:
return webob.exc.HTTPBadRequest()
# See if a version identifier is in the URI passed to
# us already. If so, simply return the right version
# API controller

View File

@ -136,3 +136,12 @@ class VersionNegotiationMiddlewareTest(common.HeatTestCase):
response = version_negotiation.process_request(request)
self.assertIsInstance(response, webob.exc.HTTPNotFound)
def test_invalid_utf8_path(self):
version_negotiation = vn.VersionNegotiationFilter(
self._version_controller_factory, None, None)
request = webob.Request.blank('/%c0')
response = version_negotiation.process_request(request)
self.assertIsInstance(response, webob.exc.HTTPBadRequest)