Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package admin
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"gitea.dev/modules/json"
|
|
"gitea.dev/modules/setting"
|
|
"gitea.dev/modules/test"
|
|
"gitea.dev/services/contexttest"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestSelfCheckPost(t *testing.T) {
|
|
defer test.MockVariableValue(&setting.PublicURLDetection)()
|
|
defer test.MockVariableValue(&setting.AppURL, "http://config/sub/")()
|
|
defer test.MockVariableValue(&setting.AppSubURL, "/sub")()
|
|
|
|
data := struct {
|
|
Problems []string `json:"problems"`
|
|
}{}
|
|
|
|
setting.PublicURLDetection = setting.PublicURLLegacy
|
|
ctx, resp := contexttest.MockContext(t, "GET http://host/sub/admin/self_check?location_origin=http://frontend")
|
|
SelfCheckPost(ctx)
|
|
assert.Equal(t, http.StatusOK, resp.Code)
|
|
require.NoError(t, json.Unmarshal(resp.Body.Bytes(), &data))
|
|
assert.Equal(t, []string{
|
|
ctx.Locale.TrString("admin.self_check.location_origin_mismatch", "http://frontend/sub/", "http://config/sub/"),
|
|
}, data.Problems)
|
|
|
|
setting.PublicURLDetection = setting.PublicURLAuto
|
|
ctx, resp = contexttest.MockContext(t, "GET http://host/sub/admin/self_check?location_origin=http://frontend")
|
|
SelfCheckPost(ctx)
|
|
assert.Equal(t, http.StatusOK, resp.Code)
|
|
require.NoError(t, json.Unmarshal(resp.Body.Bytes(), &data))
|
|
assert.Equal(t, []string{
|
|
ctx.Locale.TrString("admin.self_check.location_origin_mismatch", "http://frontend/sub/", "http://host/sub/"),
|
|
}, data.Problems)
|
|
}
|