8febe12d7d
真实本机 PG/ES/MinIO:v071 目录镜像 10 模式、结构引用/游标 15 模式、 8 表×2 外部范围身份矩阵、13 模式自然键(含软删除与合法同 parent 正例)、 备份期间三注入、收尾故障与授权撤销两个真实治理 PG 用例。 需隔离服务的用例在 test-scope.json 显式声明:普通 CI 跳过不算通过。
66 lines
2.9 KiB
Go
66 lines
2.9 KiB
Go
package v071
|
|
|
|
import (
|
|
"knowledge-governance/internal/libraryrelease"
|
|
"testing"
|
|
)
|
|
|
|
func TestContractResourceGrantHoldsRestoreBeforeObjectDeleteIsolated(t *testing.T) {
|
|
fx := openWriteSetFixture(t)
|
|
seedTargetData(t, fx)
|
|
if _, err := fx.pool.Exec(fx.ctx, `CREATE TABLE resource_access_grants(id text PRIMARY KEY,resource_id text NOT NULL REFERENCES resources(id) ON DELETE CASCADE)`); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
snapshot := sealSourceSnapshot(t, fx, nil)
|
|
target := fx.target(t)
|
|
outcome := libraryrelease.Run(fx.ctx, requestFor(snapshot), target, fx.backups(t, target), nil)
|
|
if outcome.State != "succeeded" {
|
|
t.Fatalf("publication: %+v", outcome)
|
|
}
|
|
if _, err := fx.pool.Exec(fx.ctx, `INSERT INTO resource_access_grants VALUES('after-publication','res-src')`); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
before := universeDump(t, fx.pool)
|
|
exactBefore := r10State(t, fx)
|
|
if err := target.Restore(fx.ctx, outcome.Backup); err == nil {
|
|
t.Fatal("external grant allowed destructive restore")
|
|
}
|
|
if diff := diffUniverse(before, universeDump(t, fx.pool)); diff != "" {
|
|
t.Fatalf("grant-protected restore changed PG: %s", diff)
|
|
}
|
|
r10Unchanged(t, fx, exactBefore)
|
|
var grantCount int
|
|
if err := fx.pool.QueryRow(fx.ctx, `SELECT count(*) FROM resource_access_grants WHERE id='after-publication'`).Scan(&grantCount); err != nil || grantCount != 1 {
|
|
t.Fatal("grant changed across held restore", err)
|
|
}
|
|
r10Save(t, "grant-readback", grantCount)
|
|
for _, object := range outcome.Backup.WriteSet.Objects {
|
|
if object.ResourceID == "res-src" {
|
|
got, err := fx.objects.s3.ObserveObject(fx.ctx, object.Provider, object.Locator)
|
|
if err != nil || !got.Exists || got.SHA256 != object.SHA256 {
|
|
t.Fatalf("grant-protected object lost: %v", err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestContractResourceGrantBlocksCreatedResourceCleanupIsolated(t *testing.T) {
|
|
fx := openWriteSetFixture(t)
|
|
seedTargetData(t, fx)
|
|
if _, err := fx.pool.Exec(fx.ctx, `CREATE TABLE resource_access_grants(id text PRIMARY KEY,resource_id text NOT NULL REFERENCES resources(id) ON DELETE CASCADE); INSERT INTO resources(id,tenant_id,handle) VALUES('protected-created',10001,'GrantProtectedResource'); INSERT INTO resource_access_grants VALUES('foreign-grant','protected-created')`); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
set := libraryrelease.WriteSet{Rows: []libraryrelease.WriteSetRow{{Table: "resources", ID: "protected-created"}}}
|
|
target := fx.target(t)
|
|
if err := target.clearJobCreatedRows(fx.ctx, set, map[string]map[string]bool{}); err == nil {
|
|
t.Error("cleanup cascaded external grant instead of holding recovery")
|
|
}
|
|
var grants, resources int
|
|
if err := fx.pool.QueryRow(fx.ctx, `SELECT (SELECT count(*) FROM resource_access_grants WHERE id='foreign-grant'),(SELECT count(*) FROM resources WHERE id='protected-created')`).Scan(&grants, &resources); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if grants != 1 || resources != 1 {
|
|
t.Fatalf("external FK protection lost: grants=%d resources=%d", grants, resources)
|
|
}
|
|
}
|