Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return all catalog repos when token-auth disabled #1668

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES/1651.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Modified the `_catalog` endpoint to allow non-authed users to see all repos in catalog
(private and public) when token-auth is disabled.
3 changes: 3 additions & 0 deletions pulp_container/app/registry_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@ def get_queryset(self, *args, **kwargs):
distribution_permission = "container.pull_containerdistribution"
namespace_permission = "container.namespace_pull_containerdistribution"

if settings.get("TOKEN_AUTH_DISABLED", False):
return queryset

public_repositories = queryset.filter(private=False)
repositories_by_distribution = get_objects_for_user(
self.request.user, distribution_permission, queryset
Expand Down
34 changes: 21 additions & 13 deletions pulp_container/tests/functional/api/test_repositories_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ def setUpClass(cls):
]
)

cls.repositories_names_sorted = sorted(
[
cls.distribution1.base_path,
cls.distribution2.base_path,
cls.distribution3.base_path,
]
)

@classmethod
def tearDownClass(cls):
"""Clean generated resources."""
Expand All @@ -192,26 +200,26 @@ def test_none_user(self):
"""Check if the user can see only public repositories."""
auth = (self.user_none["username"], self.user_none["password"])
repositories = self.get_listed_repositories(auth)
self.assertEqual(repositories.json(), {"repositories": [self.distribution3.base_path]})
if TOKEN_AUTH_DISABLED:
self.assertEqual(repositories.json(), {"repositories": self.repositories_names_sorted})
else:
self.assertEqual(repositories.json(), {"repositories": [self.distribution3.base_path]})

@unittest.skipIf(TOKEN_AUTH_DISABLED, "Token authentication is not enabled")
def test_all_user(self):
"""Check if the user can see all repositories."""
auth = (self.user_all["username"], self.user_all["password"])
repositories = self.get_listed_repositories(auth)
repositories_names = sorted(
[
self.distribution1.base_path,
self.distribution2.base_path,
self.distribution3.base_path,
]
)
self.assertEqual(repositories.json(), {"repositories": repositories_names})
self.assertEqual(repositories.json(), {"repositories": self.repositories_names_sorted})

@unittest.skipIf(TOKEN_AUTH_DISABLED, "Token authentication is not enabled")
def test_only_dist1_user(self):
"""Check if the user can see all public repositories, but not all private repositories."""
auth = (self.user_only_dist1["username"], self.user_only_dist1["password"])
repositories = self.get_listed_repositories(auth)
repositories_names = sorted([self.distribution1.base_path, self.distribution3.base_path])
self.assertEqual(repositories.json(), {"repositories": repositories_names})

if TOKEN_AUTH_DISABLED:
self.assertEqual(repositories.json(), {"repositories": self.repositories_names_sorted})
else:
repositories_names = sorted(
[self.distribution1.base_path, self.distribution3.base_path]
)
self.assertEqual(repositories.json(), {"repositories": repositories_names})
Loading