Merge "Reject negative volume size in API"

This commit is contained in:
Jenkins
2015-03-27 10:55:43 +00:00
committed by Gerrit Code Review
3 changed files with 23 additions and 10 deletions

View File

@@ -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 = {

View File

@@ -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):

View File

@@ -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)