diff --git a/CHANGES/1703.bugfix b/CHANGES/1703.bugfix new file mode 100644 index 000000000..231a3c156 --- /dev/null +++ b/CHANGES/1703.bugfix @@ -0,0 +1,2 @@ +Fixed an issue causing an HTTP 500 error when a GET request for a non-existing +blob was made to a distribution with only a `repository_version` set. diff --git a/pulp_container/app/registry_api.py b/pulp_container/app/registry_api.py index 74af16dc3..7b975d620 100644 --- a/pulp_container/app/registry_api.py +++ b/pulp_container/app/registry_api.py @@ -297,13 +297,15 @@ def get_drv_pull(self, path): except models.ContainerDistribution.DoesNotExist: # get a pull-through cache distribution whose base_path is a substring of the path return self.get_pull_through_drv(path) - if distribution.repository: + repository = distribution.repository + if repository: repository_version = distribution.repository.latest_version() elif distribution.repository_version: repository_version = distribution.repository_version + repository = repository_version.repository else: raise RepositoryNotFound(name=path) - return distribution, distribution.repository, repository_version + return distribution, repository, repository_version def get_pull_through_drv(self, path): pull_through_cache_distribution = ( diff --git a/pulp_container/tests/functional/api/test_pull_content.py b/pulp_container/tests/functional/api/test_pull_content.py index c0c8d399c..18702a726 100644 --- a/pulp_container/tests/functional/api/test_pull_content.py +++ b/pulp_container/tests/functional/api/test_pull_content.py @@ -28,7 +28,7 @@ REGISTRY_V2_REPO_HELLO_WORLD, PULP_HELLO_WORLD_LINUX_TAG, ) -from pulp_container.constants import EMPTY_BLOB, MEDIA_TYPE +from pulp_container.constants import EMPTY_BLOB, EMPTY_JSON, MEDIA_TYPE from pulpcore.client.pulp_container import ( ContainerContainerDistribution, @@ -279,6 +279,18 @@ def test_pull_nonexistent_image(self): with self.assertRaises(exceptions.CalledProcessError): registry.pull(local_url) + def test_pull_nonexistent_blob(self): + """ + Verify that a GET request to a nonexistent BLOB will be properly handled + instead of outputting a stacktrace. + """ + blob_path = "/v2/{}/blobs/{}".format(self.distribution_with_repo.base_path, EMPTY_JSON) + non_existing_blob_url = urljoin(self.cfg.get_base_url(), blob_path) + + auth = get_auth_for_url(non_existing_blob_url) + content_response = requests.get(non_existing_blob_url, auth=auth) + assert content_response.status_code, 404 + class PullOnDemandContentTestCase(unittest.TestCase): """Verify whether on-demand served images by Pulp can be pulled."""