mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-22 11:03:57 +09:00
Partial backport of https://github.com/go-gitea/gitea/pull/39690 with only its public-only token checks, without the refactor. 1. Admin, org owner and repo or org creation APIs reject public-only tokens. 1. Profile and org pages hide private repos and limited owners from public-only tokens. 1. Heatmap API, OIDC userinfo and OCI blob mounts respect public-only tokens. Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: bircni <bircni@icloud.com>
43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
// Copyright 2018 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
|
|
activities_model "gitea.dev/models/activities"
|
|
auth_model "gitea.dev/models/auth"
|
|
"gitea.dev/modules/timeutil"
|
|
"gitea.dev/tests"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestUserHeatmap(t *testing.T) {
|
|
defer tests.PrepareTestEnv(t)()
|
|
adminUsername := "user1"
|
|
normalUsername := "user2"
|
|
token := getUserToken(t, adminUsername, auth_model.AccessTokenScopeReadUser)
|
|
|
|
fakeNow := time.Date(2011, 10, 20, 0, 0, 0, 0, time.Local)
|
|
timeutil.MockSet(fakeNow)
|
|
defer timeutil.MockUnset()
|
|
|
|
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/users/%s/heatmap", normalUsername)).
|
|
AddTokenAuth(token)
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
heatmap := DecodeJSON(t, resp, []*activities_model.UserHeatmapData{})
|
|
var dummyheatmap []*activities_model.UserHeatmapData
|
|
dummyheatmap = append(dummyheatmap, &activities_model.UserHeatmapData{Timestamp: 1603227600, Contributions: 1})
|
|
|
|
assert.Equal(t, dummyheatmap, heatmap)
|
|
|
|
publicOnlyToken := getUserToken(t, normalUsername, auth_model.AccessTokenScopeReadUser, auth_model.AccessTokenScopePublicOnly)
|
|
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/users/%s/heatmap", normalUsername)).AddTokenAuth(publicOnlyToken)
|
|
assert.Empty(t, DecodeJSON(t, MakeRequest(t, req, http.StatusOK), []*activities_model.UserHeatmapData{}))
|
|
}
|