Fix issue in V1 registry code with accessing locations under HEAD

Fixes #1922
This commit is contained in:
Joseph Schorr 2016-10-03 17:09:12 +03:00
parent 95b7b47501
commit 0b7bb6d6c6
3 changed files with 7 additions and 17 deletions

View file

@ -22,14 +22,6 @@ class DockerRegistryV1DataInterface(object):
Interface that represents all data store interactions required by a Docker Registry v1.
"""
@abstractmethod
def placement_locations_docker_v1(self, namespace_name, repo_name, image_id):
"""
Returns all the placements for the image with the given V1 Docker ID, found under the given
repository or None if no image was found.
"""
pass
@abstractmethod
def placement_locations_and_path_docker_v1(self, namespace_name, repo_name, image_id):
"""
@ -233,12 +225,6 @@ class PreOCIModel(DockerRegistryV1DataInterface):
PreOCIModel implements the data model for the v1 Docker Registry protocol using a database schema
before it was changed to support the OCI specification.
"""
def placement_locations_docker_v1(self, namespace_name, repo_name, image_id):
repo_image = model.image.get_repo_image_and_storage(namespace_name, repo_name, image_id)
if repo_image is None or repo_image.storage is None:
return None
return repo_image.storage.locations
def placement_locations_and_path_docker_v1(self, namespace_name, repo_name, image_id):
repo_image = model.image.get_repo_image_extended(namespace_name, repo_name, image_id)
if not repo_image or repo_image.storage is None:

View file

@ -84,7 +84,7 @@ def head_image_layer(namespace, repository, image_id, headers):
logger.debug('Checking repo permissions')
if permission.can() or model.repository_is_public(namespace, repository):
logger.debug('Looking up placement locations')
locations = model.placement_locations_docker_v1(namespace, repository, image_id)
locations, _ = model.placement_locations_and_path_docker_v1(namespace, repository, image_id)
if locations is None:
logger.debug('Could not find any blob placement locations')
abort(404, 'Image %(image_id)s not found', issue='unknown-image',

View file

@ -438,6 +438,10 @@ class V1RegistryPullMixin(V1RegistryMixin):
response = self.conduct('GET', image_prefix + 'json', auth='sig')
self.assertEquals(image_id, response.json()['id'])
# Ensure we can HEAD the image layer.
self.conduct('HEAD', image_prefix + 'layer', auth='sig')
# And retrieve the layer data.
response = self.conduct('GET', image_prefix + 'layer', auth='sig')
# Ensure we can parse the layer bytes and that they contain the contents.
@ -1145,10 +1149,10 @@ class V2RegistryTests(V2RegistryPullMixin, V2RegistryPushMixin, RegistryTestsMix
""" Tests for V2 registry. """
def test_numeric_tag(self):
# Push a new repository.
self.do_push('public', 'newrepo', 'public', 'password', tag_name='1234')
self.do_push('public', 'new-repo', 'public', 'password', tag_name='1234')
# Pull the repository.
self.do_pull('public', 'newrepo', 'public', 'password', manifest_id='1234')
self.do_pull('public', 'new-repo', 'public', 'password', manifest_id='1234')
def test_label_invalid_manifest(self):
images = [{