diff --git a/data/interfaces/v2.py b/data/interfaces/v2.py index f949ddc4e..56f778bb8 100644 --- a/data/interfaces/v2.py +++ b/data/interfaces/v2.py @@ -22,7 +22,7 @@ class Repository(namedtuple('Repository', ['id', 'name', 'namespace_name', 'desc :type description: string :type is_public: bool :type kind: string - :type trust_enabled: bool + :type trust_enabled: bool """ class ManifestJSON(namedtuple('ManifestJSON', ['digest', 'json', 'media_type'])): @@ -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] diff --git a/endpoints/v2/catalog.py b/endpoints/v2/catalog.py index 8ae243460..e95cf8366 100644 --- a/endpoints/v2/catalog.py +++ b/endpoints/v2/catalog.py @@ -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], diff --git a/test/registry_tests.py b/test/registry_tests.py index 34df38e93..af0446311 100644 --- a/test/registry_tests.py +++ b/test/registry_tests.py @@ -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. - link_url = response.headers.get('Link')[1:].split(';')[0][:-1] - v2_index = link_url.find('/v2/') - relative_url = link_url[v2_index:] + 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() + 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.assertNotEquals(next_data['repositories'], data['repositories']) + 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,