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.
112 lines
3.7 KiB
Go
112 lines
3.7 KiB
Go
package calendar
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func TestCalendarDAVIdentityAtomicAndRebuild(t *testing.T) {
|
|
r, domain, actor, c := fixture(t)
|
|
ctx := context.Background()
|
|
item := sample(t, "client@example.test", "2026-10-01T09:00:00Z", "2026-10-01T10:00:00Z", false)
|
|
var wg sync.WaitGroup
|
|
results := make(chan error, 2)
|
|
for i := 0; i < 2; i++ {
|
|
wg.Add(1)
|
|
go func() {
|
|
defer wg.Done()
|
|
_, _, err := r.ChangeDAV(ctx, domain, c.ID, actor, "arbitrary.ics", "", &item, nil)
|
|
results <- err
|
|
}()
|
|
}
|
|
wg.Wait()
|
|
close(results)
|
|
success := 0
|
|
for err := range results {
|
|
if err == nil {
|
|
success++
|
|
} else if !errors.Is(err, ErrPreconditionRequired) {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if success != 1 {
|
|
t.Fatal(success)
|
|
}
|
|
// Filename metadata survives an index rebuild and a settings change.
|
|
c, err := r.Get(domain, c.ID, actor)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err = r.Settings(ctx, domain, c.ID, actor, c.Version, "Renamed", false, c.Members); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, table := range []string{"calendar_event_cache", "calendar_month_cache", "calendar_index_state"} {
|
|
if _, err = r.DB.Exec("DELETE FROM " + table); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
c, items, err := r.DAVSnapshot(ctx, domain, c.ID, actor, true)
|
|
if err != nil || len(items) != 1 || DAVFilename(c, items[0].UID) != "arbitrary.ics" || items[0].ETag != item.ETag {
|
|
t.Fatal(err, items, c.DAVNames)
|
|
}
|
|
if _, _, err = r.ChangeDAV(ctx, domain, c.ID, actor, "other.ics", "", &item, nil); err != ErrConflict {
|
|
t.Fatal("duplicate UID", err)
|
|
}
|
|
other := sample(t, "other@example.test", "2026-10-01T09:00:00Z", "2026-10-01T10:00:00Z", false)
|
|
if _, _, err = r.ChangeDAV(ctx, domain, c.ID, actor, "arbitrary.ics", item.ETag, &other, nil); err != ErrConflict {
|
|
t.Fatal("identity changed", err)
|
|
}
|
|
member := uuid.NewString()
|
|
c, err = r.Settings(ctx, domain, c.ID, actor, c.Version, c.Name, false, map[string]string{member: "read"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, _, err = r.ChangeDAV(ctx, domain, c.ID, member, "arbitrary.ics", item.ETag, &item, nil); err != ErrForbidden {
|
|
t.Fatal("read member wrote", err)
|
|
}
|
|
c, err = r.Settings(ctx, domain, c.ID, actor, c.Version, c.Name, false, map[string]string{member: "write"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, _, err = r.ChangeDAV(ctx, domain, c.ID, member, "arbitrary.ics", item.ETag, &item, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
c, err = r.Get(domain, c.ID, actor)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err = r.Settings(ctx, domain, c.ID, actor, c.Version, c.Name, false, map[string]string{}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, _, err = r.DAVSnapshot(ctx, domain, c.ID, member, true); err != ErrMissing {
|
|
t.Fatal("revoked ACL leaked", err)
|
|
}
|
|
if _, _, err = r.ChangeDAV(ctx, domain, c.ID, actor, "arbitrary.ics", item.ETag, nil, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
c, err = r.Get(domain, c.ID, actor)
|
|
if err != nil || len(c.DAVNames) != 0 {
|
|
t.Fatal("alias retained after delete", err, c.DAVNames)
|
|
}
|
|
}
|
|
|
|
func TestCalendarDAVSnapshotLimit(t *testing.T) {
|
|
r, domain, actor, c := fixture(t)
|
|
ctx := context.Background()
|
|
if _, _, err := r.DAVSnapshot(ctx, domain, c.ID, actor, false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// Synthetic disposable cache only; exceed the collection bound deliberately.
|
|
_, err := r.DB.Exec(`WITH RECURSIVE n(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM n WHERE x<10001) INSERT INTO calendar_event_cache(domain,calendar,uid,month,start,end,etag,data) SELECT ?,?,CAST(x AS TEXT),'2026-10',0,0,'"test"','' FROM n`, domain, c.ID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, items, err := r.DAVSnapshot(ctx, domain, c.ID, actor, false); err != ErrLimit || items != nil {
|
|
t.Fatal("returned truncated collection", len(items), err)
|
|
}
|
|
}
|