mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-02-15 04:42:41 +02:00
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>
64 lines
2.4 KiB
Go
64 lines
2.4 KiB
Go
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
"path"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestPullSummaryCommits(t *testing.T) {
|
|
onApplicationRun(t, func(t *testing.T, u *url.URL) {
|
|
testUser := "user2"
|
|
testRepo := "repo1"
|
|
branchOld := "master"
|
|
branchNew := "new-branch"
|
|
session := loginUser(t, testUser)
|
|
|
|
// Create a branch with commit, open a PR and see if the summary is displayed correctly for 1 commit
|
|
testEditFileToNewBranch(t, session, testUser, testRepo, branchOld, branchNew, "README.md", "test of pull summary")
|
|
url := path.Join(testUser, testRepo, "compare", branchOld+"..."+branchNew)
|
|
req := NewRequestWithValues(t, "POST", url,
|
|
map[string]string{
|
|
"title": "1st pull request to test summary",
|
|
},
|
|
)
|
|
session.MakeRequest(t, req, http.StatusOK)
|
|
testPullSummaryCommits(t, session, testUser, testRepo, "6", "wants to merge 1 commit")
|
|
|
|
// Merge the PR and see if the summary is displayed correctly for 1 commit
|
|
testPullMerge(t, session, testUser, testRepo, "6", "merge", true)
|
|
testPullSummaryCommits(t, session, testUser, testRepo, "6", "merged 1 commit")
|
|
|
|
// Create a branch with 2 commits, open a PR and see if the summary is displayed correctly for 2 commits
|
|
testEditFileToNewBranch(t, session, testUser, testRepo, branchOld, branchNew, "README.md", "test of pull summary (the 2nd)")
|
|
testEditFile(t, session, testUser, testRepo, branchNew, "README.md", "test of pull summary (the 3rd)")
|
|
req = NewRequestWithValues(t, "POST", url,
|
|
map[string]string{
|
|
"title": "2nd pull request to test summary",
|
|
},
|
|
)
|
|
session.MakeRequest(t, req, http.StatusOK)
|
|
testPullSummaryCommits(t, session, testUser, testRepo, "7", "wants to merge 2 commits")
|
|
|
|
// Merge the PR and see if the summary is displayed correctly for 2 commits
|
|
testPullMerge(t, session, testUser, testRepo, "7", "merge", true)
|
|
testPullSummaryCommits(t, session, testUser, testRepo, "7", "merged 2 commits")
|
|
})
|
|
}
|
|
|
|
func testPullSummaryCommits(t *testing.T, session *TestSession, user, repo, pullNum, expectedSummary string) {
|
|
t.Helper()
|
|
req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullNum))
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
doc := NewHTMLParser(t, resp.Body)
|
|
text := strings.TrimSpace(doc.doc.Find(".pull-desc").Text())
|
|
assert.Contains(t, text, expectedSummary)
|
|
}
|