mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-19 16:18:11 +00:00
The token a request authenticated with now lives on the doer, so permission and visibility checks apply its scope from the doer alone. Replaces https://github.com/go-gitea/gitea/pull/39167, following https://github.com/go-gitea/gitea/pull/39167#issuecomment-6063839619. 1. Public-only tokens get 404 instead of 403 for hidden users, orgs and repos, like GitHub. 2. Org ownership, site admin, repo and org creation, generation and transfer endpoints reject public-only tokens. 3. API pull request responses set `head.repo` to `null` and `head.repo_id` to `-1` when the caller cannot see the head repository. 4. Public-only tokens see org memberships like anonymous callers, so concealed members stay hidden. 5. Site admin access in activity feeds, follower lists, org members, Actions run lists and packages needs a session or an `all`-scoped token. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
auth_model "gitea.dev/models/auth"
|
|
"gitea.dev/tests"
|
|
)
|
|
|
|
func TestRepoWebTokenScopes(t *testing.T) {
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
miscToken := getUserToken(t, "user2", auth_model.AccessTokenScopeReadMisc)
|
|
publicOnlyToken := getUserToken(t, "user2", auth_model.AccessTokenScopeReadRepository, auth_model.AccessTokenScopePublicOnly)
|
|
readToken := getUserToken(t, "user2", auth_model.AccessTokenScopeReadRepository)
|
|
|
|
for _, test := range []struct {
|
|
name string
|
|
url string
|
|
}{
|
|
{"repository home", "/user2/repo2"},
|
|
{"workflow badge", "/org3/repo3/actions/workflows/test.yml/badge.svg"},
|
|
} {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
assertBasicAuthStatus(t, test.url, miscToken, http.StatusForbidden)
|
|
assertBasicAuthStatus(t, test.url, publicOnlyToken, http.StatusNotFound)
|
|
assertBasicAuthStatus(t, test.url, readToken, http.StatusOK)
|
|
})
|
|
}
|
|
|
|
assertBasicAuthStatus(t, "/user2/repo1/actions/workflows/test.yml/badge.svg", publicOnlyToken, http.StatusOK)
|
|
}
|
|
|
|
func assertBasicAuthStatus(t *testing.T, url, token string, status int) {
|
|
t.Helper()
|
|
req := NewRequest(t, http.MethodGet, url)
|
|
req.SetBasicAuth("user2", token)
|
|
MakeRequest(t, req, status)
|
|
}
|