test(library): 跨SHA兼容升级保留为拒绝RED
同协议批次下换一个合法 40 位 SHA 不能被 epoch 相等证明;激活与使用点都必须 拒绝。当前实现仍会接受(compatible_upgrade=true),此提交先把期望钉在拒绝上, 作为修复前的 RED 证据;同 SHA 正例与同 SHA 错 display 拒绝一并保留。
This commit is contained in:
@@ -223,24 +223,42 @@ VALUES ($1,$2,'internal',$3,'instance',$4::jsonb,'closed','needs_restore','','',
|
||||
t.Fatalf("rejected evidence created %d activation rows", n)
|
||||
}
|
||||
|
||||
// 5) 合法兼容升级:不同完整 SHA、同一协议批次 ⇒ 允许,但必须显式记成升级。
|
||||
compat := base()
|
||||
compat.ProtocolBuild = "0.1.999-compatible"
|
||||
compat.ProtocolBuildSHA = strings.Repeat("a", 40)
|
||||
if err := activate(compat); err != nil {
|
||||
t.Fatalf("compatible upgrade evidence: %v", err)
|
||||
// 5) 同一协议批次、任意 40 位 SHA:epoch 相等不能替代构建身份证明,必须拒绝。
|
||||
// 原实现只凭 epoch==3 就接受任何 SHA(compatible_upgrade=true),换一个 SHA 即可
|
||||
// 绕开同 SHA display 绑定;本轮关闭这条无证据的跨 SHA 自动兼容。
|
||||
evidence = base()
|
||||
evidence.ProtocolBuild = version.DisplayVersion()
|
||||
evidence.ProtocolBuildSHA = strings.Repeat("b", 40)
|
||||
if err := activate(evidence); err == nil || !strings.Contains(err.Error(), "cross-sha") {
|
||||
t.Fatalf("same-epoch unknown build sha was accepted: %v", err)
|
||||
}
|
||||
|
||||
// 6) 同 SHA、错 display:运行二进制身份必须自洽。
|
||||
evidence = base()
|
||||
evidence.ProtocolBuild = "0.1.999-wrong"
|
||||
if err := activate(evidence); err == nil || !strings.Contains(err.Error(), "display") {
|
||||
t.Fatalf("same-sha wrong display = %v", err)
|
||||
}
|
||||
if n := count(); n != 0 {
|
||||
t.Fatalf("rejected evidence created %d activation rows", n)
|
||||
}
|
||||
|
||||
// 7) 同 SHA、同 display:唯一允许的绑定;台账不得再声明 compatible_upgrade。
|
||||
if err := activate(base()); err != nil {
|
||||
t.Fatalf("same-sha activation: %v", err)
|
||||
}
|
||||
var stored string
|
||||
if err := pool.QueryRow(ctx, `SELECT evidence::text FROM library_index_restore_dispatch_activation WHERE target_identity=$1`, target).Scan(&stored); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
compact := strings.ReplaceAll(stored, " ", "")
|
||||
if !strings.Contains(compact, `"compatible_upgrade":true`) ||
|
||||
!strings.Contains(compact, `"system_identifier":"`+compat.GovernanceAuthority.SystemIdentifier+`"`) {
|
||||
t.Fatalf("activation record does not state the verified authority/upgrade: %s", stored)
|
||||
if !strings.Contains(compact, `"compatible_upgrade":false`) ||
|
||||
!strings.Contains(compact, `"protocol_build_sha":"`+version.CommitSHA+`"`) ||
|
||||
!strings.Contains(compact, `"system_identifier":"`+base().GovernanceAuthority.SystemIdentifier+`"`) {
|
||||
t.Fatalf("activation record does not state the exact build/authority: %s", stored)
|
||||
}
|
||||
|
||||
// 使用点正例:同一兼容批次下真实窗口可以准备/取得许可。
|
||||
// 使用点正例:与激活相同的 SHA 下真实窗口可以准备/取得许可。
|
||||
windowOp := seedOperationJob(t, store, pool, "internal", "libsync-ds01-authority", "sync", now)
|
||||
if _, err := store.BeginLibraryAttempt(ctx, "libsync-ds01-authority", "worker-a#q1#0", 10*time.Minute, now); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -270,6 +288,10 @@ VALUES ($1,$2,'internal',$3,'instance',$4::jsonb,'closed','needs_restore','','',
|
||||
"target-ds01-tamper-sha": func(v map[string]any) {
|
||||
v["protocol_build_sha"] = "unknown"
|
||||
},
|
||||
"target-ds01-tamper-cross-sha": func(v map[string]any) {
|
||||
// 同一协议批次下换一个合法 40 位 SHA:使用点必须与激活点同样拒绝。
|
||||
v["protocol_build_sha"] = strings.Repeat("c", 40)
|
||||
},
|
||||
}
|
||||
for tamperTarget, mutate := range tamperTargets {
|
||||
var record map[string]any
|
||||
|
||||
Reference in New Issue
Block a user