Files
pages/internal/store/schutzaria_test.go
T
Anya Tokugawa d5d21b7841
Build and publish container images / images (push) Successful in 9m34s
Release container images / release (push) Successful in 36s
Refactor architecture into eight components and consolidate reliability work
Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts.

Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation.

Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
2026-11-01 15:23:31 +09:00

92 lines
3.4 KiB
Go

package store
import (
"database/sql"
"encoding/json"
"testing"
"pageswiki/internal/schutzaria"
)
func schutzariaStoreFixture(t *testing.T) *Store {
t.Helper()
db, err := sql.Open("sqlite", ":memory:")
if err != nil {
t.Fatal(err)
}
db.SetMaxOpenConns(1)
t.Cleanup(func() { db.Close() })
s := &Store{DB: db}
if err = s.EnsureAuthSchema(); err != nil {
t.Fatal(err)
}
for _, stmt := range []string{
`INSERT INTO principals(uuid,state,created_at_ms,updated_at_ms) VALUES('p','active',1,1)`,
`INSERT INTO domain_memberships(uuid,domain_uuid,principal_uuid,state,created_at_ms) VALUES('m','d','p','active',1)`,
`INSERT INTO auth_roles(uuid,domain_uuid,name,created_at_ms) VALUES('r','d','reader',1)`,
`INSERT INTO auth_role_bindings(membership_uuid,role_uuid,created_at_ms) VALUES('m','r',1)`,
} {
if _, err = db.Exec(stmt); err != nil {
t.Fatal(err)
}
}
return s
}
func TestSchutzariaReadLoaderBudgetsAndErrors(t *testing.T) {
for _, kind := range []string{"grant", "locality", "db-error"} {
t.Run(kind, func(t *testing.T) {
s := schutzariaStoreFixture(t)
if _, err := s.DB.Exec(`INSERT INTO auth_capability_grants(uuid,role_uuid,capability,target_type,target_id,created_at_ms) VALUES('all','r','read','domain','d',1)`); err != nil {
t.Fatal(err)
}
switch kind {
case "grant":
_, err := s.DB.Exec(`WITH RECURSIVE n(x) AS (SELECT 1 UNION ALL SELECT x+1 FROM n WHERE x<4096) INSERT INTO auth_capability_grants(uuid,role_uuid,capability,target_type,target_id,created_at_ms) SELECT 'grant-'||x,'r','read','path','/page/'||x,1 FROM n`)
if err != nil {
t.Fatal(err)
}
case "locality":
_, err := s.DB.Exec(`WITH RECURSIVE n(x) AS (SELECT 1 UNION ALL SELECT x+1 FROM n WHERE x<4097) INSERT INTO locality_access_policies(domain_uuid,node_kind,node_uuid,scope_path,grants_access,actor_uuid,authority_rank) SELECT 'd','spot','spot-'||x,'/scope/'||x,0,'p',3 FROM n`)
if err != nil {
t.Fatal(err)
}
case "db-error":
if _, err := s.DB.Exec(`DROP TABLE locality_access_policies`); err != nil {
t.Fatal(err)
}
}
policy, err := s.LoadReadPathPolicy("d", "p")
if err == nil || policy != nil || policy.Allows("/would-be-allowed") {
t.Fatal("incomplete ACL snapshot escaped", policy, err)
}
})
}
}
func TestSchutzariaStoreCompatibility(t *testing.T) {
var policy *ReadPathPolicy = schutzaria.NewReadPathPolicy(false, []string{"/exact"}, nil, nil)
if !policy.Allows("/exact") || policy.Allows("/exact/child") {
t.Fatal("alias mismatch")
}
var locality LocalityPolicy = schutzaria.LocalityPolicy{Kind: "spot", UUID: "id", Policy: "public"}
data, err := json.Marshal(locality)
if err != nil || string(data) != `{"kind":"spot","uuid":"id","policy":"public"}` {
t.Fatal(string(data), err)
}
var user UserSpacePolicy = schutzaria.UserSpacePolicy{Username: "alice", RootVisibility: "private", DescendantVisibility: "domain"}
for _, p := range []string{"/u/alice", "/u/alice/page", "/u/bob"} {
if EffectiveUserSpaceVisibility(user, p) != schutzaria.EffectiveUserSpaceVisibility(user, p) {
t.Fatal("user policy wrapper mismatch")
}
}
if ErrApprovalTransition != schutzaria.ErrApprovalTransition {
t.Fatal("error identity changed")
}
for _, p := range []string{"/public", "/u/private", "/v/tree"} {
if PublicSemanticPath(p) != schutzaria.PublicSemanticPath(p) {
t.Fatal("publication wrapper mismatch")
}
}
}