2017-04-29 10:03:25 +05:30
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package integrations
|
|
|
|
|
|
|
|
import (
|
2017-10-10 06:53:29 +05:30
|
|
|
"fmt"
|
2017-04-29 10:03:25 +05:30
|
|
|
"net/http"
|
2019-03-15 19:49:09 +05:30
|
|
|
"net/url"
|
2021-09-22 11:08:34 +05:30
|
|
|
"os"
|
2017-04-29 10:03:25 +05:30
|
|
|
"testing"
|
2017-07-10 16:37:39 +05:30
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
2021-12-10 06:57:50 +05:30
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-16 14:23:21 +05:30
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 15:19:20 +05:30
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2020-06-09 08:16:51 +05:30
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2019-05-11 15:51:34 +05:30
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2020-08-12 01:35:34 +05:30
|
|
|
"code.gitea.io/gitea/modules/util"
|
2017-07-10 16:37:39 +05:30
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2017-04-29 10:03:25 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
func TestAPIUserReposNotLogin(t *testing.T) {
|
2019-11-26 04:51:37 +05:30
|
|
|
defer prepareTestEnv(t)()
|
2021-11-24 15:19:20 +05:30
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
2017-07-10 16:37:39 +05:30
|
|
|
|
|
|
|
req := NewRequestf(t, "GET", "/api/v1/users/%s/repos", user.Name)
|
|
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
2017-04-29 10:03:25 +05:30
|
|
|
|
2017-07-10 16:37:39 +05:30
|
|
|
var apiRepos []api.Repository
|
|
|
|
DecodeJSON(t, resp, &apiRepos)
|
2021-12-10 06:57:50 +05:30
|
|
|
expectedLen := unittest.GetCount(t, repo_model.Repository{OwnerID: user.ID},
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.Cond("is_private = ?", false))
|
2017-07-10 16:37:39 +05:30
|
|
|
assert.Len(t, apiRepos, expectedLen)
|
|
|
|
for _, repo := range apiRepos {
|
|
|
|
assert.EqualValues(t, user.ID, repo.Owner.ID)
|
|
|
|
assert.False(t, repo.Private)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-10 06:53:29 +05:30
|
|
|
func TestAPISearchRepo(t *testing.T) {
|
2019-11-26 04:51:37 +05:30
|
|
|
defer prepareTestEnv(t)()
|
2017-07-10 16:37:39 +05:30
|
|
|
const keyword = "test"
|
|
|
|
|
|
|
|
req := NewRequestf(t, "GET", "/api/v1/repos/search?q=%s", keyword)
|
|
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
2017-04-30 10:38:09 +05:30
|
|
|
|
2017-09-20 14:54:38 +05:30
|
|
|
var body api.SearchResults
|
2017-07-10 16:37:39 +05:30
|
|
|
DecodeJSON(t, resp, &body)
|
2017-09-20 14:54:38 +05:30
|
|
|
assert.NotEmpty(t, body.Data)
|
|
|
|
for _, repo := range body.Data {
|
|
|
|
assert.Contains(t, repo.Name, keyword)
|
|
|
|
assert.False(t, repo.Private)
|
2017-07-10 16:37:39 +05:30
|
|
|
}
|
2017-10-10 06:53:29 +05:30
|
|
|
|
2021-11-24 15:19:20 +05:30
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 15}).(*user_model.User)
|
|
|
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 16}).(*user_model.User)
|
|
|
|
user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 18}).(*user_model.User)
|
|
|
|
user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 20}).(*user_model.User)
|
|
|
|
orgUser := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 17}).(*user_model.User)
|
2017-10-10 06:53:29 +05:30
|
|
|
|
2020-06-09 08:16:51 +05:30
|
|
|
oldAPIDefaultNum := setting.API.DefaultPagingNum
|
|
|
|
defer func() {
|
|
|
|
setting.API.DefaultPagingNum = oldAPIDefaultNum
|
|
|
|
}()
|
|
|
|
setting.API.DefaultPagingNum = 10
|
|
|
|
|
2017-10-10 06:53:29 +05:30
|
|
|
// Map of expected results, where key is user for login
|
2021-11-24 15:19:20 +05:30
|
|
|
type expectedResults map[*user_model.User]struct {
|
2017-10-10 06:53:29 +05:30
|
|
|
count int
|
|
|
|
repoOwnerID int64
|
|
|
|
repoName string
|
|
|
|
includesPrivate bool
|
|
|
|
}
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name, requestURL string
|
|
|
|
expectedResults
|
|
|
|
}{
|
2022-01-20 23:16:10 +05:30
|
|
|
{
|
|
|
|
name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50&private=false", expectedResults: expectedResults{
|
|
|
|
nil: {count: 30},
|
|
|
|
user: {count: 30},
|
|
|
|
user2: {count: 30},
|
|
|
|
},
|
2017-10-10 06:53:29 +05:30
|
|
|
},
|
2022-01-20 23:16:10 +05:30
|
|
|
{
|
|
|
|
name: "RepositoriesMax10", requestURL: "/api/v1/repos/search?limit=10&private=false", expectedResults: expectedResults{
|
|
|
|
nil: {count: 10},
|
|
|
|
user: {count: 10},
|
|
|
|
user2: {count: 10},
|
|
|
|
},
|
2017-10-10 06:53:29 +05:30
|
|
|
},
|
2022-01-20 23:16:10 +05:30
|
|
|
{
|
|
|
|
name: "RepositoriesDefault", requestURL: "/api/v1/repos/search?default&private=false", expectedResults: expectedResults{
|
|
|
|
nil: {count: 10},
|
|
|
|
user: {count: 10},
|
|
|
|
user2: {count: 10},
|
|
|
|
},
|
2017-10-10 06:53:29 +05:30
|
|
|
},
|
2022-01-20 23:16:10 +05:30
|
|
|
{
|
|
|
|
name: "RepositoriesByName", requestURL: fmt.Sprintf("/api/v1/repos/search?q=%s&private=false", "big_test_"), expectedResults: expectedResults{
|
|
|
|
nil: {count: 7, repoName: "big_test_"},
|
|
|
|
user: {count: 7, repoName: "big_test_"},
|
|
|
|
user2: {count: 7, repoName: "big_test_"},
|
|
|
|
},
|
2017-10-10 06:53:29 +05:30
|
|
|
},
|
2022-01-20 23:16:10 +05:30
|
|
|
{
|
|
|
|
name: "RepositoriesAccessibleAndRelatedToUser", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user.ID), expectedResults: expectedResults{
|
|
|
|
nil: {count: 5},
|
|
|
|
user: {count: 9, includesPrivate: true},
|
|
|
|
user2: {count: 6, includesPrivate: true},
|
|
|
|
},
|
2017-10-10 06:53:29 +05:30
|
|
|
},
|
2022-01-20 23:16:10 +05:30
|
|
|
{
|
|
|
|
name: "RepositoriesAccessibleAndRelatedToUser2", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user2.ID), expectedResults: expectedResults{
|
|
|
|
nil: {count: 1},
|
|
|
|
user: {count: 2, includesPrivate: true},
|
|
|
|
user2: {count: 2, includesPrivate: true},
|
|
|
|
user4: {count: 1},
|
|
|
|
},
|
2017-10-10 06:53:29 +05:30
|
|
|
},
|
2022-01-20 23:16:10 +05:30
|
|
|
{
|
|
|
|
name: "RepositoriesAccessibleAndRelatedToUser3", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user3.ID), expectedResults: expectedResults{
|
|
|
|
nil: {count: 1},
|
|
|
|
user: {count: 4, includesPrivate: true},
|
|
|
|
user2: {count: 3, includesPrivate: true},
|
|
|
|
user3: {count: 4, includesPrivate: true},
|
|
|
|
},
|
2017-10-17 20:50:22 +05:30
|
|
|
},
|
2022-01-20 23:16:10 +05:30
|
|
|
{
|
|
|
|
name: "RepositoriesOwnedByOrganization", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", orgUser.ID), expectedResults: expectedResults{
|
|
|
|
nil: {count: 1, repoOwnerID: orgUser.ID},
|
|
|
|
user: {count: 2, repoOwnerID: orgUser.ID, includesPrivate: true},
|
|
|
|
user2: {count: 1, repoOwnerID: orgUser.ID},
|
|
|
|
},
|
2017-10-10 06:53:29 +05:30
|
|
|
},
|
2017-10-27 02:46:13 +05:30
|
|
|
{name: "RepositoriesAccessibleAndRelatedToUser4", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user4.ID), expectedResults: expectedResults{
|
|
|
|
nil: {count: 3},
|
2019-05-15 20:54:39 +05:30
|
|
|
user: {count: 4, includesPrivate: true},
|
2022-01-20 23:16:10 +05:30
|
|
|
user4: {count: 7, includesPrivate: true},
|
|
|
|
}},
|
2017-10-27 02:46:13 +05:30
|
|
|
{name: "RepositoriesAccessibleAndRelatedToUser4/SearchModeSource", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d&mode=%s", user4.ID, "source"), expectedResults: expectedResults{
|
|
|
|
nil: {count: 0},
|
2019-05-15 20:54:39 +05:30
|
|
|
user: {count: 1, includesPrivate: true},
|
2022-01-20 23:16:10 +05:30
|
|
|
user4: {count: 1, includesPrivate: true},
|
|
|
|
}},
|
2017-10-27 02:46:13 +05:30
|
|
|
{name: "RepositoriesAccessibleAndRelatedToUser4/SearchModeFork", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d&mode=%s", user4.ID, "fork"), expectedResults: expectedResults{
|
|
|
|
nil: {count: 1},
|
|
|
|
user: {count: 1},
|
2022-01-20 23:16:10 +05:30
|
|
|
user4: {count: 2, includesPrivate: true},
|
|
|
|
}},
|
2017-10-27 02:46:13 +05:30
|
|
|
{name: "RepositoriesAccessibleAndRelatedToUser4/SearchModeFork/Exclusive", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d&mode=%s&exclusive=1", user4.ID, "fork"), expectedResults: expectedResults{
|
|
|
|
nil: {count: 1},
|
|
|
|
user: {count: 1},
|
2022-01-20 23:16:10 +05:30
|
|
|
user4: {count: 2, includesPrivate: true},
|
|
|
|
}},
|
2017-10-27 02:46:13 +05:30
|
|
|
{name: "RepositoriesAccessibleAndRelatedToUser4/SearchModeMirror", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d&mode=%s", user4.ID, "mirror"), expectedResults: expectedResults{
|
|
|
|
nil: {count: 2},
|
|
|
|
user: {count: 2},
|
2022-01-20 23:16:10 +05:30
|
|
|
user4: {count: 4, includesPrivate: true},
|
|
|
|
}},
|
2017-10-27 02:46:13 +05:30
|
|
|
{name: "RepositoriesAccessibleAndRelatedToUser4/SearchModeMirror/Exclusive", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d&mode=%s&exclusive=1", user4.ID, "mirror"), expectedResults: expectedResults{
|
|
|
|
nil: {count: 1},
|
|
|
|
user: {count: 1},
|
2022-01-20 23:16:10 +05:30
|
|
|
user4: {count: 2, includesPrivate: true},
|
|
|
|
}},
|
2017-10-27 02:46:13 +05:30
|
|
|
{name: "RepositoriesAccessibleAndRelatedToUser4/SearchModeCollaborative", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d&mode=%s", user4.ID, "collaborative"), expectedResults: expectedResults{
|
|
|
|
nil: {count: 0},
|
2019-05-15 20:54:39 +05:30
|
|
|
user: {count: 1, includesPrivate: true},
|
2022-01-20 23:16:10 +05:30
|
|
|
user4: {count: 1, includesPrivate: true},
|
|
|
|
}},
|
2017-10-10 06:53:29 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
for _, testCase := range testCases {
|
|
|
|
t.Run(testCase.name, func(t *testing.T) {
|
|
|
|
for userToLogin, expected := range testCase.expectedResults {
|
|
|
|
var session *TestSession
|
|
|
|
var testName string
|
2017-10-27 02:46:13 +05:30
|
|
|
var userID int64
|
2018-09-10 21:45:52 +05:30
|
|
|
var token string
|
2017-10-10 06:53:29 +05:30
|
|
|
if userToLogin != nil && userToLogin.ID > 0 {
|
|
|
|
testName = fmt.Sprintf("LoggedUser%d", userToLogin.ID)
|
|
|
|
session = loginUser(t, userToLogin.Name)
|
2018-09-10 21:45:52 +05:30
|
|
|
token = getTokenForLoggedInUser(t, session)
|
2017-10-27 02:46:13 +05:30
|
|
|
userID = userToLogin.ID
|
2017-10-10 06:53:29 +05:30
|
|
|
} else {
|
|
|
|
testName = "AnonymousUser"
|
|
|
|
session = emptyTestSession(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run(testName, func(t *testing.T) {
|
2018-09-10 21:45:52 +05:30
|
|
|
request := NewRequest(t, "GET", testCase.requestURL+"&token="+token)
|
2017-10-10 06:53:29 +05:30
|
|
|
response := session.MakeRequest(t, request, http.StatusOK)
|
|
|
|
|
|
|
|
var body api.SearchResults
|
|
|
|
DecodeJSON(t, response, &body)
|
|
|
|
|
2019-05-15 20:54:39 +05:30
|
|
|
repoNames := make([]string, 0, len(body.Data))
|
|
|
|
for _, repo := range body.Data {
|
|
|
|
repoNames = append(repoNames, fmt.Sprintf("%d:%s:%t", repo.ID, repo.FullName, repo.Private))
|
|
|
|
}
|
|
|
|
assert.Len(t, repoNames, expected.count)
|
2017-10-10 06:53:29 +05:30
|
|
|
for _, repo := range body.Data {
|
2017-10-27 02:46:13 +05:30
|
|
|
r := getRepo(t, repo.ID)
|
2018-11-28 16:56:14 +05:30
|
|
|
hasAccess, err := models.HasAccess(userID, r)
|
2019-05-15 20:54:39 +05:30
|
|
|
assert.NoError(t, err, "Error when checking if User: %d has access to %s: %v", userID, repo.FullName, err)
|
|
|
|
assert.True(t, hasAccess, "User: %d does not have access to %s", userID, repo.FullName)
|
2017-10-27 02:46:13 +05:30
|
|
|
|
2017-10-10 06:53:29 +05:30
|
|
|
assert.NotEmpty(t, repo.Name)
|
2019-05-15 20:54:39 +05:30
|
|
|
assert.Equal(t, repo.Name, r.Name)
|
2017-10-10 06:53:29 +05:30
|
|
|
|
|
|
|
if len(expected.repoName) > 0 {
|
|
|
|
assert.Contains(t, repo.Name, expected.repoName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if expected.repoOwnerID > 0 {
|
|
|
|
assert.Equal(t, expected.repoOwnerID, repo.Owner.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !expected.includesPrivate {
|
2019-05-15 20:54:39 +05:30
|
|
|
assert.False(t, repo.Private, "User: %d not expecting private repository: %s", userID, repo.FullName)
|
2017-10-10 06:53:29 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2017-04-30 10:38:09 +05:30
|
|
|
}
|
2017-07-12 06:53:41 +05:30
|
|
|
|
2021-12-10 06:57:50 +05:30
|
|
|
var repoCache = make(map[int64]*repo_model.Repository)
|
2017-10-27 02:46:13 +05:30
|
|
|
|
2021-12-10 06:57:50 +05:30
|
|
|
func getRepo(t *testing.T, repoID int64) *repo_model.Repository {
|
2017-10-27 02:46:13 +05:30
|
|
|
if _, ok := repoCache[repoID]; !ok {
|
2021-12-10 06:57:50 +05:30
|
|
|
repoCache[repoID] = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID}).(*repo_model.Repository)
|
2017-10-27 02:46:13 +05:30
|
|
|
}
|
|
|
|
return repoCache[repoID]
|
|
|
|
}
|
|
|
|
|
2017-07-12 06:53:41 +05:30
|
|
|
func TestAPIViewRepo(t *testing.T) {
|
2019-11-26 04:51:37 +05:30
|
|
|
defer prepareTestEnv(t)()
|
2017-07-12 06:53:41 +05:30
|
|
|
|
2020-04-07 00:12:30 +05:30
|
|
|
var repo api.Repository
|
|
|
|
|
2017-07-12 06:53:41 +05:30
|
|
|
req := NewRequest(t, "GET", "/api/v1/repos/user2/repo1")
|
|
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &repo)
|
|
|
|
assert.EqualValues(t, 1, repo.ID)
|
|
|
|
assert.EqualValues(t, "repo1", repo.Name)
|
2021-06-18 04:54:55 +05:30
|
|
|
assert.EqualValues(t, 2, repo.Releases)
|
2020-04-07 00:12:30 +05:30
|
|
|
assert.EqualValues(t, 1, repo.OpenIssues)
|
|
|
|
assert.EqualValues(t, 3, repo.OpenPulls)
|
|
|
|
|
|
|
|
req = NewRequest(t, "GET", "/api/v1/repos/user12/repo10")
|
|
|
|
resp = MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &repo)
|
|
|
|
assert.EqualValues(t, 10, repo.ID)
|
|
|
|
assert.EqualValues(t, "repo10", repo.Name)
|
|
|
|
assert.EqualValues(t, 1, repo.OpenPulls)
|
|
|
|
assert.EqualValues(t, 1, repo.Forks)
|
|
|
|
|
|
|
|
req = NewRequest(t, "GET", "/api/v1/repos/user5/repo4")
|
|
|
|
resp = MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &repo)
|
|
|
|
assert.EqualValues(t, 4, repo.ID)
|
|
|
|
assert.EqualValues(t, "repo4", repo.Name)
|
|
|
|
assert.EqualValues(t, 1, repo.Stars)
|
2017-07-12 06:53:41 +05:30
|
|
|
}
|
2017-07-13 16:44:15 +05:30
|
|
|
|
|
|
|
func TestAPIOrgRepos(t *testing.T) {
|
2019-11-26 04:51:37 +05:30
|
|
|
defer prepareTestEnv(t)()
|
2021-11-24 15:19:20 +05:30
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
|
|
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
|
|
|
|
user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
|
2017-07-13 16:44:15 +05:30
|
|
|
// User3 is an Org. Check their repos.
|
2021-11-24 15:19:20 +05:30
|
|
|
sourceOrg := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User)
|
2017-07-13 16:44:15 +05:30
|
|
|
|
2021-11-24 15:19:20 +05:30
|
|
|
expectedResults := map[*user_model.User]struct {
|
2018-11-24 02:53:27 +05:30
|
|
|
count int
|
|
|
|
includesPrivate bool
|
|
|
|
}{
|
|
|
|
nil: {count: 1},
|
2020-02-15 09:59:06 +05:30
|
|
|
user: {count: 3, includesPrivate: true},
|
2018-11-24 02:53:27 +05:30
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2017-07-13 16:44:15 +05:30
|
|
|
}
|
|
|
|
}
|
2017-07-30 06:43:33 +05:30
|
|
|
|
|
|
|
func TestAPIGetRepoByIDUnauthorized(t *testing.T) {
|
2019-11-26 04:51:37 +05:30
|
|
|
defer prepareTestEnv(t)()
|
2021-11-24 15:19:20 +05:30
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User)
|
2018-09-10 21:45:52 +05:30
|
|
|
session := loginUser(t, user.Name)
|
|
|
|
token := getTokenForLoggedInUser(t, session)
|
|
|
|
req := NewRequestf(t, "GET", "/api/v1/repositories/2?token="+token)
|
|
|
|
session.MakeRequest(t, req, http.StatusNotFound)
|
2017-07-30 06:43:33 +05:30
|
|
|
}
|
2018-07-05 04:15:15 +05:30
|
|
|
|
|
|
|
func TestAPIRepoMigrate(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
ctxUserID, userID int64
|
|
|
|
cloneURL, repoName string
|
|
|
|
expectedStatus int
|
|
|
|
}{
|
2020-07-24 10:16:38 +05:30
|
|
|
{ctxUserID: 1, userID: 2, cloneURL: "https://github.com/go-gitea/test_repo.git", repoName: "git-admin", expectedStatus: http.StatusCreated},
|
|
|
|
{ctxUserID: 2, userID: 2, cloneURL: "https://github.com/go-gitea/test_repo.git", repoName: "git-own", expectedStatus: http.StatusCreated},
|
|
|
|
{ctxUserID: 2, userID: 1, cloneURL: "https://github.com/go-gitea/test_repo.git", repoName: "git-bad", expectedStatus: http.StatusForbidden},
|
|
|
|
{ctxUserID: 2, userID: 3, cloneURL: "https://github.com/go-gitea/test_repo.git", repoName: "git-org", expectedStatus: http.StatusCreated},
|
|
|
|
{ctxUserID: 2, userID: 6, cloneURL: "https://github.com/go-gitea/test_repo.git", repoName: "git-bad-org", expectedStatus: http.StatusForbidden},
|
2021-03-16 03:22:11 +05:30
|
|
|
{ctxUserID: 2, userID: 3, cloneURL: "https://localhost:3000/user/test_repo.git", repoName: "private-ip", expectedStatus: http.StatusUnprocessableEntity},
|
2020-11-29 06:07:58 +05:30
|
|
|
{ctxUserID: 2, userID: 3, cloneURL: "https://10.0.0.1/user/test_repo.git", repoName: "private-ip", expectedStatus: http.StatusUnprocessableEntity},
|
2018-07-05 04:15:15 +05:30
|
|
|
}
|
|
|
|
|
2019-11-26 04:51:37 +05:30
|
|
|
defer prepareTestEnv(t)()
|
2018-07-05 04:15:15 +05:30
|
|
|
for _, testCase := range testCases {
|
2021-11-24 15:19:20 +05:30
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: testCase.ctxUserID}).(*user_model.User)
|
2018-07-05 04:15:15 +05:30
|
|
|
session := loginUser(t, user.Name)
|
2018-09-10 21:45:52 +05:30
|
|
|
token := getTokenForLoggedInUser(t, session)
|
2020-09-11 03:59:19 +05:30
|
|
|
req := NewRequestWithJSON(t, "POST", "/api/v1/repos/migrate?token="+token, &api.MigrateRepoOptions{
|
|
|
|
CloneAddr: testCase.cloneURL,
|
|
|
|
RepoOwnerID: testCase.userID,
|
|
|
|
RepoName: testCase.repoName,
|
2018-07-05 04:15:15 +05:30
|
|
|
})
|
2020-09-04 22:58:36 +05:30
|
|
|
resp := MakeRequest(t, req, NoExpectedStatus)
|
|
|
|
if resp.Code == http.StatusUnprocessableEntity {
|
|
|
|
respJSON := map[string]string{}
|
|
|
|
DecodeJSON(t, resp, &respJSON)
|
2020-11-29 06:07:58 +05:30
|
|
|
switch respJSON["message"] {
|
|
|
|
case "Remote visit addressed rate limitation.":
|
2020-09-04 22:58:36 +05:30
|
|
|
t.Log("test hit github rate limitation")
|
2021-11-20 15:04:05 +05:30
|
|
|
case "You can not import from disallowed hosts.":
|
2020-11-29 06:07:58 +05:30
|
|
|
assert.EqualValues(t, "private-ip", testCase.repoName)
|
|
|
|
default:
|
2021-11-22 11:48:31 +05:30
|
|
|
assert.Failf(t, "unexpected error '%v' on url '%s'", respJSON["message"], testCase.cloneURL)
|
2020-09-04 22:58:36 +05:30
|
|
|
}
|
|
|
|
} else {
|
|
|
|
assert.EqualValues(t, testCase.expectedStatus, resp.Code)
|
|
|
|
}
|
2018-07-05 04:15:15 +05:30
|
|
|
}
|
|
|
|
}
|
2018-07-05 05:21:02 +05:30
|
|
|
|
2019-03-15 19:49:09 +05:30
|
|
|
func TestAPIRepoMigrateConflict(t *testing.T) {
|
|
|
|
onGiteaRun(t, testAPIRepoMigrateConflict)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAPIRepoMigrateConflict(t *testing.T, u *url.URL) {
|
|
|
|
username := "user2"
|
|
|
|
baseAPITestContext := NewAPITestContext(t, username, "repo1")
|
|
|
|
|
|
|
|
u.Path = baseAPITestContext.GitPath()
|
|
|
|
|
|
|
|
t.Run("Existing", func(t *testing.T) {
|
|
|
|
httpContext := baseAPITestContext
|
|
|
|
|
|
|
|
httpContext.Reponame = "repo-tmp-17"
|
2021-09-22 11:08:34 +05:30
|
|
|
dstPath, err := os.MkdirTemp("", httpContext.Reponame)
|
2019-03-15 19:49:09 +05:30
|
|
|
assert.NoError(t, err)
|
2020-08-12 01:35:34 +05:30
|
|
|
defer util.RemoveAll(dstPath)
|
2019-03-15 19:49:09 +05:30
|
|
|
t.Run("CreateRepo", doAPICreateRepository(httpContext, false))
|
|
|
|
|
2021-11-24 15:19:20 +05:30
|
|
|
user, err := user_model.GetUserByName(httpContext.Username)
|
2019-03-15 19:49:09 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
userID := user.ID
|
|
|
|
|
2020-07-24 10:16:38 +05:30
|
|
|
cloneURL := "https://github.com/go-gitea/test_repo.git"
|
2019-03-15 19:49:09 +05:30
|
|
|
|
|
|
|
req := NewRequestWithJSON(t, "POST", "/api/v1/repos/migrate?token="+httpContext.Token,
|
2020-09-11 03:59:19 +05:30
|
|
|
&api.MigrateRepoOptions{
|
|
|
|
CloneAddr: cloneURL,
|
|
|
|
RepoOwnerID: userID,
|
|
|
|
RepoName: httpContext.Reponame,
|
2019-03-15 19:49:09 +05:30
|
|
|
})
|
|
|
|
resp := httpContext.Session.MakeRequest(t, req, http.StatusConflict)
|
|
|
|
respJSON := map[string]string{}
|
|
|
|
DecodeJSON(t, resp, &respJSON)
|
2019-11-09 03:51:00 +05:30
|
|
|
assert.Equal(t, "The repository with the same name already exists.", respJSON["message"])
|
2019-03-15 19:49:09 +05:30
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-07-05 05:21:02 +05:30
|
|
|
func TestAPIOrgRepoCreate(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
ctxUserID int64
|
|
|
|
orgName, repoName string
|
|
|
|
expectedStatus int
|
|
|
|
}{
|
|
|
|
{ctxUserID: 1, orgName: "user3", repoName: "repo-admin", expectedStatus: http.StatusCreated},
|
|
|
|
{ctxUserID: 2, orgName: "user3", repoName: "repo-own", expectedStatus: http.StatusCreated},
|
|
|
|
{ctxUserID: 2, orgName: "user6", repoName: "repo-bad-org", expectedStatus: http.StatusForbidden},
|
2019-11-20 16:57:49 +05:30
|
|
|
{ctxUserID: 28, orgName: "user3", repoName: "repo-creator", expectedStatus: http.StatusCreated},
|
|
|
|
{ctxUserID: 28, orgName: "user6", repoName: "repo-not-creator", expectedStatus: http.StatusForbidden},
|
2018-07-05 05:21:02 +05:30
|
|
|
}
|
|
|
|
|
2019-11-26 04:51:37 +05:30
|
|
|
defer prepareTestEnv(t)()
|
2018-07-05 05:21:02 +05:30
|
|
|
for _, testCase := range testCases {
|
2021-11-24 15:19:20 +05:30
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: testCase.ctxUserID}).(*user_model.User)
|
2018-07-05 05:21:02 +05:30
|
|
|
session := loginUser(t, user.Name)
|
2018-09-10 21:45:52 +05:30
|
|
|
token := getTokenForLoggedInUser(t, session)
|
|
|
|
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/org/%s/repos?token="+token, testCase.orgName), &api.CreateRepoOption{
|
2018-07-05 05:21:02 +05:30
|
|
|
Name: testCase.repoName,
|
|
|
|
})
|
|
|
|
session.MakeRequest(t, req, testCase.expectedStatus)
|
|
|
|
}
|
|
|
|
}
|
2019-03-15 19:49:09 +05:30
|
|
|
|
|
|
|
func TestAPIRepoCreateConflict(t *testing.T) {
|
|
|
|
onGiteaRun(t, testAPIRepoCreateConflict)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAPIRepoCreateConflict(t *testing.T, u *url.URL) {
|
|
|
|
username := "user2"
|
|
|
|
baseAPITestContext := NewAPITestContext(t, username, "repo1")
|
|
|
|
|
|
|
|
u.Path = baseAPITestContext.GitPath()
|
|
|
|
|
|
|
|
t.Run("Existing", func(t *testing.T) {
|
|
|
|
httpContext := baseAPITestContext
|
|
|
|
|
|
|
|
httpContext.Reponame = "repo-tmp-17"
|
2021-09-22 11:08:34 +05:30
|
|
|
dstPath, err := os.MkdirTemp("", httpContext.Reponame)
|
2019-03-15 19:49:09 +05:30
|
|
|
assert.NoError(t, err)
|
2020-08-12 01:35:34 +05:30
|
|
|
defer util.RemoveAll(dstPath)
|
2019-03-15 19:49:09 +05:30
|
|
|
t.Run("CreateRepo", doAPICreateRepository(httpContext, false))
|
|
|
|
|
|
|
|
req := NewRequestWithJSON(t, "POST", "/api/v1/user/repos?token="+httpContext.Token,
|
|
|
|
&api.CreateRepoOption{
|
|
|
|
Name: httpContext.Reponame,
|
|
|
|
})
|
|
|
|
resp := httpContext.Session.MakeRequest(t, req, http.StatusConflict)
|
|
|
|
respJSON := map[string]string{}
|
|
|
|
DecodeJSON(t, resp, &respJSON)
|
|
|
|
assert.Equal(t, respJSON["message"], "The repository with the same name already exists.")
|
|
|
|
})
|
|
|
|
}
|
2020-01-31 21:19:04 +05:30
|
|
|
|
|
|
|
func TestAPIRepoTransfer(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
ctxUserID int64
|
|
|
|
newOwner string
|
|
|
|
teams *[]int64
|
|
|
|
expectedStatus int
|
|
|
|
}{
|
2021-03-01 06:17:30 +05:30
|
|
|
// Disclaimer for test story: "user1" is an admin, "user2" is normal user and part of in owner team of org "user3"
|
|
|
|
|
|
|
|
// Transfer to a user with teams in another org should fail
|
2020-01-31 21:19:04 +05:30
|
|
|
{ctxUserID: 1, newOwner: "user3", teams: &[]int64{5}, expectedStatus: http.StatusForbidden},
|
2021-03-01 06:17:30 +05:30
|
|
|
// Transfer to a user with non-existent team IDs should fail
|
|
|
|
{ctxUserID: 1, newOwner: "user2", teams: &[]int64{2}, expectedStatus: http.StatusUnprocessableEntity},
|
|
|
|
// Transfer should go through
|
2020-01-31 21:19:04 +05:30
|
|
|
{ctxUserID: 1, newOwner: "user3", teams: &[]int64{2}, expectedStatus: http.StatusAccepted},
|
2021-03-01 06:17:30 +05:30
|
|
|
// Let user transfer it back to himself
|
|
|
|
{ctxUserID: 2, newOwner: "user2", expectedStatus: http.StatusAccepted},
|
|
|
|
// And revert transfer
|
|
|
|
{ctxUserID: 2, newOwner: "user3", teams: &[]int64{2}, expectedStatus: http.StatusAccepted},
|
|
|
|
// Cannot start transfer to an existing repo
|
|
|
|
{ctxUserID: 2, newOwner: "user3", teams: nil, expectedStatus: http.StatusUnprocessableEntity},
|
|
|
|
// Start transfer, repo is now in pending transfer mode
|
|
|
|
{ctxUserID: 2, newOwner: "user6", teams: nil, expectedStatus: http.StatusCreated},
|
2020-01-31 21:19:04 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
defer prepareTestEnv(t)()
|
|
|
|
|
2022-01-20 23:16:10 +05:30
|
|
|
// create repo to move
|
2021-11-24 15:19:20 +05:30
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
|
2020-01-31 21:19:04 +05:30
|
|
|
session := loginUser(t, user.Name)
|
|
|
|
token := getTokenForLoggedInUser(t, session)
|
|
|
|
repoName := "moveME"
|
2021-06-18 20:16:22 +05:30
|
|
|
apiRepo := new(api.Repository)
|
2020-01-31 21:19:04 +05:30
|
|
|
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/user/repos?token=%s", token), &api.CreateRepoOption{
|
|
|
|
Name: repoName,
|
|
|
|
Description: "repo move around",
|
|
|
|
Private: false,
|
|
|
|
Readme: "Default",
|
|
|
|
AutoInit: true,
|
|
|
|
})
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusCreated)
|
2021-06-18 20:16:22 +05:30
|
|
|
DecodeJSON(t, resp, apiRepo)
|
2020-01-31 21:19:04 +05:30
|
|
|
|
2022-01-20 23:16:10 +05:30
|
|
|
// start testing
|
2020-01-31 21:19:04 +05:30
|
|
|
for _, testCase := range testCases {
|
2021-11-24 15:19:20 +05:30
|
|
|
user = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: testCase.ctxUserID}).(*user_model.User)
|
2021-12-10 06:57:50 +05:30
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiRepo.ID}).(*repo_model.Repository)
|
2020-01-31 21:19:04 +05:30
|
|
|
session = loginUser(t, user.Name)
|
|
|
|
token = getTokenForLoggedInUser(t, session)
|
|
|
|
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer?token=%s", repo.OwnerName, repo.Name, token), &api.TransferRepoOption{
|
|
|
|
NewOwner: testCase.newOwner,
|
|
|
|
TeamIDs: testCase.teams,
|
|
|
|
})
|
|
|
|
session.MakeRequest(t, req, testCase.expectedStatus)
|
|
|
|
}
|
|
|
|
|
2022-01-20 23:16:10 +05:30
|
|
|
// cleanup
|
2021-12-10 06:57:50 +05:30
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiRepo.ID}).(*repo_model.Repository)
|
2020-01-31 21:19:04 +05:30
|
|
|
_ = models.DeleteRepository(user, repo.OwnerID, repo.ID)
|
|
|
|
}
|
2021-06-17 19:32:34 +05:30
|
|
|
|
2021-12-24 09:56:52 +05:30
|
|
|
func transfer(t *testing.T) *repo_model.Repository {
|
2022-01-20 23:16:10 +05:30
|
|
|
// create repo to move
|
2021-12-24 09:56:52 +05:30
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
|
|
|
session := loginUser(t, user.Name)
|
|
|
|
token := getTokenForLoggedInUser(t, session)
|
|
|
|
repoName := "moveME"
|
|
|
|
apiRepo := new(api.Repository)
|
|
|
|
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/user/repos?token=%s", token), &api.CreateRepoOption{
|
|
|
|
Name: repoName,
|
|
|
|
Description: "repo move around",
|
|
|
|
Private: false,
|
|
|
|
Readme: "Default",
|
|
|
|
AutoInit: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusCreated)
|
|
|
|
DecodeJSON(t, resp, apiRepo)
|
|
|
|
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiRepo.ID}).(*repo_model.Repository)
|
|
|
|
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer?token=%s", repo.OwnerName, repo.Name, token), &api.TransferRepoOption{
|
|
|
|
NewOwner: "user4",
|
|
|
|
})
|
|
|
|
session.MakeRequest(t, req, http.StatusCreated)
|
|
|
|
|
|
|
|
return repo
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAPIAcceptTransfer(t *testing.T) {
|
|
|
|
defer prepareTestEnv(t)()
|
|
|
|
|
|
|
|
repo := transfer(t)
|
|
|
|
|
|
|
|
// try to accept with not authorized user
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
token := getTokenForLoggedInUser(t, session)
|
|
|
|
req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/reject?token=%s", repo.OwnerName, repo.Name, token))
|
|
|
|
session.MakeRequest(t, req, http.StatusForbidden)
|
|
|
|
|
|
|
|
// try to accept repo that's not marked as transferred
|
|
|
|
req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/accept?token=%s", "user2", "repo1", token))
|
|
|
|
session.MakeRequest(t, req, http.StatusNotFound)
|
|
|
|
|
|
|
|
// accept transfer
|
|
|
|
session = loginUser(t, "user4")
|
|
|
|
token = getTokenForLoggedInUser(t, session)
|
|
|
|
|
|
|
|
req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/accept?token=%s", repo.OwnerName, repo.Name, token))
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusAccepted)
|
|
|
|
apiRepo := new(api.Repository)
|
|
|
|
DecodeJSON(t, resp, apiRepo)
|
|
|
|
assert.Equal(t, "user4", apiRepo.Owner.UserName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAPIRejectTransfer(t *testing.T) {
|
|
|
|
defer prepareTestEnv(t)()
|
|
|
|
|
|
|
|
repo := transfer(t)
|
|
|
|
|
|
|
|
// try to reject with not authorized user
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
token := getTokenForLoggedInUser(t, session)
|
|
|
|
req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/reject?token=%s", repo.OwnerName, repo.Name, token))
|
|
|
|
session.MakeRequest(t, req, http.StatusForbidden)
|
|
|
|
|
|
|
|
// try to reject repo that's not marked as transferred
|
|
|
|
req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/reject?token=%s", "user2", "repo1", token))
|
|
|
|
session.MakeRequest(t, req, http.StatusNotFound)
|
|
|
|
|
|
|
|
// reject transfer
|
|
|
|
session = loginUser(t, "user4")
|
|
|
|
token = getTokenForLoggedInUser(t, session)
|
|
|
|
|
|
|
|
req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/reject?token=%s", repo.OwnerName, repo.Name, token))
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
apiRepo := new(api.Repository)
|
|
|
|
DecodeJSON(t, resp, apiRepo)
|
|
|
|
assert.Equal(t, "user2", apiRepo.Owner.UserName)
|
|
|
|
}
|
|
|
|
|
2021-07-05 20:59:08 +05:30
|
|
|
func TestAPIGenerateRepo(t *testing.T) {
|
|
|
|
defer prepareTestEnv(t)()
|
|
|
|
|
2021-11-24 15:19:20 +05:30
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
|
2021-07-05 20:59:08 +05:30
|
|
|
session := loginUser(t, user.Name)
|
|
|
|
token := getTokenForLoggedInUser(t, session)
|
|
|
|
|
2021-12-10 06:57:50 +05:30
|
|
|
templateRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 44}).(*repo_model.Repository)
|
2021-07-05 20:59:08 +05:30
|
|
|
|
|
|
|
// user
|
|
|
|
repo := new(api.Repository)
|
|
|
|
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/generate?token=%s", templateRepo.OwnerName, templateRepo.Name, token), &api.GenerateRepoOption{
|
|
|
|
Owner: user.Name,
|
|
|
|
Name: "new-repo",
|
|
|
|
Description: "test generate repo",
|
|
|
|
Private: false,
|
|
|
|
GitContent: true,
|
|
|
|
})
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusCreated)
|
|
|
|
DecodeJSON(t, resp, repo)
|
|
|
|
|
|
|
|
assert.Equal(t, "new-repo", repo.Name)
|
|
|
|
|
|
|
|
// org
|
|
|
|
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/generate?token=%s", templateRepo.OwnerName, templateRepo.Name, token), &api.GenerateRepoOption{
|
|
|
|
Owner: "user3",
|
|
|
|
Name: "new-repo",
|
|
|
|
Description: "test generate repo",
|
|
|
|
Private: false,
|
|
|
|
GitContent: true,
|
|
|
|
})
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusCreated)
|
|
|
|
DecodeJSON(t, resp, repo)
|
|
|
|
|
|
|
|
assert.Equal(t, "new-repo", repo.Name)
|
|
|
|
}
|
|
|
|
|
2021-06-17 19:32:34 +05:30
|
|
|
func TestAPIRepoGetReviewers(t *testing.T) {
|
|
|
|
defer prepareTestEnv(t)()
|
2021-11-24 15:19:20 +05:30
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
2021-06-17 19:32:34 +05:30
|
|
|
session := loginUser(t, user.Name)
|
|
|
|
token := getTokenForLoggedInUser(t, session)
|
2021-12-10 06:57:50 +05:30
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
2021-06-17 19:32:34 +05:30
|
|
|
|
|
|
|
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/reviewers?token=%s", user.Name, repo.Name, token)
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
var reviewers []*api.User
|
|
|
|
DecodeJSON(t, resp, &reviewers)
|
|
|
|
assert.Len(t, reviewers, 4)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAPIRepoGetAssignees(t *testing.T) {
|
|
|
|
defer prepareTestEnv(t)()
|
2021-11-24 15:19:20 +05:30
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
2021-06-17 19:32:34 +05:30
|
|
|
session := loginUser(t, user.Name)
|
|
|
|
token := getTokenForLoggedInUser(t, session)
|
2021-12-10 06:57:50 +05:30
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
2021-06-17 19:32:34 +05:30
|
|
|
|
|
|
|
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/assignees?token=%s", user.Name, repo.Name, token)
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
var assignees []*api.User
|
|
|
|
DecodeJSON(t, resp, &assignees)
|
|
|
|
assert.Len(t, assignees, 1)
|
|
|
|
}
|