接入本机人工处置协议和终端并记录Linux回归进度

This commit is contained in:
xuans committed 2026-10-03 21:33:54 +08:00
1 parent bf4caebaae
commit 0f2e6bfcce
24 files changed
+1534 -48

No files matched your search

@@ -36,6 +36,17 @@ type RecoveryReviewSummary struct {
ExpiresAt time.Time `json:"expires_at"`
}
// Validate 与服务端历史记录使用同一摘要边界,允许旧记录没有阶段,但不允许控制字符或超长字段。
func (r RecoveryReviewSummary) Validate() error {
if !validInspectionID(r.TransactionID) || !validRecoverySummary(r.ServerID) ||
(r.Phase != "" && !validRecoverySummary(r.Phase)) || !validRecoveryAction(r.Action) ||
r.ObservedAt.IsZero() || !r.ExpiresAt.After(r.ObservedAt) || r.ExpiresAt.Sub(r.ObservedAt) > RecoveryReviewLifetime ||
(r.Action != RecoveryActionRecord && !r.HistoricalEvidence) {
return ErrRecoveryReviewInvalid
}
return nil
}
// RecoveryReview 只保存只读准备摘要和不可公开的绑定值,不保存凭据或原始恢复证据。
// 它不是执行授权;调用者仍须取得持久化占用、验证动作条件并原子写入审计。
type RecoveryReview struct {
@@ -11,6 +11,38 @@ import (
"time"
)
func TestRecoveryReviewSummaryBoundary(t *testing.T) {
now := time.Now().UTC()
valid := RecoveryReviewSummary{TransactionID: "tx-1", ServerID: "历史服务器", Action: RecoveryActionRecord, ObservedAt: now, ExpiresAt: now.Add(time.Minute)}
if err := valid.Validate(); err != nil {
t.Fatalf("valid legacy summary rejected: %v", err)
}
for _, mode := range []string{"id", "server", "phase", "action", "evidence", "observed", "expired", "lifetime"} {
value := valid
switch mode {
case "id":
value.TransactionID = "../bad"
case "server":
value.ServerID = strings.Repeat("s", 161)
case "phase":
value.Phase = "phase\n"
case "action":
value.Action = "unknown"
case "evidence":
value.Action = RecoveryActionCommit
case "observed":
value.ObservedAt = time.Time{}
case "expired":
value.ExpiresAt = now
case "lifetime":
value.ExpiresAt = now.Add(time.Hour)
}
if value.Validate() == nil {
t.Fatalf("invalid summary accepted: %s", mode)
}
}
}
func TestRecoveryReviewReadOnlyBindings(t *testing.T) {
for _, action := range []RecoveryAction{RecoveryActionRecord, RecoveryActionCommit, RecoveryActionRollback} {
t.Run(string(action), func(t *testing.T) {