|
| 1 | +// Copyright 2025 The Gitea Authors. All rights reserved. |
| 2 | +// SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +package integration |
| 5 | + |
| 6 | +import ( |
| 7 | + "net/http" |
| 8 | + "testing" |
| 9 | + |
| 10 | + "code.gitea.io/gitea/modules/setting" |
| 11 | + api "code.gitea.io/gitea/modules/structs" |
| 12 | + "code.gitea.io/gitea/modules/test" |
| 13 | + "code.gitea.io/gitea/tests" |
| 14 | + |
| 15 | + "github.com/stretchr/testify/assert" |
| 16 | +) |
| 17 | + |
| 18 | +func testActionUserSignIn(t *testing.T) { |
| 19 | + req := NewRequest(t, "GET", "/api/v1/user"). |
| 20 | + AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a") |
| 21 | + resp := MakeRequest(t, req, http.StatusOK) |
| 22 | + |
| 23 | + var u api.User |
| 24 | + DecodeJSON(t, resp, &u) |
| 25 | + assert.Equal(t, "gitea-actions", u.UserName) |
| 26 | +} |
| 27 | + |
| 28 | +func testActionUserAccessPublicRepo(t *testing.T) { |
| 29 | + req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/raw/README.md"). |
| 30 | + AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a") |
| 31 | + resp := MakeRequest(t, req, http.StatusOK) |
| 32 | + assert.Equal(t, "file", resp.Header().Get("x-gitea-object-type")) |
| 33 | + |
| 34 | + defer test.MockVariableValue(&setting.Service.RequireSignInViewStrict, true)() |
| 35 | + |
| 36 | + req = NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/raw/README.md"). |
| 37 | + AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a") |
| 38 | + resp = MakeRequest(t, req, http.StatusOK) |
| 39 | + assert.Equal(t, "file", resp.Header().Get("x-gitea-object-type")) |
| 40 | +} |
| 41 | + |
| 42 | +func testActionUserNoAccessOtherPrivateRepo(t *testing.T) { |
| 43 | + req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo2/raw/README.md"). |
| 44 | + AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a") |
| 45 | + MakeRequest(t, req, http.StatusNotFound) |
| 46 | +} |
| 47 | + |
| 48 | +func TestActionUserAccessPermission(t *testing.T) { |
| 49 | + defer tests.PrepareTestEnv(t)() |
| 50 | + |
| 51 | + t.Run("ActionUserSignIn", testActionUserSignIn) |
| 52 | + t.Run("ActionUserAccessPublicRepo", testActionUserAccessPublicRepo) |
| 53 | + t.Run("ActionUserNoAccessOtherPrivateRepo", testActionUserNoAccessOtherPrivateRepo) |
| 54 | +} |
0 commit comments