Skip to content

Commit

Permalink
Handles an exception for non-existing repository
Browse files Browse the repository at this point in the history
fixes: #1703
(cherry picked from commit ae2c2f6)
  • Loading branch information
git-hyagi committed Jul 25, 2024
1 parent 7cb9e8f commit 6f101eb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES/1703.bugfix
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 4 additions & 2 deletions pulp_container/app/registry_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
14 changes: 13 additions & 1 deletion pulp_container/tests/functional/api/test_pull_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit 6f101eb

Please sign in to comment.