Fix a limit validation to be in integer range
Python's built-in int() function creates a long instance value when the string expresses more than the integer range. To validate something like the limit parameter correctly, swift3 should the type of the return value from int() built-in function. Change-Id: I5853cf392faa77e3ee652f3dc799b63f9400141a
This commit is contained in:
@@ -663,6 +663,10 @@ class Request(swob.Request):
|
||||
raise InvalidArgument(param,
|
||||
self.params[param],
|
||||
err_msg)
|
||||
if not isinstance(value, int):
|
||||
# check the instance because int() could build
|
||||
# a long instance
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
err_msg = 'Provided %s not an integer or within ' \
|
||||
'integer range' % param
|
||||
|
||||
@@ -179,6 +179,13 @@ class TestRequest(Swift3TestCase):
|
||||
with self.assertRaises(InvalidArgument):
|
||||
s3req.get_validated_param('max-keys', 0, 0)
|
||||
|
||||
# a param in the out of the integer range
|
||||
s3req = create_s3request_with_param('max-keys', '1' * 30)
|
||||
with self.assertRaises(InvalidArgument) as result:
|
||||
s3req.get_validated_param('max-keys', 1)
|
||||
self.assertTrue(
|
||||
'not an integer or within integer range' in result.exception.body)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user