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
  • Loading branch information
git-hyagi committed Jul 24, 2024
1 parent a074013 commit 265be2f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGES/1703.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed an issue that triggered a `NoneType` exception during a GET request when
a `distribution` was created with only the `repository_version` (without specifying
a `repository`).
6 changes: 4 additions & 2 deletions pulp_container/app/registry_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
15 changes: 14 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,19 @@ 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)
with self.assertRaises(requests.exceptions.HTTPError):
content_response.raise_for_status()


class PullOnDemandContentTestCase(unittest.TestCase):
"""Verify whether on-demand served images by Pulp can be pulled."""
Expand Down

0 comments on commit 265be2f

Please sign in to comment.