Make sure catalog always returns public repositories

This commit is contained in:
Joseph Schorr 2017-05-19 16:24:08 -04:00
parent 86bcbd1225
commit 065e327190
3 changed files with 24 additions and 11 deletions

View file

@ -387,9 +387,12 @@ class PreOCIModel(DockerRegistryV2DataInterface):
tags_query = tags_query.limit(limit).offset(offset)
return [_tag_view(tag) for tag in tags_query]
def get_visible_repositories(self, username, limit, offset):
def get_visible_repositories(self, username, limit, offset, include_public=None):
if include_public is None:
include_public = (username is None)
query = model.repository.get_visible_repositories(username, kind_filter='image',
include_public=(username is None))
include_public=include_public)
query = query.limit(limit).offset(offset)
return [_repository_for_repo(repo) for repo in query]

View file

@ -15,7 +15,8 @@ def catalog_search(limit, offset, pagination_callback):
if entity:
username = entity.user.username
visible_repositories = model.get_visible_repositories(username, limit+1, offset)
visible_repositories = model.get_visible_repositories(username, limit+1, offset,
include_public=True)
response = jsonify({
'repositories': ['%s/%s' % (repo.namespace_name, repo.name)
for repo in visible_repositories][0:limit],

View file

@ -1813,24 +1813,33 @@ class V2RegistryTests(V2RegistryPullMixin, V2RegistryPushMixin, RegistryTestsMix
# Perform auth and lookup the catalog again.
self.do_auth('devtable', 'password', 'devtable', 'simple')
all_repos = []
response = self.conduct('GET', '/v2/_catalog', params=dict(n=2), auth='jwt')
data = response.json()
self.assertEquals(len(data['repositories']), 2)
all_repos.extend(data['repositories'])
# Ensure we have a next link.
self.assertIsNotNone(response.headers.get('Link'))
# Request with the next link.
while response.headers.get('Link'):
link_url = response.headers.get('Link')[1:].split(';')[0][:-1]
v2_index = link_url.find('/v2/')
relative_url = link_url[v2_index:]
next_response = self.conduct('GET', relative_url, auth='jwt')
next_data = next_response.json()
all_repos.extend(next_data['repositories'])
self.assertEquals(len(next_data['repositories']), 2)
self.assertTrue(len(next_data['repositories']) <= 2)
self.assertNotEquals(next_data['repositories'], data['repositories'])
response = next_response
# Ensure the authed request has the public repository.
public = [reponame for reponame in all_repos if reponame.find('/publicrepo') >= 0]
self.assertTrue(bool(public))
class V1PushV2PullRegistryTests(V2RegistryPullMixin, V1RegistryPushMixin, RegistryTestsMixin,