Validate tag name when filtering for images

Right now all invalid tags are skipped when filtering for image list. We
should change this behaviour to raise an exception when invalid tag
value is provided.

Additionally remove misplaced `pass` from one of the tests.

Closes-Bug: 1433962
Change-Id: If5148608a70ee019697ea2dcb84e19a53222d596
This commit is contained in:
Kamil Rykowski 2015-03-18 13:29:20 +01:00
parent 15c2e40449
commit 2c08b40bf0
2 changed files with 11 additions and 3 deletions

View File

@ -132,8 +132,10 @@ class Controller(object):
tags_url_params = []
for tag in tags:
if isinstance(tag, six.string_types):
tags_url_params.append({'tag': encodeutils.safe_encode(tag)})
if not isinstance(tag, six.string_types):
raise exc.HTTPBadRequest("Invalid tag value %s" % tag)
tags_url_params.append({'tag': encodeutils.safe_encode(tag)})
for param, value in six.iteritems(filters):
if isinstance(value, six.string_types):

View File

@ -631,7 +631,6 @@ class TestController(testtools.TestCase):
images = list(self.controller.list(**filters))
self.assertEqual(1, len(images))
self.assertEqual('%s' % img_id, images[0].id)
pass
def test_list_images_for_tag_multiple_images(self):
img_id1 = '2a4560b2-e585-443e-9b39-553b46ec92d1'
@ -654,6 +653,13 @@ class TestController(testtools.TestCase):
images = list(self.controller.list(**filters))
self.assertEqual(0, len(images))
def test_list_images_for_invalid_tag(self):
filters = {'filters': {'tag': [[]]}}
self.assertRaises(exc.HTTPBadRequest,
list,
self.controller.list(**filters))
def test_list_images_with_single_sort_key(self):
img_id1 = '2a4560b2-e585-443e-9b39-553b46ec92d1'
sort_key = 'name'