feat(object-gateway): 统一对象写网关与不可变治理日志
方案A:所有对象写入经 loopback 网关,持久计划/grant/intent/逐版本 receipt 与 attempt→grant delivery 落在治理 PG;scope 由 provider+endpoint+bucket 决定, 同一物理桶只允许一个写域。版本 append 不等于 CAS,未锚定计划在首笔业务写前拒绝。 本提交只含网关与其适配层接线、协议文档;生产独占、凭据切换与桶设置未改动。
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package objectgateway_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
g "knowledge-governance/internal/objectgateway"
|
||||
)
|
||||
|
||||
func TestGatewayTargetIdentityOnEveryCall(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"))}
|
||||
gw := &g.Gateway{Pool: pool, Scope: backend.Bucket, Backend: backend, Isolation: verifiedFixture{}, MaxBytes: 1 << 20}
|
||||
if e := gw.InstallPlan(ctx, planFor(grant, request(t.Name(), grant))); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e := gw.Advance(ctx, 0, grant); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
token := strings.Repeat("a", 32)
|
||||
server := httptest.NewServer(g.HTTPServer{Gateway: gw, DataToken: token, ControlToken: strings.Repeat("b", 32)})
|
||||
defer server.Close()
|
||||
wrong, _ := g.NewClient(server.URL, token, "wrong-target")
|
||||
req := request(t.Name(), grant)
|
||||
receipt, e := wrong.Execute(ctx, req, []byte("gateway fixture "+t.Name()))
|
||||
if e == nil {
|
||||
cleanup(t, ctx, gw, receipt)
|
||||
t.Fatal("mutation accepted with wrong target identity")
|
||||
}
|
||||
var n int
|
||||
if pool.QueryRow(ctx, "SELECT count(*) FROM kg_object_gateway_intents WHERE scope=$1", gw.Scope).Scan(&n) != nil || n != 0 {
|
||||
t.Fatal("wrong target wrote intent")
|
||||
}
|
||||
}
|
||||
func TestGatewayClientRejectsIncompleteReceipt(t *testing.T) {
|
||||
grant := g.Grant{Epoch: 1, Owner: g.Digest([]byte("owner")), Plan: g.Digest([]byte("plan"))}
|
||||
req := request("receipt", grant)
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
_ = json.NewEncoder(w).Encode(g.Receipt{Request: req, State: "committed"})
|
||||
}))
|
||||
defer server.Close()
|
||||
c, _ := g.NewClient(server.URL, strings.Repeat("a", 32), "scope")
|
||||
if _, e := c.Execute(context.Background(), req, []byte("gateway fixture receipt")); e == nil {
|
||||
t.Fatal("committed receipt with missing exact version accepted")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user