From 6f101eb6e677521b12b533fac9f9d597e6fce6b1 Mon Sep 17 00:00:00 2001 From: git-hyagi <45576767+git-hyagi@users.noreply.github.com> Date: Wed, 24 Jul 2024 12:25:03 -0300 Subject: [PATCH] Handles an exception for non-existing repository fixes: #1703 (cherry picked from commit ae2c2f6d5132e98cd8dc2b93d428c542150080f5) --- CHANGES/1703.bugfix | 2 ++ pulp_container/app/registry_api.py | 6 ++++-- .../tests/functional/api/test_pull_content.py | 14 +++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 CHANGES/1703.bugfix 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 73d157377..9cf65d67f 100644 --- a/pulp_container/app/registry_api.py +++ b/pulp_container/app/registry_api.py @@ -287,13 +287,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."""