API v2: Allow GET on unowned images with show_image_direct_url
This fixes an issue where copy.deepcopy was being a called on an ImmutableLocations object, causing a Forbidden to be raised. Change-Id: Ia7ac121478cf63d68bd5a3d91faa51a42afeb2fe Closes-Bug: 1287888
This commit is contained in:
parent
cc118d431e
commit
45b7a31832
|
@ -14,6 +14,8 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import copy
|
||||||
|
|
||||||
from glance.common import exception
|
from glance.common import exception
|
||||||
import glance.domain.proxy
|
import glance.domain.proxy
|
||||||
|
|
||||||
|
@ -222,6 +224,9 @@ class ImmutableLocations(list):
|
||||||
"for this image.")
|
"for this image.")
|
||||||
raise exception.Forbidden(message)
|
raise exception.Forbidden(message)
|
||||||
|
|
||||||
|
def __deepcopy__(self, memo):
|
||||||
|
return ImmutableLocations(copy.deepcopy(list(self), memo))
|
||||||
|
|
||||||
append = forbidden
|
append = forbidden
|
||||||
extend = forbidden
|
extend = forbidden
|
||||||
insert = forbidden
|
insert = forbidden
|
||||||
|
|
|
@ -1845,7 +1845,8 @@ class TestImageDirectURLVisibility(functional.FunctionalTest):
|
||||||
headers = self._headers({'content-type': 'application/json'})
|
headers = self._headers({'content-type': 'application/json'})
|
||||||
data = jsonutils.dumps({'name': 'image-1', 'type': 'kernel',
|
data = jsonutils.dumps({'name': 'image-1', 'type': 'kernel',
|
||||||
'foo': 'bar', 'disk_format': 'aki',
|
'foo': 'bar', 'disk_format': 'aki',
|
||||||
'container_format': 'aki'})
|
'container_format': 'aki',
|
||||||
|
'visibility': 'public'})
|
||||||
response = requests.post(path, headers=headers, data=data)
|
response = requests.post(path, headers=headers, data=data)
|
||||||
self.assertEqual(201, response.status_code)
|
self.assertEqual(201, response.status_code)
|
||||||
|
|
||||||
|
@ -1875,6 +1876,15 @@ class TestImageDirectURLVisibility(functional.FunctionalTest):
|
||||||
image = jsonutils.loads(response.text)
|
image = jsonutils.loads(response.text)
|
||||||
self.assertTrue('direct_url' in image)
|
self.assertTrue('direct_url' in image)
|
||||||
|
|
||||||
|
# Image direct_url should be visible to non-owner, non-admin user
|
||||||
|
path = self._url('/v2/images/%s' % image_id)
|
||||||
|
headers = self._headers({'Content-Type': 'application/json',
|
||||||
|
'X-Tenant-Id': TENANT2})
|
||||||
|
response = requests.get(path, headers=headers)
|
||||||
|
self.assertEqual(200, response.status_code)
|
||||||
|
image = jsonutils.loads(response.text)
|
||||||
|
self.assertIn('direct_url', image)
|
||||||
|
|
||||||
# Image direct_url should be visible in a list
|
# Image direct_url should be visible in a list
|
||||||
path = self._url('/v2/images')
|
path = self._url('/v2/images')
|
||||||
headers = self._headers({'Content-Type': 'application/json'})
|
headers = self._headers({'Content-Type': 'application/json'})
|
||||||
|
|
|
@ -124,7 +124,7 @@ class TestLocationStrategy(base.IsolatedUnitTest):
|
||||||
original_locs = [{'url': 'loc1'}, {'url': 'loc2'}]
|
original_locs = [{'url': 'loc1'}, {'url': 'loc2'}]
|
||||||
ordered_locs = location_strategy.get_ordered_locations(original_locs)
|
ordered_locs = location_strategy.get_ordered_locations(original_locs)
|
||||||
|
|
||||||
# Deep copy protect original location list.
|
# Original location list should remain unchanged
|
||||||
self.assertNotEqual(id(original_locs), id(ordered_locs))
|
self.assertNotEqual(id(original_locs), id(ordered_locs))
|
||||||
self.assertEqual(original_locs, ordered_locs)
|
self.assertEqual(original_locs, ordered_locs)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue