package api_test import ( "context" "net/http" "strings" "testing" "git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi" "git.zb-server.de/ZB-Server/uptimesebi/internal/store" "git.zb-server.de/ZB-Server/uptimesebi/internal/tenant" ) func TestLegalDocuments(t *testing.T) { e := newEnv(t) admin := e.browser(t) admin.signup("a@"+uniq("lg")+".test", uniq("lg-")) err := tenant.New(e.dbPool).Tx(context.Background(), tenant.Global(), func(q *store.Queries) error { return q.MakeAdmin(context.Background(), admin.userIDSelf()) }) if err != nil { t.Fatal(err) } t.Cleanup(func() { for _, kind := range []string{"imprint", "privacy"} { admin.do("PUT", "/api/v1/admin/legal/"+kind, map[string]any{}) } }) imprint := "# Impressum\n\nBetreiber GmbH " st, body := admin.do("PUT", "/api/v1/admin/legal/imprint", map[string]any{"markdown": imprint}) expect(t, "admin sets imprint", st, body, http.StatusNoContent, "") st, body = admin.do("PUT", "/api/v1/admin/legal/privacy", map[string]any{"url": "javascript:alert(1)"}) expect(t, "javascript link", st, body, http.StatusUnprocessableEntity, "invalid_legal_url") st, body = admin.do("PUT", "/api/v1/admin/legal/privacy", map[string]any{"url": "https://operator.example/privacy"}) expect(t, "admin sets privacy link", st, body, http.StatusNoContent, "") st, body = admin.do("PUT", "/api/v1/admin/legal/terms", map[string]any{"markdown": "x"}) expect(t, "unknown kind", st, body, http.StatusNotFound, "not_found") // The console footer links them, also before signing in. _, _, login := e.browser(t).page("/login") if !strings.Contains(login, `href="/legal/imprint"`) || !strings.Contains(login, `href="https://operator.example/privacy"`) { t.Error("login page footer lacks the legal links") } st, _, html := e.browser(t).page("/legal/imprint") if st != http.StatusOK || !strings.Contains(html, "

Impressum

") || strings.Contains(html, " ![t](https://e.example/p.png)"}) html, _ := body["html"].(string) if st != http.StatusOK || !strings.Contains(html, "hi") || strings.Contains(html, "