mirror of
https://github.com/go-gitea/gitea.git
synced 2026-04-18 05:20:50 +00:00
This is the first step (the hardest part): * repo file list last commit message lazy load * admin server status monitor * watch/unwatch (normal page, watchers page) * star/unstar (normal page, watchers page) * project view, delete column * workflow dispatch, switch the branch * commit page: load branches and tags referencing this commit The legacy "data-redirect" attribute is removed, it only makes the page reload (sometimes using an incorrect link). Also did cleanup for some devtest pages.
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package context
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRedirect(t *testing.T) {
|
|
setting.IsInTesting = true
|
|
req, _ := http.NewRequest(http.MethodGet, "/", nil)
|
|
|
|
cases := []struct {
|
|
url string
|
|
keep bool
|
|
}{
|
|
{"http://test", false},
|
|
{"https://test", false},
|
|
{"//test", false},
|
|
{"/://test", true},
|
|
{"/test", true},
|
|
}
|
|
for _, c := range cases {
|
|
resp := httptest.NewRecorder()
|
|
b := NewBaseContextForTest(resp, req)
|
|
resp.Header().Add("Set-Cookie", (&http.Cookie{Name: setting.SessionConfig.CookieName, Value: "dummy"}).String())
|
|
b.Redirect(c.url)
|
|
has := resp.Header().Get("Set-Cookie") == "i_like_gitea=dummy"
|
|
assert.Equal(t, c.keep, has, "url = %q", c.url)
|
|
}
|
|
|
|
req, _ = http.NewRequest(http.MethodGet, "/", nil)
|
|
resp := httptest.NewRecorder()
|
|
req.Header.Add("X-Gitea-Fetch-Action", "1")
|
|
b := NewBaseContextForTest(resp, req)
|
|
b.Redirect("/other")
|
|
assert.Contains(t, resp.Header().Get("Content-Type"), "application/json")
|
|
assert.JSONEq(t, `{"redirect":"/other"}`, resp.Body.String())
|
|
assert.Equal(t, http.StatusOK, resp.Code)
|
|
}
|