Set min and max length for resource_name

This patch addresses the problem of HTTP 500 on
create and set of limit with lengthy resource_name.
It sets the minLength and maxLength in schema for
resource_name and if the string length of resource_
name exceeds the defined schema it will raise 404.
Includes test case too.

Change-Id: If408e81edec81c649c42bd4907156fbcdbc967ee
Closes-Bug: #1798495
This commit is contained in:
Vishakha Agarwal 2018-10-17 16:43:15 +05:30
parent c43fc16f60
commit 2e85dc47c9
2 changed files with 12 additions and 2 deletions

View File

@ -21,7 +21,9 @@ _registered_limit_properties = {
'type': 'string'
},
'resource_name': {
'type': 'string'
'type': 'string',
'minLength': 1,
'maxLength': 255
},
'default_limit': {
'type': 'integer'
@ -54,7 +56,9 @@ _limit_create_properties = {
'type': 'string'
},
'resource_name': {
'type': 'string'
'type': 'string',
'minLength': 1,
'maxLength': 255
},
'resource_limit': {
'type': 'integer'

View File

@ -2560,6 +2560,8 @@ class LimitValidationTestCase(unit.BaseTestCase):
_INVALID_FORMATS = [{'service_id': 'fake_id'},
{'region_id': 123},
{'resource_name': 123},
{'resource_name': ''},
{'resource_name': 'a' * 256},
{'default_limit': 'not_int'},
{'description': 123},
{'description': True}]
@ -2579,6 +2581,8 @@ class LimitValidationTestCase(unit.BaseTestCase):
_INVALID_FORMATS = [{'service_id': 'fake_id'},
{'region_id': 123},
{'resource_name': 123},
{'resource_name': ''},
{'resource_name': 'a' * 256},
{'default_limit': 'not_int'},
{'description': 123}]
for invalid_desc in _INVALID_FORMATS:
@ -2661,6 +2665,8 @@ class LimitValidationTestCase(unit.BaseTestCase):
{'service_id': 'fake_id'},
{'region_id': 123},
{'resource_name': 123},
{'resource_name': ''},
{'resource_name': 'a' * 256},
{'resource_limit': 'not_int'},
{'description': 123}]
for invalid_desc in _INVALID_FORMATS: