summaryrefslogtreecommitdiffstats
path: root/tests/integration/api_repo_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'tests/integration/api_repo_test.go')
-rw-r--r--tests/integration/api_repo_test.go50
1 files changed, 22 insertions, 28 deletions
diff --git a/tests/integration/api_repo_test.go b/tests/integration/api_repo_test.go
index 76850fb827..76ceb779e0 100644
--- a/tests/integration/api_repo_test.go
+++ b/tests/integration/api_repo_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ auth_model "code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/models/db"
access_model "code.gitea.io/gitea/models/perm/access"
repo_model "code.gitea.io/gitea/models/repo"
@@ -286,24 +287,17 @@ func TestAPIOrgRepos(t *testing.T) {
count int
includesPrivate bool
}{
- nil: {count: 1},
+ user: {count: 1},
user: {count: 3, 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)
- }
+ testName := fmt.Sprintf("LoggedUser%d", userToLogin.ID)
+ session := loginUser(t, userToLogin.Name)
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadOrg)
+
t.Run(testName, func(t *testing.T) {
req := NewRequestf(t, "GET", "/api/v1/orgs/%s/repos?token="+token, sourceOrg.Name)
resp := MakeRequest(t, req, http.StatusOK)
@@ -324,7 +318,7 @@ func TestAPIGetRepoByIDUnauthorized(t *testing.T) {
defer tests.PrepareTestEnv(t)()
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4})
session := loginUser(t, user.Name)
- token := getTokenForLoggedInUser(t, session)
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeRepo)
req := NewRequestf(t, "GET", "/api/v1/repositories/2?token="+token)
MakeRequest(t, req, http.StatusNotFound)
}
@@ -348,7 +342,7 @@ func TestAPIRepoMigrate(t *testing.T) {
for _, testCase := range testCases {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: testCase.ctxUserID})
session := loginUser(t, user.Name)
- token := getTokenForLoggedInUser(t, session)
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeRepo)
req := NewRequestWithJSON(t, "POST", "/api/v1/repos/migrate?token="+token, &api.MigrateRepoOptions{
CloneAddr: testCase.cloneURL,
RepoOwnerID: testCase.userID,
@@ -378,7 +372,7 @@ func TestAPIRepoMigrateConflict(t *testing.T) {
func testAPIRepoMigrateConflict(t *testing.T, u *url.URL) {
username := "user2"
- baseAPITestContext := NewAPITestContext(t, username, "repo1")
+ baseAPITestContext := NewAPITestContext(t, username, "repo1", auth_model.AccessTokenScopeRepo)
u.Path = baseAPITestContext.GitPath()
@@ -413,7 +407,7 @@ func TestAPIMirrorSyncNonMirrorRepo(t *testing.T) {
defer tests.PrepareTestEnv(t)()
session := loginUser(t, "user2")
- token := getTokenForLoggedInUser(t, session)
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeRepo)
var repo api.Repository
req := NewRequest(t, "GET", "/api/v1/repos/user2/repo1")
@@ -445,7 +439,7 @@ func TestAPIOrgRepoCreate(t *testing.T) {
for _, testCase := range testCases {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: testCase.ctxUserID})
session := loginUser(t, user.Name)
- token := getTokenForLoggedInUser(t, session)
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeAdminOrg)
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/org/%s/repos?token="+token, testCase.orgName), &api.CreateRepoOption{
Name: testCase.repoName,
})
@@ -459,7 +453,7 @@ func TestAPIRepoCreateConflict(t *testing.T) {
func testAPIRepoCreateConflict(t *testing.T, u *url.URL) {
username := "user2"
- baseAPITestContext := NewAPITestContext(t, username, "repo1")
+ baseAPITestContext := NewAPITestContext(t, username, "repo1", auth_model.AccessTokenScopeRepo)
u.Path = baseAPITestContext.GitPath()
@@ -509,7 +503,7 @@ func TestAPIRepoTransfer(t *testing.T) {
// create repo to move
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
session := loginUser(t, user.Name)
- token := getTokenForLoggedInUser(t, session)
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeRepo)
repoName := "moveME"
apiRepo := new(api.Repository)
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/user/repos?token=%s", token), &api.CreateRepoOption{
@@ -527,7 +521,7 @@ func TestAPIRepoTransfer(t *testing.T) {
user = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: testCase.ctxUserID})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiRepo.ID})
session = loginUser(t, user.Name)
- token = getTokenForLoggedInUser(t, session)
+ token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeRepo)
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,
@@ -544,7 +538,7 @@ func transfer(t *testing.T) *repo_model.Repository {
// create repo to move
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
session := loginUser(t, user.Name)
- token := getTokenForLoggedInUser(t, session)
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeRepo)
repoName := "moveME"
apiRepo := new(api.Repository)
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/user/repos?token=%s", token), &api.CreateRepoOption{
@@ -574,7 +568,7 @@ func TestAPIAcceptTransfer(t *testing.T) {
// try to accept with not authorized user
session := loginUser(t, "user2")
- token := getTokenForLoggedInUser(t, session)
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeRepo)
req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/reject?token=%s", repo.OwnerName, repo.Name, token))
MakeRequest(t, req, http.StatusForbidden)
@@ -584,7 +578,7 @@ func TestAPIAcceptTransfer(t *testing.T) {
// accept transfer
session = loginUser(t, "user4")
- token = getTokenForLoggedInUser(t, session)
+ token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeRepo)
req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/accept?token=%s", repo.OwnerName, repo.Name, token))
resp := MakeRequest(t, req, http.StatusAccepted)
@@ -600,7 +594,7 @@ func TestAPIRejectTransfer(t *testing.T) {
// try to reject with not authorized user
session := loginUser(t, "user2")
- token := getTokenForLoggedInUser(t, session)
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeRepo)
req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/reject?token=%s", repo.OwnerName, repo.Name, token))
MakeRequest(t, req, http.StatusForbidden)
@@ -610,7 +604,7 @@ func TestAPIRejectTransfer(t *testing.T) {
// reject transfer
session = loginUser(t, "user4")
- token = getTokenForLoggedInUser(t, session)
+ token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeRepo)
req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/reject?token=%s", repo.OwnerName, repo.Name, token))
resp := MakeRequest(t, req, http.StatusOK)
@@ -624,7 +618,7 @@ func TestAPIGenerateRepo(t *testing.T) {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
session := loginUser(t, user.Name)
- token := getTokenForLoggedInUser(t, session)
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeRepo)
templateRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 44})
@@ -660,7 +654,7 @@ func TestAPIRepoGetReviewers(t *testing.T) {
defer tests.PrepareTestEnv(t)()
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
session := loginUser(t, user.Name)
- token := getTokenForLoggedInUser(t, session)
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeRepo)
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/reviewers?token=%s", user.Name, repo.Name, token)
@@ -674,7 +668,7 @@ func TestAPIRepoGetAssignees(t *testing.T) {
defer tests.PrepareTestEnv(t)()
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
session := loginUser(t, user.Name)
- token := getTokenForLoggedInUser(t, session)
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeRepo)
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/assignees?token=%s", user.Name, repo.Name, token)