feat(statuspages): error page linking a home page set by admins
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 6m52s
ci / test (pull_request) Successful in 15m30s
ci / build (pull_request) Successful in 16m56s
ci / image (pull_request) Successful in 6m1s
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 6m52s
ci / test (pull_request) Successful in 15m30s
ci / build (pull_request) Successful in 16m56s
ci / image (pull_request) Successful in 6m1s
The bare status page domain and pages that do not exist answered with a plain "404 page not found". They now show an error page with a button to the platform's home page, which platform admins set under Admin. The status page servers receive it with the page index and keep it across restarts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
af992409ef
commit
1f90fe8470
17 files changed
+902
-395
No files matched your search
@@ -0,0 +1,46 @@
|
||||
package api_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
|
||||
)
|
||||
|
||||
func TestStatusPageHome(t *testing.T) {
|
||||
e := newEnv(t)
|
||||
admin := e.browser(t)
|
||||
admin.signup("a@"+uniq("home")+".test", uniq("home-"))
|
||||
if err := tenant.New(e.dbPool).Tx(context.Background(), tenant.Global(), func(q *store.Queries) error {
|
||||
return q.MakeAdmin(context.Background(), admin.userIDSelf())
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { admin.do("PUT", "/api/v1/admin/statuspage-home", map[string]any{"url": ""}) })
|
||||
pages := e.statuspageClient(t, nil)
|
||||
|
||||
st, body := admin.do("PUT", "/api/v1/admin/statuspage-home", map[string]any{"url": "javascript:alert(1)"})
|
||||
expect(t, "script link", st, body, http.StatusUnprocessableEntity, "invalid_legal_url")
|
||||
if st, body := admin.do("PUT", "/api/v1/admin/statuspage-home", map[string]any{"url": " https://example.test/ "}); st != http.StatusNoContent {
|
||||
t.Fatalf("set home = %d %v", st, body)
|
||||
}
|
||||
if _, body := admin.do("GET", "/api/v1/admin/statuspage-home", nil); body["url"] != "https://example.test/" {
|
||||
t.Errorf("home = %v", body)
|
||||
}
|
||||
index, err := pages.Pages(context.Background())
|
||||
if err != nil || index.HomeURL != "https://example.test/" {
|
||||
t.Errorf("page index home = %q %v", index.HomeURL, err)
|
||||
}
|
||||
if _, _, html := admin.page("/admin"); !strings.Contains(html, `value="https://example.test/"`) {
|
||||
t.Error("the admin page does not show the home page")
|
||||
}
|
||||
|
||||
owner := e.browser(t)
|
||||
owner.signup("o@"+uniq("home")+".test", uniq("home-"))
|
||||
if st, _ := owner.do("PUT", "/api/v1/admin/statuspage-home", map[string]any{"url": "https://evil.test/"}); st != http.StatusForbidden {
|
||||
t.Errorf("non-admin sets the home page = %d, want 403", st)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user