feat(storage): add native PostgreSQL runtime and verified offline application import
Build and publish container images / images (push) Failing after 12m29s
Build and publish container images / images (push) Failing after 12m29s
This commit is contained in:
1 parent
96065d1e89
commit
0ba1dcfef0
243 files changed
+21441
-3090
No files matched your search
@@ -0,0 +1,169 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGovernanceBackendOwnershipAndCeilings(t *testing.T) {
|
||||
for _, b := range []storeSQLBackend{storeSQLite, storePostgreSQL} {
|
||||
t.Run(fmt.Sprint(b), func(t *testing.T) {
|
||||
s, d := localityBackendStore(t, b)
|
||||
ctx := context.Background()
|
||||
exec := func(q string, args ...any) {
|
||||
t.Helper()
|
||||
if _, err := s.DB.Exec(q, args...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
admin, err := s.BootstrapOwner(d, "admin", "synthetic governance test password", "Administrator", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
quarter, err := s.CreatePasswordAccount(d, "quarter", "synthetic governance test password", "Quartier owner", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
spot, err := s.CreatePasswordAccount(d, "spot", "synthetic governance test password", "Spot owner", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
member := func(p string) string {
|
||||
t.Helper()
|
||||
var m string
|
||||
if err := s.DB.QueryRow(`SELECT uuid FROM domain_memberships WHERE principal_uuid=`+s.sqlParam(1), p).Scan(&m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
exec(`INSERT INTO zones(uuid,domain_uuid,kind,name,path_prefix,created_at_ms,updated_at_ms) VALUES(`+s.sqlValues(7)+`)`, "q", d, "quartier", "life", "/life", 1, 1)
|
||||
exec(`INSERT INTO zones(uuid,domain_uuid,kind,parent_uuid,name,path_prefix,created_at_ms,updated_at_ms) VALUES(`+s.sqlValues(8)+`)`, "st", d, "street", "q", "home", "/life/home", 1, 1)
|
||||
exec(`INSERT INTO spots(uuid,domain_uuid,name,path_prefix,created_at_ms,updated_at_ms) VALUES(`+s.sqlValues(6)+`)`, "sp", d, "room", "/life/home/room", 1, 1)
|
||||
exec(`INSERT INTO street_spots(street_uuid,spot_uuid,created_at_ms) VALUES('st','sp',1)`)
|
||||
set := func(actor, kind, id, policy string, owners *[]string, preview bool) (CityGovernance, error) {
|
||||
t.Helper()
|
||||
g, err := s.CityGovernance(ctx, d, actor, kind, id)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
var p *string
|
||||
if policy != "" {
|
||||
p = &policy
|
||||
}
|
||||
return s.ChangeCityGovernance(ctx, d, actor, kind, id, CityGovernanceChange{Epoch: g.Epoch, TopologyVersion: g.TopologyVersion, Policy: p, Owners: owners, ConfirmRelaxation: true}, preview)
|
||||
}
|
||||
// A child cannot broaden an authenticated-only Domain ceiling.
|
||||
if _, err = set(admin.UUID, "quartier", "q", "public", nil, false); !errors.Is(err, ErrGovernanceCeiling) {
|
||||
t.Fatal("ceiling bypass", err)
|
||||
}
|
||||
if _, err = set(admin.UUID, "domain", d, "public", nil, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
owners := []string{member(quarter.UUID)}
|
||||
if _, err = set(admin.UUID, "quartier", "q", "public", &owners, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
owners = []string{member(spot.UUID)}
|
||||
if _, err = set(quarter.UUID, "spot", "sp", "public", &owners, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
g, err := s.CityGovernance(ctx, d, spot.UUID, "spot", "sp")
|
||||
if err != nil || g.CanAppoint || !g.DraftEffectivePublic || g.PublicationEnabled {
|
||||
t.Fatal("ownership or publication intent mismatch", g, err)
|
||||
}
|
||||
if _, err = set(spot.UUID, "quartier", "q", "authenticated_acl", nil, false); !errors.Is(err, ErrAccessDenied) {
|
||||
t.Fatal("spot owner controls ancestor", err)
|
||||
}
|
||||
if _, err = set(spot.UUID, "spot", "sp", "", &owners, false); !errors.Is(err, ErrAccessDenied) {
|
||||
t.Fatal("spot owner appoints owner", err)
|
||||
}
|
||||
candidates, err := s.CityGovernanceMembers(ctx, d, quarter.UUID, "spot", "sp", "SPOT")
|
||||
if err != nil || len(candidates) != 1 || candidates[0].Username != "spot" {
|
||||
t.Fatal("candidate lookup", candidates, err)
|
||||
}
|
||||
old := g
|
||||
if _, err = set(quarter.UUID, "spot", "sp", "authenticated_acl", nil, true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
g, err = s.CityGovernance(ctx, d, spot.UUID, "spot", "sp")
|
||||
if err != nil || g.Policy != old.Policy || g.Epoch != old.Epoch {
|
||||
t.Fatal("preview mutated policy", err)
|
||||
}
|
||||
if _, err = set(quarter.UUID, "quartier", "q", "authenticated_acl", nil, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = set(spot.UUID, "spot", "sp", "public", nil, false); !errors.Is(err, ErrGovernanceCeiling) {
|
||||
t.Fatal("lower owner broadened ceiling", err)
|
||||
}
|
||||
p := "inherit"
|
||||
if _, err = s.ChangeCityGovernance(ctx, d, spot.UUID, "spot", "sp", CityGovernanceChange{Epoch: old.Epoch, TopologyVersion: old.TopologyVersion, Policy: &p}, false); !errors.Is(err, ErrGovernanceConflict) {
|
||||
t.Fatal("stale governance edit accepted", err)
|
||||
}
|
||||
if err = s.SetConfigInDomain(d, "authorization_mode", "enforcing"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
acl, err := s.LocalityAccess(ctx, d, admin.UUID, "spot", "sp", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
acl.Mode = "restricted"
|
||||
acl.Entries = []LocalityAccessEntry{{Kind: "user", Name: "spot", Permission: "read"}}
|
||||
acl, err = s.LocalityAccess(ctx, d, admin.UUID, "spot", "sp", &acl)
|
||||
if err != nil || acl.AuthorityRank != 3 || !acl.GrantsAccess {
|
||||
t.Fatal("administrator ACL", acl, err)
|
||||
}
|
||||
acl.Entries[0].Permission = "read_write"
|
||||
if _, err = s.LocalityAccess(ctx, d, spot.UUID, "spot", "sp", &acl); !errors.Is(err, ErrGovernanceCeiling) {
|
||||
t.Fatal("lower owner expanded ACL", err)
|
||||
}
|
||||
acl.Entries = nil
|
||||
acl, err = s.LocalityAccess(ctx, d, spot.UUID, "spot", "sp", &acl)
|
||||
if err != nil || acl.AuthorityRank != 3 {
|
||||
t.Fatal("lower owner could not narrow ACL", err)
|
||||
}
|
||||
if _, err := s.DB.Exec(`UPDATE spots SET path_prefix='/elsewhere' WHERE uuid='sp'`); err == nil {
|
||||
t.Fatal("City path bypassed protected ACL")
|
||||
}
|
||||
if _, err := s.DB.Exec(`DELETE FROM street_spots WHERE spot_uuid='sp'`); err == nil {
|
||||
t.Fatal("City membership bypassed protected ACL")
|
||||
}
|
||||
// Audit failure must roll back policy and epoch together.
|
||||
concurrent, err := s.CityGovernance(ctx, d, admin.UUID, "domain", d)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
results := make(chan error, 2)
|
||||
for i := 0; i < 2; i++ {
|
||||
go func() {
|
||||
_, e := s.ChangeCityGovernance(ctx, d, admin.UUID, "domain", d, CityGovernanceChange{Epoch: concurrent.Epoch, TopologyVersion: concurrent.TopologyVersion, Policy: &concurrent.Policy}, false)
|
||||
results <- e
|
||||
}()
|
||||
}
|
||||
winners := 0
|
||||
for i := 0; i < 2; i++ {
|
||||
if e := <-results; e == nil {
|
||||
winners++
|
||||
} else if !errors.Is(e, ErrGovernanceConflict) {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
if winners != 1 {
|
||||
t.Fatal("concurrent governance updates lost CAS", winners)
|
||||
}
|
||||
before, err := s.CityGovernance(ctx, d, admin.UUID, "domain", d)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
exec(`ALTER TABLE city_governance_events RENAME COLUMN after_json TO unavailable_after`)
|
||||
if _, err = set(admin.UUID, "domain", d, "authenticated_acl", nil, false); err == nil {
|
||||
t.Fatal("missing audit accepted")
|
||||
}
|
||||
after, err := s.CityGovernance(ctx, d, admin.UUID, "domain", d)
|
||||
if err != nil || before.Epoch != after.Epoch || before.Policy != after.Policy {
|
||||
t.Fatal("partial governance commit", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user