Skip to content

Commit 79118aa

Browse files
committed
fix
1 parent 1fa50f3 commit 79118aa

File tree

6 files changed

+70
-13
lines changed

6 files changed

+70
-13
lines changed

modules/test/utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ package test
55

66
import (
77
"net/http"
8+
"strings"
89
)
910

1011
// RedirectURL returns the redirect URL of a http response.
1112
func RedirectURL(resp http.ResponseWriter) string {
1213
return resp.Header().Get("Location")
1314
}
15+
16+
func IsNormalPageCompleted(s string) bool {
17+
return strings.Contains(s, `<footer class="page-footer"`) && strings.Contains(s, `</html>`)
18+
}

options/locale/locale_en-US.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3035,8 +3035,6 @@ config.git_disable_diff_highlight = Disable Diff Syntax Highlight
30353035
config.git_max_diff_lines = Max Diff Lines (for a single file)
30363036
config.git_max_diff_line_characters = Max Diff Characters (for a single line)
30373037
config.git_max_diff_files = Max Diff Files (to be shown)
3038-
config.git_enable_reflogs = Enable Reflogs
3039-
config.git_reflog_expiry_time = Expiry Time
30403038
config.git_gc_args = GC Arguments
30413039
config.git_migrate_timeout = Migration Timeout
30423040
config.git_mirror_timeout = Mirror Update Timeout

routers/common/errpage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func RenderPanicErrorPage(w http.ResponseWriter, req *http.Request, err any) {
2626

2727
defer func() {
2828
if err := recover(); err != nil {
29-
log.Error("Panic occurs again when rendering error page: %v", err)
29+
log.Error("Panic occurs again when rendering error page: %v. Stack:\n%s", err, log.Stack(2))
3030
}
3131
}()
3232

routers/common/errpage_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package common
5+
6+
import (
7+
"context"
8+
"errors"
9+
"net/http"
10+
"net/http/httptest"
11+
"net/url"
12+
"path/filepath"
13+
"testing"
14+
15+
"code.gitea.io/gitea/models/unittest"
16+
"code.gitea.io/gitea/modules/test"
17+
"code.gitea.io/gitea/modules/web/middleware"
18+
19+
"github.com/stretchr/testify/assert"
20+
)
21+
22+
func TestRenderPanicErrorPage(t *testing.T) {
23+
w := httptest.NewRecorder()
24+
req := &http.Request{URL: &url.URL{}}
25+
req = req.WithContext(middleware.WithContextData(context.Background()))
26+
RenderPanicErrorPage(w, req, errors.New("fake panic error (for test only)"))
27+
respContent := w.Body.String()
28+
assert.Contains(t, respContent, `class="page-content status-page-500"`)
29+
assert.Contains(t, respContent, `</html>`)
30+
31+
// the 500 page doesn't have normal pages footer, it makes it easier to distinguish a normal page and a failed page.
32+
// especially when a sub-template causes page error, the HTTP response code is still 200,
33+
// the different "footer" is the only way to know whether a page is fully rendered without error.
34+
assert.False(t, test.IsNormalPageCompleted(respContent))
35+
}
36+
37+
func TestMain(m *testing.M) {
38+
unittest.MainTest(m, &unittest.TestOptions{
39+
GiteaRootPath: filepath.Join("..", ".."),
40+
})
41+
}

templates/admin/config.tmpl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -333,16 +333,6 @@
333333

334334
<div class="ui divider"></div>
335335

336-
<dt>{{.locale.Tr "admin.config.git_enable_reflogs"}}</dt>
337-
<dd>{{if .Git.Reflog.Enabled}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}</dd>
338-
339-
{{if .Git.Reflog.Enabled}}
340-
<dt>{{.locale.Tr "admin.config.git_reflog_expiry_time"}}</dt>
341-
<dd>{{.locale.Tr "tool.days" .Git.Reflog.Expiration}}</dd>
342-
{{end}}
343-
344-
<div class="ui divider"></div>
345-
346336
<dt>{{.locale.Tr "admin.config.git_migrate_timeout"}}</dt>
347337
<dd>{{.Git.Timeout.Migrate}} {{.locale.Tr "tool.raw_seconds"}}</dd>
348338
<dt>{{.locale.Tr "admin.config.git_mirror_timeout"}}</dt>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2023 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/test"
11+
"code.gitea.io/gitea/tests"
12+
13+
"github.com/stretchr/testify/assert"
14+
)
15+
16+
func TestAdminConfig(t *testing.T) {
17+
defer tests.PrepareTestEnv(t)()
18+
19+
session := loginUser(t, "user1")
20+
req := NewRequest(t, "GET", "/admin/config")
21+
resp := session.MakeRequest(t, req, http.StatusOK)
22+
assert.True(t, test.IsNormalPageCompleted(resp.Body.String()))
23+
}

0 commit comments

Comments
 (0)