From 2e85dc47c9301b00f89bd44955534f8d9631e3d6 Mon Sep 17 00:00:00 2001 From: Vishakha Agarwal Date: Wed, 17 Oct 2018 16:43:15 +0530 Subject: [PATCH] Set min and max length for resource_name This patch addresses the problem of HTTP 500 on create and set of limit with lengthy resource_name. It sets the minLength and maxLength in schema for resource_name and if the string length of resource_ name exceeds the defined schema it will raise 404. Includes test case too. Change-Id: If408e81edec81c649c42bd4907156fbcdbc967ee Closes-Bug: #1798495 --- keystone/limit/schema.py | 8 ++++++-- keystone/tests/unit/test_validation.py | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/keystone/limit/schema.py b/keystone/limit/schema.py index 99c795a80c..8fa68af1a5 100644 --- a/keystone/limit/schema.py +++ b/keystone/limit/schema.py @@ -21,7 +21,9 @@ _registered_limit_properties = { 'type': 'string' }, 'resource_name': { - 'type': 'string' + 'type': 'string', + 'minLength': 1, + 'maxLength': 255 }, 'default_limit': { 'type': 'integer' @@ -54,7 +56,9 @@ _limit_create_properties = { 'type': 'string' }, 'resource_name': { - 'type': 'string' + 'type': 'string', + 'minLength': 1, + 'maxLength': 255 }, 'resource_limit': { 'type': 'integer' diff --git a/keystone/tests/unit/test_validation.py b/keystone/tests/unit/test_validation.py index 800d0ab7d2..6b4ada1e04 100644 --- a/keystone/tests/unit/test_validation.py +++ b/keystone/tests/unit/test_validation.py @@ -2560,6 +2560,8 @@ class LimitValidationTestCase(unit.BaseTestCase): _INVALID_FORMATS = [{'service_id': 'fake_id'}, {'region_id': 123}, {'resource_name': 123}, + {'resource_name': ''}, + {'resource_name': 'a' * 256}, {'default_limit': 'not_int'}, {'description': 123}, {'description': True}] @@ -2579,6 +2581,8 @@ class LimitValidationTestCase(unit.BaseTestCase): _INVALID_FORMATS = [{'service_id': 'fake_id'}, {'region_id': 123}, {'resource_name': 123}, + {'resource_name': ''}, + {'resource_name': 'a' * 256}, {'default_limit': 'not_int'}, {'description': 123}] for invalid_desc in _INVALID_FORMATS: @@ -2661,6 +2665,8 @@ class LimitValidationTestCase(unit.BaseTestCase): {'service_id': 'fake_id'}, {'region_id': 123}, {'resource_name': 123}, + {'resource_name': ''}, + {'resource_name': 'a' * 256}, {'resource_limit': 'not_int'}, {'description': 123}] for invalid_desc in _INVALID_FORMATS: