Add a test to replicate the owner-required behavior of copy-image
Right now, image_import(method='copy-image') requires you to be the owner of the image. This adds a test that validates that behavior so we can measure the difference of the next set of changes to modify that. Change-Id: I284271a458117b753a88b847598ca10ce4fb94fa
This commit is contained in:
parent
fadf546a75
commit
f450b9cf03
|
@ -17,7 +17,9 @@ from unittest import mock
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
|
from glance.api import authorization
|
||||||
import glance.async_.flows.api_image_import as import_flow
|
import glance.async_.flows.api_image_import as import_flow
|
||||||
|
from glance.common import exception
|
||||||
from glance.common.exception import ImportTaskError
|
from glance.common.exception import ImportTaskError
|
||||||
from glance import context
|
from glance import context
|
||||||
from glance import gateway
|
from glance import gateway
|
||||||
|
@ -166,3 +168,33 @@ class TestImportToStoreTask(test_utils.BaseTestCase):
|
||||||
"store1")
|
"store1")
|
||||||
except cursive_exception.SignatureVerificationError:
|
except cursive_exception.SignatureVerificationError:
|
||||||
self.fail("Exception shouldn't be raised")
|
self.fail("Exception shouldn't be raised")
|
||||||
|
|
||||||
|
|
||||||
|
class TestImportCopyImageTask(test_utils.BaseTestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestImportCopyImageTask, self).setUp()
|
||||||
|
|
||||||
|
self.context = context.RequestContext(user_id=TENANT1,
|
||||||
|
project_id=TENANT1,
|
||||||
|
overwrite=False)
|
||||||
|
|
||||||
|
@mock.patch("glance.async_.flows.api_image_import.image_import")
|
||||||
|
def test_copy_as_non_owner(self, mock_import):
|
||||||
|
img_repo_db = mock.MagicMock()
|
||||||
|
img_repo = authorization.ImageRepoProxy(img_repo_db, self.context)
|
||||||
|
|
||||||
|
fake_req = {"method": {"name": "copy-image"},
|
||||||
|
"backend": ['cheap']}
|
||||||
|
|
||||||
|
# FIXME(danms): Right now, this fails with Forbidden because we
|
||||||
|
# don't own the image
|
||||||
|
self.assertRaises(exception.Forbidden,
|
||||||
|
import_flow.get_flow,
|
||||||
|
task_id=TASK_ID1,
|
||||||
|
task_type=TASK_TYPE,
|
||||||
|
task_repo=mock.MagicMock(),
|
||||||
|
image_repo=img_repo,
|
||||||
|
image_id=IMAGE_ID1,
|
||||||
|
import_req=fake_req,
|
||||||
|
backend=['cheap'])
|
||||||
|
|
Loading…
Reference in New Issue