diff --git a/endpoints/v1/index.py b/endpoints/v1/index.py index 16f94d8f9..2a3eb6d05 100644 --- a/endpoints/v1/index.py +++ b/endpoints/v1/index.py @@ -315,7 +315,7 @@ def _conduct_repo_search(username, query, results): if repo.is_public: return True - return ReadRepositoryPermission(repo.namespace_name, repo.name).can() + return ReadRepositoryPermission(repo.namespace_user.username, repo.name).can() only_public = username is None matching_repos = model.get_sorted_matching_repositories(query, only_public, can_read, limit=5) diff --git a/test/registry_tests.py b/test/registry_tests.py index b9d4d8212..dd1b415e8 100644 --- a/test/registry_tests.py +++ b/test/registry_tests.py @@ -1273,6 +1273,26 @@ class RegistryTestsMixin(object): class V1RegistryTests(V1RegistryPullMixin, V1RegistryPushMixin, RegistryTestsMixin, RegistryTestCaseMixin, LiveServerTestCase): """ Tests for V1 registry. """ + def test_search(self): + # Public + resp = self.conduct('GET', '/v1/search', params=dict(q='public')) + data = resp.json() + self.assertEquals(1, data['num_results']) + self.assertEquals(1, len(data['results'])) + + # Simple (not logged in, no results) + resp = self.conduct('GET', '/v1/search', params=dict(q='simple')) + data = resp.json() + self.assertEquals(0, data['num_results']) + self.assertEquals(0, len(data['results'])) + + # Simple (logged in) + resp = self.conduct('GET', '/v1/search', params=dict(q='simple'), auth=('devtable', 'password')) + data = resp.json() + self.assertEquals(1, data['num_results']) + self.assertEquals(1, len(data['results'])) + + def test_users(self): # Not logged in, should 404. self.conduct('GET', '/v1/users', expected_code=404)