From e4a8242b96360cddbf3b5c7114e814af53aa9796 Mon Sep 17 00:00:00 2001 From: Eli Qiao Date: Wed, 27 Jul 2016 14:31:27 +0800 Subject: [PATCH] API: restrict length of bay's name to 242 Restrict the length of bay's name to avoid passing a invalid long name to heat stack. Reason of 242 is: stack_name = '%s-%s' % (bay.name, short_id.generate_id()) 255 - len(short_id.generate_id()) - 1 = 242 Closes-bug: #1606785 Change-Id: If22a9018ece718f014c40e8059b945ae1a411f5b --- magnum/api/controllers/v1/bay.py | 5 +++-- magnum/tests/unit/api/controllers/v1/test_bay.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/magnum/api/controllers/v1/bay.py b/magnum/api/controllers/v1/bay.py index 7bb1a112ee..ae42847f81 100644 --- a/magnum/api/controllers/v1/bay.py +++ b/magnum/api/controllers/v1/bay.py @@ -83,9 +83,10 @@ class Bay(base.APIBase): uuid = types.uuid """Unique UUID for this bay""" - name = wtypes.StringType(min_length=1, max_length=255, + name = wtypes.StringType(min_length=1, max_length=242, pattern='^[a-zA-Z][a-zA-Z0-9_.-]*$') - """Name of this bay""" + """Name of this bay, max length is limited to 242 because of heat stack + requires max length limit to 255, and Magnum amend a uuid length""" baymodel_id = wsme.wsproperty(wtypes.text, _get_baymodel_id, _set_baymodel_id, mandatory=True) diff --git a/magnum/tests/unit/api/controllers/v1/test_bay.py b/magnum/tests/unit/api/controllers/v1/test_bay.py index b5d9fd28f1..1f1306d7a1 100644 --- a/magnum/tests/unit/api/controllers/v1/test_bay.py +++ b/magnum/tests/unit/api/controllers/v1/test_bay.py @@ -532,7 +532,7 @@ class TestPost(api_base.FunctionalTest): self.assertEqual(1, response.json['master_count']) def test_create_bay_with_invalid_long_name(self): - bdict = apiutils.bay_post_data(name='x' * 256) + bdict = apiutils.bay_post_data(name='x' * 243) response = self.post_json('/bays', bdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_int)