Files
upstream-gitea/tests/integration/repo_home_token_scope_test.go
upstream-mirror 52ae0c5802
Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
snapshot of https://github.com/go-gitea/gitea.git (main, 2026-09-15; blobs > 131072B omitted)
2026-09-15 21:41:59 +05:00

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.StatusForbidden)
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)
}