forked from forgejo/forgejo
Merge pull request 'Disabling Stars should disable the routes too' (#2471) from algernon/forgejo:stars/disable-routes into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2471 Reviewed-by: Otto <otto@codeberg.org> Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
commit
2855727c85
6 changed files with 96 additions and 15 deletions
|
@ -9,7 +9,10 @@ import (
|
|||
"testing"
|
||||
|
||||
auth_model "code.gitea.io/gitea/models/auth"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/routers"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -25,12 +28,26 @@ func TestAPIStar(t *testing.T) {
|
|||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadUser)
|
||||
tokenWithUserScope := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteUser, auth_model.AccessTokenScopeWriteRepository)
|
||||
|
||||
assertDisabledStarsNotFound := func(t *testing.T, req *RequestWrapper) {
|
||||
t.Helper()
|
||||
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
defer test.MockVariableValue(&setting.Repository.DisableStars, true)()
|
||||
defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())()
|
||||
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
}
|
||||
|
||||
t.Run("Star", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "PUT", fmt.Sprintf("/api/v1/user/starred/%s", repo)).
|
||||
AddTokenAuth(tokenWithUserScope)
|
||||
MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
t.Run("disabled stars", func(t *testing.T) {
|
||||
assertDisabledStarsNotFound(t, req)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("GetStarredRepos", func(t *testing.T) {
|
||||
|
@ -46,6 +63,10 @@ func TestAPIStar(t *testing.T) {
|
|||
DecodeJSON(t, resp, &repos)
|
||||
assert.Len(t, repos, 1)
|
||||
assert.Equal(t, repo, repos[0].FullName)
|
||||
|
||||
t.Run("disabled stars", func(t *testing.T) {
|
||||
assertDisabledStarsNotFound(t, req)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("GetMyStarredRepos", func(t *testing.T) {
|
||||
|
@ -61,6 +82,10 @@ func TestAPIStar(t *testing.T) {
|
|||
DecodeJSON(t, resp, &repos)
|
||||
assert.Len(t, repos, 1)
|
||||
assert.Equal(t, repo, repos[0].FullName)
|
||||
|
||||
t.Run("disabled stars", func(t *testing.T) {
|
||||
assertDisabledStarsNotFound(t, req)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("IsStarring", func(t *testing.T) {
|
||||
|
@ -73,6 +98,10 @@ func TestAPIStar(t *testing.T) {
|
|||
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/user/starred/%s", repo+"notexisting")).
|
||||
AddTokenAuth(tokenWithUserScope)
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
t.Run("disabled stars", func(t *testing.T) {
|
||||
assertDisabledStarsNotFound(t, req)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("Unstar", func(t *testing.T) {
|
||||
|
@ -81,5 +110,9 @@ func TestAPIStar(t *testing.T) {
|
|||
req := NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/user/starred/%s", repo)).
|
||||
AddTokenAuth(tokenWithUserScope)
|
||||
MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
t.Run("disabled stars", func(t *testing.T) {
|
||||
assertDisabledStarsNotFound(t, req)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -16,7 +16,9 @@ import (
|
|||
unit_model "code.gitea.io/gitea/models/unit"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/routers"
|
||||
files_service "code.gitea.io/gitea/services/repository/files"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
|
@ -107,6 +109,14 @@ func TestBadges(t *testing.T) {
|
|||
resp := MakeRequest(t, req, http.StatusSeeOther)
|
||||
|
||||
assertBadge(t, resp, "stars-0-blue")
|
||||
|
||||
t.Run("disabled stars", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
defer test.MockVariableValue(&setting.Repository.DisableStars, true)()
|
||||
defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())()
|
||||
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("Issues", func(t *testing.T) {
|
||||
|
|
|
@ -9,6 +9,9 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/routers"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -80,3 +83,26 @@ func TestRepoStarUnstarUI(t *testing.T) {
|
|||
func TestRepoWatchUnwatchUI(t *testing.T) {
|
||||
testRepoStarringOrWatching(t, "watch", "watchers")
|
||||
}
|
||||
|
||||
func TestDisabledStars(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer test.MockVariableValue(&setting.Repository.DisableStars, true)()
|
||||
defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())()
|
||||
|
||||
t.Run("repo star, unstar", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "POST", "/user2/repo1/action/star")
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
req = NewRequest(t, "POST", "/user2/repo1/action/unstar")
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
})
|
||||
|
||||
t.Run("repo stargazers", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", "/user2/repo1/stars")
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue