From bc8269472574fd27ad2be5f1d3c1888dc5440c4b Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Thu, 25 Jun 2020 12:17:21 -0700 Subject: [PATCH] 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 (cherry picked from commit f450b9cf0314afeb9aa64ed687218b92b6a49321) --- .../async_/flows/test_api_image_import.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/glance/tests/unit/async_/flows/test_api_image_import.py b/glance/tests/unit/async_/flows/test_api_image_import.py index b449768cdb..eeed57c424 100644 --- a/glance/tests/unit/async_/flows/test_api_image_import.py +++ b/glance/tests/unit/async_/flows/test_api_image_import.py @@ -18,7 +18,9 @@ from unittest import mock from glance_store import exceptions as store_exceptions from oslo_config import cfg +from glance.api import authorization import glance.async_.flows.api_image_import as import_flow +from glance.common import exception from glance.common.exception import ImportTaskError from glance import context from glance import gateway @@ -260,3 +262,33 @@ class TestVerifyImageStateTask(test_utils.BaseTestCase): # Except for copy-image, image state should revert to queued mock_repo.save_image.assert_called_once() + + +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'])