Fix 500 if custom property name is greater than 255

If user passes property 'key' greater than 255 characters
then it fails with 500 error.

Modified request deserializer to check if custom property key
is greater than 255 characters then raise HTTPBadRequest with
appropriate error message.

Change-Id: I1d24ff4812315b590675452891ab4d51e8c836a2
Closes-Bug: #1737952
This commit is contained in:
Abhishek Kekane 2017-12-26 09:45:53 +00:00
parent af7b564ac3
commit 8dba796806
2 changed files with 26 additions and 0 deletions

View File

@ -453,6 +453,15 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer):
image[key] = properties.pop(key)
except KeyError:
pass
# NOTE(abhishekk): Check if custom property key name is less than 255
# characters. Reference LP #1737952
for key in properties:
if len(key) > 255:
msg = (_("Custom property should not be greater than 255 "
"characters."))
raise webob.exc.HTTPBadRequest(explanation=msg)
return dict(image=image, extra_properties=properties, tags=tags)
def _get_change_operation_d10(self, raw_change):

View File

@ -2441,6 +2441,23 @@ class TestImagesDeserializer(test_utils.BaseTestCase):
'tags': ['one', 'two']}
self.assertEqual(expected, output)
def test_create_invalid_property_key(self):
request = unit_test_utils.get_fake_request()
request.body = jsonutils.dump_as_bytes({
'id': UUID3,
'name': 'image-1',
'visibility': 'public',
'tags': ['one', 'two'],
'container_format': 'ami',
'disk_format': 'ami',
'min_ram': 128,
'min_disk': 10,
'f' * 256: 'bar',
'protected': True,
})
self.assertRaises(webob.exc.HTTPBadRequest, self.deserializer.create,
request)
def test_create_readonly_attributes_forbidden(self):
bodies = [
{'direct_url': 'http://example.com'},