Merge "Fail on disabled_reasons with more than 255 chars"
This commit is contained in:
commit
7341c71120
@ -98,8 +98,8 @@ class ServiceController(wsgi.Controller):
|
|||||||
if not reason:
|
if not reason:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
utils.check_string_length(reason.strip(), 'Disabled reason',
|
utils.check_string_length(reason, 'Disabled reason', min_length=1,
|
||||||
min_length=1, max_length=255)
|
max_length=255, allow_all_spaces=False)
|
||||||
except exception.InvalidInput:
|
except exception.InvalidInput:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -653,10 +653,14 @@ class ServicesTest(test.TestCase):
|
|||||||
req, "disable-log-reason", body)
|
req, "disable-log-reason", body)
|
||||||
|
|
||||||
def test_invalid_reason_field(self):
|
def test_invalid_reason_field(self):
|
||||||
reason = ' '
|
# Check that empty strings are not allowed
|
||||||
|
reason = ' ' * 10
|
||||||
self.assertFalse(self.controller._is_valid_as_reason(reason))
|
self.assertFalse(self.controller._is_valid_as_reason(reason))
|
||||||
reason = 'a' * 256
|
reason = 'a' * 256
|
||||||
self.assertFalse(self.controller._is_valid_as_reason(reason))
|
self.assertFalse(self.controller._is_valid_as_reason(reason))
|
||||||
|
# Check that spaces at the end are also counted
|
||||||
|
reason = 'a' * 255 + ' '
|
||||||
|
self.assertFalse(self.controller._is_valid_as_reason(reason))
|
||||||
reason = 'it\'s a valid reason.'
|
reason = 'it\'s a valid reason.'
|
||||||
self.assertTrue(self.controller._is_valid_as_reason(reason))
|
self.assertTrue(self.controller._is_valid_as_reason(reason))
|
||||||
reason = None
|
reason = None
|
||||||
|
@ -625,7 +625,8 @@ def get_blkdev_major_minor(path, lookup_for_file=True):
|
|||||||
raise exception.Error(msg)
|
raise exception.Error(msg)
|
||||||
|
|
||||||
|
|
||||||
def check_string_length(value, name, min_length=0, max_length=None):
|
def check_string_length(value, name, min_length=0, max_length=None,
|
||||||
|
allow_all_spaces=True):
|
||||||
"""Check the length of specified string.
|
"""Check the length of specified string.
|
||||||
|
|
||||||
:param value: the value of the string
|
:param value: the value of the string
|
||||||
@ -640,6 +641,11 @@ def check_string_length(value, name, min_length=0, max_length=None):
|
|||||||
except(ValueError, TypeError) as exc:
|
except(ValueError, TypeError) as exc:
|
||||||
raise exception.InvalidInput(reason=exc)
|
raise exception.InvalidInput(reason=exc)
|
||||||
|
|
||||||
|
if not allow_all_spaces and str.isspace(value):
|
||||||
|
msg = _('%(name)s cannot be all spaces.')
|
||||||
|
raise exception.InvalidInput(reason=msg)
|
||||||
|
|
||||||
|
|
||||||
_visible_admin_metadata_keys = ['readonly', 'attached_mode']
|
_visible_admin_metadata_keys = ['readonly', 'attached_mode']
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user