mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-04-26 22:36:59 -04:00
Some checks are pending
/ release (push) Waiting to run
testing-integration / test-unit (push) Waiting to run
testing-integration / test-sqlite (push) Waiting to run
testing-integration / test-mariadb (v10.6) (push) Waiting to run
testing-integration / test-mariadb (v11.8) (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions
Replace the anti-CSRF token with a [cross origin protection by Go](https://go.dev/doc/go1.25#nethttppkgnethttp) that uses a stateless way of verifying if a request was cross origin or not. This allows is to remove al lot of code and replace it with a few lines of code and we no longer have to hand roll this protection. The new protection uses indicators by the browser itself that indicate if the request is cross-origin, thus we no longer have to take care of ensuring the generated CSRF token is passed back to the server any request by the the browser will have send this indicator. Resolves forgejo/forgejo#3538 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9830 Reviewed-by: oliverpool <oliverpool@noreply.codeberg.org> Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
123 lines
3.9 KiB
Go
123 lines
3.9 KiB
Go
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package integration
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"testing"
|
|
|
|
actions_model "forgejo.org/models/actions"
|
|
repo_model "forgejo.org/models/repo"
|
|
"forgejo.org/models/unittest"
|
|
user_model "forgejo.org/models/user"
|
|
forgejo_context "forgejo.org/services/context"
|
|
"forgejo.org/tests"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRunnerModification(t *testing.T) {
|
|
defer unittest.OverrideFixtures("tests/integration/fixtures/TestRunnerModification")()
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
|
userRunner := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunner{ID: 1001, OwnerID: user.ID})
|
|
userURL := "/user/settings/actions/runners"
|
|
org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3, Type: user_model.UserTypeOrganization})
|
|
orgRunner := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunner{ID: 1002, OwnerID: org.ID})
|
|
orgURL := "/org/" + org.Name + "/settings/actions/runners"
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1, OwnerID: user.ID})
|
|
repoRunner := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunner{ID: 1003, RepoID: repo.ID})
|
|
repoURL := "/" + repo.FullName() + "/settings/actions/runners"
|
|
admin := unittest.AssertExistsAndLoadBean(t, &user_model.User{IsAdmin: true})
|
|
globalRunner := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunner{ID: 1004}, "owner_id = 0 AND repo_id = 0")
|
|
adminURL := "/admin/actions/runners"
|
|
|
|
adminSess := loginUser(t, admin.Name)
|
|
sess := loginUser(t, user.Name)
|
|
|
|
test := func(t *testing.T, fail bool, baseURL string, id int64) {
|
|
defer tests.PrintCurrentTest(t, 1)()
|
|
t.Helper()
|
|
|
|
sess := sess
|
|
if baseURL == adminURL {
|
|
sess = adminSess
|
|
}
|
|
|
|
req := NewRequestWithValues(t, "POST", baseURL+fmt.Sprintf("/%d", id), map[string]string{
|
|
"description": "New Description",
|
|
})
|
|
if fail {
|
|
sess.MakeRequest(t, req, http.StatusNotFound)
|
|
} else {
|
|
sess.MakeRequest(t, req, http.StatusSeeOther)
|
|
flashCookie := sess.GetCookie(forgejo_context.CookieNameFlash)
|
|
assert.NotNil(t, flashCookie)
|
|
assert.Equal(t, "success%3DRunner%2Bupdated%2Bsuccessfully", flashCookie.Value)
|
|
}
|
|
|
|
req = NewRequest(t, "POST", baseURL+fmt.Sprintf("/%d/delete", id))
|
|
if fail {
|
|
sess.MakeRequest(t, req, http.StatusNotFound)
|
|
} else {
|
|
sess.MakeRequest(t, req, http.StatusOK)
|
|
flashCookie := sess.GetCookie(forgejo_context.CookieNameFlash)
|
|
assert.NotNil(t, flashCookie)
|
|
assert.Equal(t, "success%3DRunner%2Bdeleted%2Bsuccessfully", flashCookie.Value)
|
|
}
|
|
}
|
|
|
|
t.Run("User runner", func(t *testing.T) {
|
|
t.Run("Organisation", func(t *testing.T) {
|
|
test(t, true, orgURL, userRunner.ID)
|
|
})
|
|
t.Run("Repository", func(t *testing.T) {
|
|
test(t, true, repoURL, userRunner.ID)
|
|
})
|
|
t.Run("User", func(t *testing.T) {
|
|
test(t, false, userURL, userRunner.ID)
|
|
})
|
|
})
|
|
|
|
t.Run("Organisation runner", func(t *testing.T) {
|
|
t.Run("Repository", func(t *testing.T) {
|
|
test(t, true, repoURL, orgRunner.ID)
|
|
})
|
|
t.Run("User", func(t *testing.T) {
|
|
test(t, true, userURL, orgRunner.ID)
|
|
})
|
|
t.Run("Organisation", func(t *testing.T) {
|
|
test(t, false, orgURL, orgRunner.ID)
|
|
})
|
|
})
|
|
|
|
t.Run("Repository runner", func(t *testing.T) {
|
|
t.Run("Organisation", func(t *testing.T) {
|
|
test(t, true, orgURL, repoRunner.ID)
|
|
})
|
|
t.Run("User", func(t *testing.T) {
|
|
test(t, true, userURL, repoRunner.ID)
|
|
})
|
|
t.Run("Repository", func(t *testing.T) {
|
|
test(t, false, repoURL, repoRunner.ID)
|
|
})
|
|
})
|
|
|
|
t.Run("Global runner", func(t *testing.T) {
|
|
t.Run("Organisation", func(t *testing.T) {
|
|
test(t, true, orgURL, globalRunner.ID)
|
|
})
|
|
t.Run("User", func(t *testing.T) {
|
|
test(t, true, userURL, globalRunner.ID)
|
|
})
|
|
t.Run("Repository", func(t *testing.T) {
|
|
test(t, true, repoURL, globalRunner.ID)
|
|
})
|
|
t.Run("Admin", func(t *testing.T) {
|
|
test(t, false, adminURL, globalRunner.ID)
|
|
})
|
|
})
|
|
}
|