Merge "Test tag against schema to check length"
This commit is contained in:
@@ -18,6 +18,7 @@ from oslo_utils import encodeutils
|
|||||||
import webob.exc
|
import webob.exc
|
||||||
|
|
||||||
from glance.api import policy
|
from glance.api import policy
|
||||||
|
from glance.api.v2 import images as v2_api
|
||||||
from glance.common import exception
|
from glance.common import exception
|
||||||
from glance.common import utils
|
from glance.common import utils
|
||||||
from glance.common import wsgi
|
from glance.common import wsgi
|
||||||
@@ -94,8 +95,20 @@ class ResponseSerializer(wsgi.JSONResponseSerializer):
|
|||||||
response.status_int = 204
|
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():
|
def create_resource():
|
||||||
"""Images resource factory method"""
|
"""Images resource factory method"""
|
||||||
serializer = ResponseSerializer()
|
serializer = ResponseSerializer()
|
||||||
|
deserializer = RequestDeserializer()
|
||||||
controller = Controller()
|
controller = Controller()
|
||||||
return wsgi.Resource(controller, serializer=serializer)
|
return wsgi.Resource(controller, deserializer, serializer)
|
||||||
|
|||||||
@@ -2558,6 +2558,19 @@ class TestImages(functional.FunctionalTest):
|
|||||||
images = jsonutils.loads(response.text)['images']
|
images = jsonutils.loads(response.text)['images']
|
||||||
self.assertEqual(0, len(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()
|
self.stop_servers()
|
||||||
|
|
||||||
def test_images_container(self):
|
def test_images_container(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user