Merge "Test tag against schema to check length"

This commit is contained in:
Jenkins
2016-03-10 23:14:06 +00:00
committed by Gerrit Code Review
2 changed files with 27 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ from oslo_utils import encodeutils
import webob.exc
from glance.api import policy
from glance.api.v2 import images as v2_api
from glance.common import exception
from glance.common import utils
from glance.common import wsgi
@@ -94,8 +95,20 @@ class ResponseSerializer(wsgi.JSONResponseSerializer):
response.status_int = 204
class RequestDeserializer(wsgi.JSONRequestDeserializer):
def update(self, request):
try:
schema = v2_api.get_schema()
schema_format = {"tags": [request.urlvars.get('tag_value')]}
schema.validate(schema_format)
except exception.InvalidObject as e:
raise webob.exc.HTTPBadRequest(explanation=e.msg)
return super(RequestDeserializer, self).default(request)
def create_resource():
"""Images resource factory method"""
serializer = ResponseSerializer()
deserializer = RequestDeserializer()
controller = Controller()
return wsgi.Resource(controller, serializer=serializer)
return wsgi.Resource(controller, deserializer, serializer)

View File

@@ -2558,6 +2558,19 @@ class TestImages(functional.FunctionalTest):
images = jsonutils.loads(response.text)['images']
self.assertEqual(0, len(images))
# Try to add a tag that is too long
big_tag = 'a' * 300
path = self._url('/v2/images/%s/tags/%s' % (image_id, big_tag))
response = requests.put(path, headers=self._headers())
self.assertEqual(400, response.status_code)
# Tags should not have changed since request was over limit
path = self._url('/v2/images/%s' % image_id)
response = requests.get(path, headers=self._headers())
self.assertEqual(200, response.status_code)
tags = jsonutils.loads(response.text)['tags']
self.assertEqual(['sniff', 'snozz'], sorted(tags))
self.stop_servers()
def test_images_container(self):