From 3379141d818804aa8f7143ef32bd538c7e4ce795 Mon Sep 17 00:00:00 2001 From: Daniel Balko Date: Fri, 23 Nov 2018 22:23:27 +0100 Subject: API: '/orgs/:org/repos': return private repos with read access (#5310) (#3829) (#5383) Signed-off-by: Daniel Balko --- integrations/api_repo_test.go | 49 ++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 12 deletions(-) (limited to 'integrations') diff --git a/integrations/api_repo_test.go b/integrations/api_repo_test.go index 62237e2be3..da748942f6 100644 --- a/integrations/api_repo_test.go +++ b/integrations/api_repo_test.go @@ -212,21 +212,46 @@ func TestAPIViewRepo(t *testing.T) { func TestAPIOrgRepos(t *testing.T) { prepareTestEnv(t) user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) + user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User) + user3 := models.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User) // User3 is an Org. Check their repos. sourceOrg := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) - // Login as User2. - session := loginUser(t, user.Name) - token := getTokenForLoggedInUser(t, session) - req := NewRequestf(t, "GET", "/api/v1/orgs/%s/repos?token="+token, sourceOrg.Name) - resp := session.MakeRequest(t, req, http.StatusOK) - var apiRepos []*api.Repository - DecodeJSON(t, resp, &apiRepos) - expectedLen := models.GetCount(t, models.Repository{OwnerID: sourceOrg.ID}, - models.Cond("is_private = ?", false)) - assert.Len(t, apiRepos, expectedLen) - for _, repo := range apiRepos { - assert.False(t, repo.Private) + expectedResults := map[*models.User]struct { + count int + includesPrivate bool + }{ + nil: {count: 1}, + user: {count: 2, includesPrivate: true}, + user2: {count: 3, includesPrivate: true}, + user3: {count: 1}, + } + + for userToLogin, expected := range expectedResults { + var session *TestSession + var testName string + var token string + if userToLogin != nil && userToLogin.ID > 0 { + testName = fmt.Sprintf("LoggedUser%d", userToLogin.ID) + session = loginUser(t, userToLogin.Name) + token = getTokenForLoggedInUser(t, session) + } else { + testName = "AnonymousUser" + session = emptyTestSession(t) + } + t.Run(testName, func(t *testing.T) { + req := NewRequestf(t, "GET", "/api/v1/orgs/%s/repos?token="+token, sourceOrg.Name) + resp := session.MakeRequest(t, req, http.StatusOK) + + var apiRepos []*api.Repository + DecodeJSON(t, resp, &apiRepos) + assert.Len(t, apiRepos, expected.count) + for _, repo := range apiRepos { + if !expected.includesPrivate { + assert.False(t, repo.Private) + } + } + }) } } -- cgit v1.2.3