Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
139 lines
5.3 KiB
Go
139 lines
5.3 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"github.com/google/uuid"
|
|
"pageswiki/internal/store"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestPeriodicalProjection(t *testing.T) {
|
|
s, token, target, reader := periodicalFixture(t)
|
|
ctx := context.Background()
|
|
d, err := s.store.GetDomainByUUID(target)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = s.store.CreateDomain(d.CampusUUID, "source", "Source", "source.example.test", "local", "", "", true); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var source string
|
|
var sid int64
|
|
if err = s.store.DB.QueryRow(`SELECT uuid,id FROM domains WHERE name='source'`).Scan(&source, &sid); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
on := true
|
|
if err = s.store.ChangePeriodical(ctx, target, reader, "blog", &on, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err = s.store.DB.Exec(`INSERT INTO periodical_settings(domain_uuid,kind,enabled) VALUES(?,'blog',1)`, source); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, date := range []string{"2026-09-18", "2026-10-01"} {
|
|
path, _ := store.PeriodicalPath("/blog", date, "")
|
|
page, e := s.store.CreatePageAtPathInDomain(source, path)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if _, e = s.store.SaveRevision(page, "<p>Source body</p>", ""); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if _, e = s.store.DB.Exec(`INSERT INTO periodical_entries(domain_uuid,kind,page_uuid,owner_uuid,local_date,title,timezone) VALUES(?,'blog',?,?,?,?,'UTC')`, source, page, reader, date, "Source "+date); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
}
|
|
if err = s.store.SetPeriodicalProjection(ctx, d.ID, reader, "blog", source, "/blog/2026/09"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if w := periodicalRequest(s, token, "GET", "/v/blog/-/new", ""); w.Code != 303 || w.Header().Get("Location") != "//source.example.test/v/blog/-/new" {
|
|
t.Fatal("source composer redirect", w.Code, w.Header().Get("Location"))
|
|
}
|
|
get := func() string {
|
|
w := periodicalRequest(s, token, "GET", "/v/blog/2026/09", "")
|
|
if w.Code != 200 {
|
|
t.Fatal(w.Code, w.Body.String())
|
|
}
|
|
return w.Body.String()
|
|
}
|
|
if strings.Contains(get(), "Source 2026-09-18") {
|
|
t.Fatal("source ACL bypass")
|
|
}
|
|
membership, role := uuid.NewString(), uuid.NewString()
|
|
if _, err = s.store.DB.Exec(`INSERT OR IGNORE INTO domain_memberships(uuid,domain_uuid,principal_uuid,state,created_at_ms) VALUES(?,?,?,'active',0)`, membership, source, reader); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = s.store.DB.QueryRow(`SELECT uuid FROM domain_memberships WHERE domain_uuid=? AND principal_uuid=?`, source, reader).Scan(&membership); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, stmt := range []struct {
|
|
q string
|
|
args []any
|
|
}{
|
|
{`UPDATE domain_memberships SET state='active' WHERE uuid=?`, []any{membership}},
|
|
{`INSERT INTO auth_roles(uuid,domain_uuid,name,created_at_ms) VALUES(?,?,'projection-reader',0)`, []any{role, source}},
|
|
{`INSERT INTO auth_role_bindings VALUES(?,?,0)`, []any{membership, role}},
|
|
{`INSERT INTO auth_capability_grants(uuid,role_uuid,capability,target_type,target_id,created_at_ms) VALUES(?,?,'read','domain',?,0)`, []any{uuid.NewString(), role, source}},
|
|
} {
|
|
if _, err = s.store.DB.Exec(stmt.q, stmt.args...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
body := get()
|
|
if !strings.Contains(body, "Source 2026-09-18") || strings.Contains(body, "Source 2026-10-01") {
|
|
t.Fatal("projection prefix filtering")
|
|
}
|
|
if !strings.Contains(body, `href="//source.example.test/blog/2026/09/18"`) {
|
|
t.Fatal("source link missing")
|
|
}
|
|
if strings.Contains(body, "data-periodical-compose aria") || strings.Contains(body, "data-periodical-edit aria") {
|
|
t.Fatal("projection mutation UI")
|
|
}
|
|
var count int
|
|
if err = s.store.DB.QueryRow(`SELECT count(*) FROM paths WHERE domain_uuid=?`, target).Scan(&count); err != nil || count != 0 {
|
|
t.Fatal("content copied", count, err)
|
|
}
|
|
w := periodicalRequest(s, token, "POST", "/_/api/v1/extension/content.blog/posts", `{}`)
|
|
if w.Code != 403 {
|
|
t.Fatal("projection post", w.Code)
|
|
}
|
|
if err = s.store.SetPeriodicalProjection(ctx, d.ID, reader, "blog", target, "/"); err == nil {
|
|
t.Fatal("self projection")
|
|
}
|
|
if err = s.store.SetPeriodicalProjection(ctx, sid, reader, "blog", target, "/"); err == nil {
|
|
t.Fatal("cycle projection")
|
|
}
|
|
if _, err = s.store.DB.Exec(`UPDATE domain_memberships SET state='suspended' WHERE uuid=?`, membership); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if strings.Contains(get(), "Source 2026-09-18") {
|
|
t.Fatal("revoked membership leaked")
|
|
}
|
|
if err = s.store.CreateCampus("other", "Other", "en", "controller", "other.example.test", true); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err = s.store.DB.Exec(`UPDATE domains SET campus_uuid=(SELECT uuid FROM campuses WHERE name='other') WHERE uuid=?`, source); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = s.store.SetPeriodicalProjection(ctx, d.ID, reader, "blog", source, "/"); err == nil {
|
|
t.Fatal("cross Campus configured")
|
|
}
|
|
w = periodicalRequest(s, token, "GET", "/v/blog", "")
|
|
if w.Code != 503 {
|
|
t.Fatal("cross Campus projection remained active", w.Code)
|
|
}
|
|
if _, err = s.store.DB.Exec(`UPDATE domains SET campus_uuid=? WHERE uuid=?`, d.CampusUUID, source); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err = s.store.DB.Exec(`UPDATE domains SET placement='remote' WHERE uuid=?`, source); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
w = periodicalRequest(s, token, "GET", "/v/blog", "")
|
|
if w.Code != 503 {
|
|
t.Fatal("remote source not closed", w.Code)
|
|
}
|
|
if err = s.store.SetPeriodicalProjection(ctx, d.ID, reader, "blog", "", ""); err != nil {
|
|
t.Fatal("projection removal", err)
|
|
}
|
|
}
|