Fix namespace lookup in V1 registry search

Fixes #2053
This commit is contained in:
Joseph Schorr 2016-10-31 13:24:40 -04:00
parent 6ae13096c7
commit bab17932ac
2 changed files with 21 additions and 1 deletions

View file

@ -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)

View file

@ -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)