5eef13b615
方案A:所有对象写入经 loopback 网关,持久计划/grant/intent/逐版本 receipt 与 attempt→grant delivery 落在治理 PG;scope 由 provider+endpoint+bucket 决定, 同一物理桶只允许一个写域。版本 append 不等于 CAS,未锚定计划在首笔业务写前拒绝。 本提交只含网关与其适配层接线、协议文档;生产独占、凭据切换与桶设置未改动。
38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
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, Isolation: verifiedFixture{}, 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)
|
|
}
|