diff --git a/glance/api/v1/members.py b/glance/api/v1/members.py index ae9dd5f6aa..fbae772475 100644 --- a/glance/api/v1/members.py +++ b/glance/api/v1/members.py @@ -93,6 +93,10 @@ class Controller(object): can_share = bool(body['member']['can_share']) try: registry.add_member(req.context, image_id, id, can_share) + except exception.Invalid, e: + msg = "%s" % e + logger.debug(msg) + raise webob.exc.HTTPBadRequest(explanation=msg) except exception.NotFound, e: msg = "%s" % e logger.debug(msg) @@ -121,6 +125,10 @@ class Controller(object): try: registry.replace_members(req.context, image_id, body) + except exception.Invalid, e: + msg = "%s" % e + logger.debug(msg) + raise webob.exc.HTTPBadRequest(explanation=msg) except exception.NotFound, e: msg = "%s" % e logger.debug(msg) diff --git a/glance/tests/functional/test_shared_images.py b/glance/tests/functional/test_shared_images.py index c8882c4809..5a39d22365 100644 --- a/glance/tests/functional/test_shared_images.py +++ b/glance/tests/functional/test_shared_images.py @@ -148,6 +148,24 @@ class TestSharedImagesApi(keystone_utils.KeystoneTests): self.assertEqual(response.status, 200) self.assertEqual(content, '{"images": []}') + # Build path for the next couple of checks + path = ("http://%s:%d/v1/images/%s/members" % + ("0.0.0.0", self.api_port, image_id)) + + # Make sure update with invalid data gets rejected with 400 + body = { + 'test': [ + { + 'member_id': keystone_utils.bacon_id, + 'can_share': False, + }, + ], + } + response, _ = self._request(path, 'PUT', + keystone_utils.pattieblack_token, + body=json.dumps(body)) + self.assertEqual(response.status, 400) + # Replace froggy with bacon body = { 'memberships': [ @@ -157,8 +175,6 @@ class TestSharedImagesApi(keystone_utils.KeystoneTests): }, ], } - path = "http://%s:%d/v1/images/%s/members" % \ - ("0.0.0.0", self.api_port, image_id) response, content = self._request(path, 'PUT', keystone_utils.pattieblack_token,