|
|
|
@ -10,6 +10,7 @@ import ( |
|
|
|
|
auth_model "code.gitea.io/gitea/models/auth" |
|
|
|
|
"code.gitea.io/gitea/models/db" |
|
|
|
|
org_model "code.gitea.io/gitea/models/organization" |
|
|
|
|
repo_model "code.gitea.io/gitea/models/repo" |
|
|
|
|
"code.gitea.io/gitea/models/unittest" |
|
|
|
|
user_model "code.gitea.io/gitea/models/user" |
|
|
|
|
api "code.gitea.io/gitea/modules/structs" |
|
|
|
@ -81,8 +82,8 @@ func TestAPIForkListLimitedAndPrivateRepos(t *testing.T) { |
|
|
|
|
var forks []*api.Repository |
|
|
|
|
DecodeJSON(t, resp, &forks) |
|
|
|
|
|
|
|
|
|
assert.Len(t, forks, 1) |
|
|
|
|
assert.EqualValues(t, "1", resp.Header().Get("X-Total-Count")) |
|
|
|
|
assert.Len(t, forks, 2) |
|
|
|
|
assert.EqualValues(t, "2", resp.Header().Get("X-Total-Count")) |
|
|
|
|
|
|
|
|
|
assert.NoError(t, org_service.AddTeamMember(db.DefaultContext, ownerTeam2, user1)) |
|
|
|
|
|
|
|
|
@ -96,3 +97,31 @@ func TestAPIForkListLimitedAndPrivateRepos(t *testing.T) { |
|
|
|
|
assert.EqualValues(t, "2", resp.Header().Get("X-Total-Count")) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestGetPrivateReposForks(t *testing.T) { |
|
|
|
|
defer tests.PrepareTestEnv(t)() |
|
|
|
|
|
|
|
|
|
user1Sess := loginUser(t, "user1") |
|
|
|
|
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}) // private repository
|
|
|
|
|
privateOrg := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 23}) |
|
|
|
|
user1Token := getTokenForLoggedInUser(t, user1Sess, auth_model.AccessTokenScopeWriteRepository) |
|
|
|
|
|
|
|
|
|
forkedRepoName := "forked-repo" |
|
|
|
|
// create fork from a private repository
|
|
|
|
|
req := NewRequestWithJSON(t, "POST", "/api/v1/repos/"+repo2.FullName()+"/forks", &api.CreateForkOption{ |
|
|
|
|
Organization: &privateOrg.Name, |
|
|
|
|
Name: &forkedRepoName, |
|
|
|
|
}).AddTokenAuth(user1Token) |
|
|
|
|
MakeRequest(t, req, http.StatusAccepted) |
|
|
|
|
|
|
|
|
|
// test get a private fork without clear permissions
|
|
|
|
|
req = NewRequest(t, "GET", "/api/v1/repos/"+repo2.FullName()+"/forks").AddTokenAuth(user1Token) |
|
|
|
|
resp := MakeRequest(t, req, http.StatusOK) |
|
|
|
|
|
|
|
|
|
forks := []*api.Repository{} |
|
|
|
|
DecodeJSON(t, resp, &forks) |
|
|
|
|
assert.Len(t, forks, 1) |
|
|
|
|
assert.EqualValues(t, "1", resp.Header().Get("X-Total-Count")) |
|
|
|
|
assert.EqualValues(t, "forked-repo", forks[0].Name) |
|
|
|
|
assert.EqualValues(t, privateOrg.Name, forks[0].Owner.UserName) |
|
|
|
|
} |
|
|
|
|