2017-07-12 04:23:41 +03:00
|
|
|
// Copyright 2017 The Gogs Authors. All rights reserved.
|
2024-02-25 13:58:23 +03:00
|
|
|
// Copyright 2024 The Forgejo Authors c/o Codeberg e.V.. All rights reserved.
|
2022-11-27 21:20:29 +03:00
|
|
|
// SPDX-License-Identifier: MIT
|
2017-07-12 04:23:41 +03:00
|
|
|
|
2022-09-02 22:18:23 +03:00
|
|
|
package integration
|
2017-07-12 04:23:41 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2024-02-25 13:58:23 +03:00
|
|
|
"net/url"
|
2017-07-12 04:23:41 +03:00
|
|
|
"testing"
|
|
|
|
|
2024-02-25 13:58:23 +03:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2019-05-11 13:21:34 +03:00
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2024-02-25 13:58:23 +03:00
|
|
|
"code.gitea.io/gitea/modules/test"
|
|
|
|
"code.gitea.io/gitea/routers"
|
2022-09-02 22:18:23 +03:00
|
|
|
"code.gitea.io/gitea/tests"
|
2017-07-12 04:23:41 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCreateForkNoLogin(t *testing.T) {
|
2022-09-02 22:18:23 +03:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2017-07-12 04:23:41 +03:00
|
|
|
req := NewRequestWithJSON(t, "POST", "/api/v1/repos/user2/repo1/forks", &api.CreateForkOption{})
|
|
|
|
MakeRequest(t, req, http.StatusUnauthorized)
|
|
|
|
}
|
2024-02-25 13:58:23 +03:00
|
|
|
|
|
|
|
func TestAPIDisabledForkRepo(t *testing.T) {
|
|
|
|
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
|
|
|
defer test.MockVariableValue(&setting.Repository.DisableForks, true)()
|
|
|
|
defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())()
|
|
|
|
|
|
|
|
t.Run("fork listing", func(t *testing.T) {
|
|
|
|
defer tests.PrintCurrentTest(t)()
|
|
|
|
|
|
|
|
req := NewRequest(t, "GET", "/api/v1/repos/user2/repo1/forks")
|
|
|
|
MakeRequest(t, req, http.StatusNotFound)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("forking", func(t *testing.T) {
|
|
|
|
defer tests.PrintCurrentTest(t)()
|
|
|
|
|
|
|
|
session := loginUser(t, "user5")
|
|
|
|
token := getTokenForLoggedInUser(t, session)
|
|
|
|
|
|
|
|
req := NewRequestWithJSON(t, "POST", "/api/v1/repos/user2/repo1/forks", &api.CreateForkOption{}).AddTokenAuth(token)
|
|
|
|
session.MakeRequest(t, req, http.StatusNotFound)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|