Image Registry tags validation

New format 'valid_tag' was added to jsonschema and tags check to match 'valid_tag'
Added UT for this.

Fixes: bug #1200199

Change-Id: I64318b5c745074741a197a5ef1940bae900f6358
This commit is contained in:
Ilya Tyaptin 2013-07-18 17:06:07 +04:00
parent ca9c55ff03
commit 4bb456933b
3 changed files with 58 additions and 0 deletions

View File

@ -34,6 +34,7 @@ image_tags_schema = {
"type": "array",
"items": {
"type": "string",
"format": "valid_tag"
},
},
},

View File

@ -0,0 +1,49 @@
# Copyright (c) 2013 Mirantis Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from savanna.service.validations import images as im
from savanna.tests.unit.service.validation import utils as u
class TestTagsAddingValidation(u.ValidationTestCase):
def setUp(self):
self._create_object_fun = im.check_tags
self.scheme = im.image_tags_schema
def test_add_tags_validation(self):
right_tags = ['1', 'a', 'a_1', 'a.2', 'a.A', 'a-A']
wrong_tags = ['a.', '_a', 'a..a']
wrong_symbols = "!@#$%^&*,"
data = {
'tags': []
}
for tag in right_tags:
data["tags"] = [tag]
self._assert_create_object_validation(
data=data)
for tag in wrong_tags:
data["tags"] = [tag]
self._assert_create_object_validation(
data=data,
bad_req_i=(1, 'VALIDATION_ERROR',
u"'%s' is not a 'valid_tag'" % tag))
for symb in wrong_symbols:
tag = "a%sa" % symb
data['tags'] = [tag]
self._assert_create_object_validation(
data=data,
bad_req_i=(1, 'VALIDATION_ERROR',
u"'%s' is not a 'valid_tag'" % tag))

View File

@ -29,6 +29,14 @@ def validate_name_format(entry):
return res is not None
@jsonschema.FormatChecker.cls_checks('valid_tag')
def validate_valid_tag_format(entry):
res = re.match(r"^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-_]"
r"*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9]"
r"[A-Za-z0-9\-_]*[A-Za-z0-9])$", entry)
return res is not None
@jsonschema.FormatChecker.cls_checks('uuid')
def validate_uuid_format(entry):
return uuidutils.is_uuid_like(entry)