Skip to content

Commit eefaea6

Browse files
committed
fix test
1 parent f9547ff commit eefaea6

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

routers/web/admin/admin_test.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"code.gitea.io/gitea/services/contexttest"
1414

1515
"github.com/stretchr/testify/assert"
16+
"github.com/stretchr/testify/require"
1617
)
1718

1819
func TestShadowPassword(t *testing.T) {
@@ -74,19 +75,29 @@ func TestShadowPassword(t *testing.T) {
7475
}
7576

7677
func TestSelfCheckPost(t *testing.T) {
78+
defer test.MockVariableValue(&setting.PublicURLDetection)()
7779
defer test.MockVariableValue(&setting.AppURL, "http://config/sub/")()
7880
defer test.MockVariableValue(&setting.AppSubURL, "/sub")()
7981

80-
ctx, resp := contexttest.MockContext(t, "GET http://host/sub/admin/self_check?location_origin=http://frontend")
81-
SelfCheckPost(ctx)
82-
assert.Equal(t, http.StatusOK, resp.Code)
83-
8482
data := struct {
8583
Problems []string `json:"problems"`
8684
}{}
87-
err := json.Unmarshal(resp.Body.Bytes(), &data)
88-
assert.NoError(t, err)
85+
86+
setting.PublicURLDetection = setting.PublicURLLegacy
87+
ctx, resp := contexttest.MockContext(t, "GET http://host/sub/admin/self_check?location_origin=http://frontend")
88+
SelfCheckPost(ctx)
89+
assert.Equal(t, http.StatusOK, resp.Code)
90+
require.NoError(t, json.Unmarshal(resp.Body.Bytes(), &data))
8991
assert.Equal(t, []string{
9092
ctx.Locale.TrString("admin.self_check.location_origin_mismatch", "http://frontend/sub/", "http://config/sub/"),
9193
}, data.Problems)
94+
95+
setting.PublicURLDetection = setting.PublicURLAuto
96+
ctx, resp = contexttest.MockContext(t, "GET http://host/sub/admin/self_check?location_origin=http://frontend")
97+
SelfCheckPost(ctx)
98+
assert.Equal(t, http.StatusOK, resp.Code)
99+
require.NoError(t, json.Unmarshal(resp.Body.Bytes(), &data))
100+
assert.Equal(t, []string{
101+
ctx.Locale.TrString("admin.self_check.location_origin_mismatch", "http://frontend/sub/", "http://host/sub/"),
102+
}, data.Problems)
92103
}

0 commit comments

Comments
 (0)