Limit the min length of string for integer JSON-Schema

The JSON-Schema of integer string is without min length limits. That
leads to the user can input empty string, and nova API code can't
handle that case. Finally the user will get 500 returned.

The create_backup and multi_create API are fixed. The networks and
tenant_networks API have same problem on few parameters, but due
to the nova-network is deprecated, so just keep those nova-network
specific API behaviour as before.

Change-Id: I521e914fc48b7a221431f41c567f2cb4b9b4ab99
Closes-bug: #1652719
This commit is contained in:
He Jie Xu 2016-12-27 14:27:42 +08:00 committed by Sean Dague
parent 0cd67d23bd
commit 934ccef0bd
5 changed files with 31 additions and 12 deletions

View File

@ -48,9 +48,9 @@ create = {
'allowed_end': parameter_types.ip_address,
'enable_dhcp': parameter_types.boolean,
'share_address': parameter_types.boolean,
'mtu': parameter_types.positive_integer,
'vlan': parameter_types.positive_integer,
'vlan_start': parameter_types.positive_integer,
'mtu': parameter_types.positive_integer_with_empty_str,
'vlan': parameter_types.positive_integer_with_empty_str,
'vlan_start': parameter_types.positive_integer_with_empty_str,
'vpn_start': {
'type': 'string',
},

View File

@ -26,9 +26,10 @@ create = {
'ipam': parameter_types.boolean,
'cidr': parameter_types.cidr,
'cidr_v6': parameter_types.cidr,
'vlan_start': parameter_types.positive_integer,
'network_size': parameter_types.positive_integer,
'num_networks': parameter_types.positive_integer
'vlan_start': parameter_types.positive_integer_with_empty_str,
'network_size':
parameter_types.positive_integer_with_empty_str,
'num_networks': parameter_types.positive_integer_with_empty_str
},
'required': ['label'],
'oneOf': [

View File

@ -201,15 +201,21 @@ none = {
positive_integer = {
'type': ['integer', 'string'],
'pattern': '^[0-9]*$', 'minimum': 1
'pattern': '^[0-9]*$', 'minimum': 1, 'minLength': 1
}
non_negative_integer = {
'type': ['integer', 'string'],
'pattern': '^[0-9]*$', 'minimum': 0
'pattern': '^[0-9]*$', 'minimum': 0, 'minLength': 1
}
# This only be used by nova-network specific APIs. It will be removed when
# those API removed.
positive_integer_with_empty_str = {
'type': ['integer', 'string'],
'pattern': '^[0-9]*$', 'minimum': 1,
}
hostname = {
'type': 'string', 'minLength': 1, 'maxLength': 255,

View File

@ -165,6 +165,18 @@ class CreateBackupTestsV21(admin_only_action_common.CommonMixin,
self.controller._create_backup,
self.req, fakes.FAKE_UUID, body=body)
def test_create_backup_rotation_with_empty_string(self):
body = {
'createBackup': {
'name': 'Backup 1',
'backup_type': 'daily',
'rotation': '',
},
}
self.assertRaises(self.validation_error,
self.controller._create_backup,
self.req, fakes.FAKE_UUID, body=body)
def test_create_backup_no_backup_type(self):
# Backup Type (daily or weekly) is required for backup requests.
body = {

View File

@ -185,8 +185,8 @@ class MultiCreateExtensionTestV21(test.TestCase):
'server': {
multiple_create_v21.MIN_ATTRIBUTE_NAME: '',
'name': 'server_test',
'image_ref': image_href,
'flavor_ref': flavor_ref,
'imageRef': image_href,
'flavorRef': flavor_ref,
}
}
self.assertRaises(self.validation_error,
@ -202,8 +202,8 @@ class MultiCreateExtensionTestV21(test.TestCase):
'server': {
multiple_create_v21.MAX_ATTRIBUTE_NAME: '',
'name': 'server_test',
'image_ref': image_href,
'flavor_ref': flavor_ref,
'imageRef': image_href,
'flavorRef': flavor_ref,
}
}
self.assertRaises(self.validation_error,