fix(httpapi): 恢复作业 id 改成维护窗口可接受的形状
build / build (push) Successful in 1m18s

librestore-<scope>-<时间戳.微秒> 带 ".",冻结协调器的 job 白名单只收
[A-Za-z0-9_-],所以每次恢复都在开窗口时被拒(invalid freeze request),
作业随后被接管扫成失败。改纳秒整数,并加测试锁住该约束。

试过:make verify 15 项全绿;真实恢复复现该错误后修复。
This commit is contained in:
姚章浩
2026-10-29 06:28:29 +08:00
parent b061a9686c
commit a6406209bd
3 changed files with 39 additions and 2 deletions
+28
View File
@@ -85,3 +85,31 @@ func TestLibraryJobResumeRejectsNonFailedJobs(t *testing.T) {
t.Fatalf("status=%d body=%s", recorder.Code, recorder.Body.String())
}
}
// 恢复作业 id 会作为维护窗口的 job 标识落进 freeze journal,协调器只接受
// [A-Za-z0-9_-]。带 "." 的时间戳曾经让每次恢复都在开窗口时被拒(invalid freeze request)。
func TestLibraryRestoreJobIDIsAFreezeSafeIdentifier(t *testing.T) {
store := &fakeLibraryStore{fakeJobStore: fakeJobStore{enqueueEchoRequestedID: true}}
digest, err := libraryRestoreParamsDigest("internal", "snap-1")
if err != nil {
t.Fatal(err)
}
now := time.Now().UTC()
store.grant = &governance.LibraryReleaseAuthorization{ID: "a", Scope: "internal", SnapshotID: "snap-1",
ParamsDigest: digest, ExpiresAt: now.Add(time.Hour), CreatedAt: now}
config := Config{Store: store, ProductionReleaseRequestsEnabled: true, ProductionBackupRestoreVerified: true}
recorder := httptest.NewRecorder()
libraryRestoreEnqueue(recorder, restoreRequest(`{"scope":"internal","snapshot_id":"snap-1"}`, roleAdmin), config)
if recorder.Code != http.StatusAccepted {
t.Fatalf("status=%d body=%s", recorder.Code, recorder.Body.String())
}
id := store.lastJob.ID
if id == "" || len(id) > 128 {
t.Fatalf("作业 id 形状不对:%q", id)
}
for _, r := range id {
if !(r >= 'a' && r <= 'z' || r >= 'A' && r <= 'Z' || r >= '0' && r <= '9' || r == '-' || r == '_') {
t.Fatalf("作业 id 含维护窗口不接受的字符 %q:%q", r, id)
}
}
}