Merge "Reject negative volume size in API"
This commit is contained in:
@@ -49,6 +49,13 @@ configuration_integer_size = {
|
||||
"pattern": "[0-9]+"
|
||||
}
|
||||
|
||||
configuration_positive_integer = {
|
||||
"type": "string",
|
||||
"maxLength": 40,
|
||||
"minLength": 1,
|
||||
"pattern": "^[0-9]+$"
|
||||
}
|
||||
|
||||
configuration_non_empty_string = {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
@@ -70,11 +77,7 @@ volume_size = {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"pattern": "[0-9]+"
|
||||
}]
|
||||
configuration_positive_integer]
|
||||
}
|
||||
|
||||
host_string = {
|
||||
|
||||
@@ -165,7 +165,7 @@ class MalformedJson(object):
|
||||
"resize['volume']['size'] %s is not valid under "
|
||||
"any of the given schemas" % data,
|
||||
"%s is not of type 'integer'" % data,
|
||||
"%s does not match '[0-9]+'" % data])
|
||||
"%s does not match '^[0-9]+$'" % data])
|
||||
|
||||
@test
|
||||
def test_bad_change_user_password(self):
|
||||
|
||||
@@ -166,12 +166,22 @@ class TestInstanceController(TestCase):
|
||||
self.assertTrue(validator.is_valid(body))
|
||||
|
||||
def test_validate_resize_volume_string(self):
|
||||
body = {"resize": {"volume": {"size": '-44.0'}}}
|
||||
body = {"resize": {"volume": {"size": "4"}}}
|
||||
schema = self.controller.get_schema('action', body)
|
||||
validator = jsonschema.Draft4Validator(schema)
|
||||
self.assertTrue(validator.is_valid(body))
|
||||
|
||||
def test_validate_resize_volume_invalid(self):
|
||||
def test_validate_resize_volume_string_invalid_number(self):
|
||||
body = {"resize": {"volume": {"size": '-44.0'}}}
|
||||
schema = self.controller.get_schema('action', body)
|
||||
validator = jsonschema.Draft4Validator(schema)
|
||||
self.assertFalse(validator.is_valid(body))
|
||||
errors = sorted(validator.iter_errors(body), key=lambda e: e.path)
|
||||
self.assertThat(errors[0].context[1].message,
|
||||
Equals("'-44.0' does not match '^[0-9]+$'"))
|
||||
self.assertThat(errors[0].path.pop(), Equals('size'))
|
||||
|
||||
def test_validate_resize_volume_invalid_characters(self):
|
||||
body = {"resize": {"volume": {"size": 'x'}}}
|
||||
schema = self.controller.get_schema('action', body)
|
||||
validator = jsonschema.Draft4Validator(schema)
|
||||
@@ -180,7 +190,7 @@ class TestInstanceController(TestCase):
|
||||
self.assertThat(errors[0].context[0].message,
|
||||
Equals("'x' is not of type 'integer'"))
|
||||
self.assertThat(errors[0].context[1].message,
|
||||
Equals("'x' does not match '[0-9]+'"))
|
||||
Equals("'x' does not match '^[0-9]+$'"))
|
||||
self.assertThat(errors[0].path.pop(), Equals('size'))
|
||||
|
||||
def test_validate_resize_instance(self):
|
||||
@@ -215,7 +225,7 @@ class TestInstanceController(TestCase):
|
||||
"flavorRef"],
|
||||
errors[0].path.pop())
|
||||
|
||||
@skip("This damn URI validator allows just about any garbage you give it")
|
||||
@skip("This URI validator allows just about anything you give it")
|
||||
def test_validate_resize_instance_invalid_url(self):
|
||||
body = {"resize": {"flavorRef": "xyz-re1f2-daze329d-f23901"}}
|
||||
schema = self.controller.get_schema('action', body)
|
||||
|
||||
Reference in New Issue
Block a user