package objectgateway_test import ( "errors" g "knowledge-governance/internal/objectgateway" "testing" ) func TestGatewayGrantCannotAuthorizeUnplannedKey(t *testing.T) { ctx, pool, backend := fixture(t) grant := g.Grant{Epoch: 1, Owner: g.Digest([]byte(t.Name())), Plan: g.Digest([]byte("fixed-plan"))} gateway := &g.Gateway{Pool: pool, Scope: backend.Bucket, Backend: backend, MaxBytes: 1 << 20} if e := gateway.Advance(ctx, 0, grant); !errors.Is(e, g.ErrConflict) { t.Fatal("unregistered plan grant", e) } allowed := request("allowed-plan-key", grant) plan := planFor(grant, allowed) if e := gateway.InstallPlan(ctx, plan); e != nil { t.Fatal(e) } changed := planFor(grant, request("extra-plan-key", grant)) if e := gateway.InstallPlan(ctx, changed); !errors.Is(e, g.ErrConflict) { t.Fatal("immutable plan rebound", e) } if e := gateway.Advance(ctx, 0, grant); e != nil { t.Fatal(e) } req := request(t.Name(), grant) if _, e := gateway.Execute(ctx, req, []byte("gateway fixture "+t.Name())); !errors.Is(e, g.ErrConflict) { t.Fatal("unplanned key admitted", e) } receipt, e := gateway.Execute(ctx, allowed, []byte("gateway fixture allowed-plan-key")) if e != nil || receipt.State != "committed" { t.Fatal("valid planned key refused", e) } cleanup(t, ctx, gateway, receipt) }