9a5720e8ad
Branch Policy Check / Verify merge target (pull_request) Has been cancelled
Universal: PR Check / Branch Policy (pull_request) Has been cancelled
PR RC Release / Build RC Release (pull_request) Has been cancelled
Universal: PR Check / Validate PR (pull_request) Has been cancelled
Branch Cleanup / Delete merged branch (pull_request) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Full namespace migration: update the Go module path and all import statements from git.mokoconsulting.tech to code.mokoconsulting.tech. Also updates all URL references in templates, workflows, configs, tests, and documentation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package common
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"net/url"
|
|
"strings"
|
|
"testing"
|
|
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/setting"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/test"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestFetchRedirectDelegate(t *testing.T) {
|
|
defer test.MockVariableValue(&setting.AppURL, "https://gitea/")()
|
|
|
|
cases := []struct {
|
|
method string
|
|
input string
|
|
status int
|
|
}{
|
|
{method: "POST", input: "/foo?k=v", status: http.StatusSeeOther},
|
|
{method: "GET", input: "/foo?k=v", status: http.StatusBadRequest},
|
|
{method: "POST", input: `\/foo?k=v`, status: http.StatusBadRequest},
|
|
{method: "POST", input: `\\/foo?k=v`, status: http.StatusBadRequest},
|
|
{method: "POST", input: "https://gitea/xxx", status: http.StatusSeeOther},
|
|
{method: "POST", input: "https://other/xxx", status: http.StatusBadRequest},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.method+" "+c.input, func(t *testing.T) {
|
|
resp := httptest.NewRecorder()
|
|
req := httptest.NewRequest(c.method, "/?redirect="+url.QueryEscape(c.input), nil)
|
|
FetchRedirectDelegate(resp, req)
|
|
assert.Equal(t, c.status, resp.Code)
|
|
if c.status == http.StatusSeeOther {
|
|
assert.Equal(t, c.input, resp.Header().Get("Location"))
|
|
} else {
|
|
assert.Empty(t, resp.Header().Get("Location"))
|
|
assert.Equal(t, "Bad Request", strings.TrimSpace(resp.Body.String()))
|
|
}
|
|
})
|
|
}
|
|
}
|