完成证书历史版本恢复核心实现

补充历史证书版本读取、稳定标识、完整证书链恢复、恢复回滚保护及接口安全输出,并同步更新整改任务进度。
This commit is contained in:
xuans committed 2026-10-03 01:14:12 +08:00
1 parent 3c59ac5e80
commit 3f6a05d2b9
11 files changed
+864 -102

No files matched your search

+10 -5
View File
@@ -22,9 +22,10 @@ import (
)
type serviceRepository struct {
item domain.Domain
states []string
updateErr error
item domain.Domain
states []string
updateErr error
updateCalls int
}
func (r *serviceRepository) GetByID(_ context.Context, _ string) (domain.Domain, error) {
@@ -32,6 +33,7 @@ func (r *serviceRepository) GetByID(_ context.Context, _ string) (domain.Domain,
}
func (r *serviceRepository) UpdateCertificateState(_ context.Context, _ string, status string, expiresAt *time.Time) error {
r.updateCalls++
if status == "valid" && r.updateErr != nil {
return r.updateErr
}
@@ -301,8 +303,11 @@ func TestServiceRestoreVersionRollsBackFilesWhenStateUpdateFails(t *testing.T) {
}
repository := &serviceRepository{item: item, updateErr: errors.New("simulated state update failure")}
service := NewService(cfg, repository, nil, nil, nil)
if _, err := service.RestoreVersion(context.Background(), item.ID, first.Version); err == nil {
t.Fatal("state update failure should be returned")
if _, err := service.RestoreVersion(context.Background(), item.ID, first.Version); !errors.Is(err, repository.updateErr) {
t.Fatalf("必须实际到达状态更新并返回注入的错误:%v", err)
}
if repository.updateCalls != 1 {
t.Fatalf("恢复未实际到达状态更新:调用次数=%d", repository.updateCalls)
}
afterCertificate, err := os.ReadFile(second.CertificatePath)
if err != nil {