完善部署中断恢复提示和安全阶段诊断并记录实机边界
This commit is contained in:
1 parent
b27eedc1d0
commit
6efc89061b
17 files changed
+386
-14
No files matched your search
@@ -26,9 +26,7 @@ func sanitizeDeploymentReport(report deployment.Report) deployment.Report {
|
||||
result := report
|
||||
result.Results = append([]deployment.Result(nil), report.Results...)
|
||||
for index := range result.Results {
|
||||
if result.Results[index].Status == "failed" {
|
||||
result.Results[index].Message = "证书部署失败"
|
||||
}
|
||||
result.Results[index] = deployment.PublicResult(result.Results[index])
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/deployment"
|
||||
)
|
||||
|
||||
func TestSanitizeDeploymentReportKeepsSafeDiagnosisWithoutMutatingEvidence(t *testing.T) {
|
||||
report := deployment.Report{Status: "failed", Results: []deployment.Result{
|
||||
{Status: "failed", FailureCode: deployment.FailureLock, Message: "secret-path"},
|
||||
{Status: "failed", FailureCode: "secret-code", Message: "secret-output"},
|
||||
}}
|
||||
public := sanitizeDeploymentReport(report)
|
||||
if public.Results[0].FailureCode != deployment.FailureLock || public.Results[0].Message != deployment.PublicResult(report.Results[0]).Message {
|
||||
t.Fatalf("固定锁诊断丢失:%+v", public)
|
||||
}
|
||||
if public.Results[1].FailureCode != "" || public.Results[1].Message != "证书部署失败" {
|
||||
t.Fatalf("未知诊断未脱敏:%+v", public)
|
||||
}
|
||||
if report.Results[0].Message != "secret-path" || report.Results[1].FailureCode != "secret-code" {
|
||||
t.Fatal("公开响应脱敏修改了受保护的原始证据")
|
||||
}
|
||||
stored := taskDeploymentResults(report)
|
||||
if stored[0].Message != public.Results[0].Message || stored[1].Message != "证书部署失败" {
|
||||
t.Fatalf("接口工作流未持久化安全诊断:%+v", stored)
|
||||
}
|
||||
}
|
||||
@@ -553,7 +553,7 @@ func (s *Server) listTaskDeploymentResults(c *gin.Context) {
|
||||
}
|
||||
for index := range items {
|
||||
if items[index].Status == "failed" {
|
||||
items[index].Message = "证书部署失败"
|
||||
items[index].Message = deployment.PublicStoredFailureMessage(items[index].Message)
|
||||
}
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"items": items})
|
||||
@@ -565,6 +565,7 @@ func taskDeploymentResults(report deployment.Report) []repository.TaskDeployment
|
||||
}
|
||||
items := make([]repository.TaskDeploymentResult, 0, len(report.Results))
|
||||
for index, item := range report.Results {
|
||||
item = deployment.PublicResult(item)
|
||||
items = append(items, repository.TaskDeploymentResult{
|
||||
ResultIndex: index,
|
||||
ServerID: item.ServerID,
|
||||
|
||||
@@ -78,6 +78,34 @@ func TestTaskDeploymentResultsIssueAndRead(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskDeploymentResultsKeepAllowlistedLockDiagnosis(t *testing.T) {
|
||||
raw := deployment.Result{ServerID: "server-a", Status: "failed", FailureCode: deployment.FailureLock, Message: "secret-path remote-command-output"}
|
||||
server, tasks, _, closeDB := newTaskAPITestServer(t, func(_ context.Context, id string) (certificate.IssueResult, deployment.Report, error) {
|
||||
return certificate.IssueResult{DomainID: id}, deployment.Report{Status: "failed", Total: 1, Failed: 1, Results: []deployment.Result{raw}}, errors.New("部署失败")
|
||||
})
|
||||
defer closeDB()
|
||||
response := httptest.NewRecorder()
|
||||
serveAdminHTTP(server, response, httptest.NewRequest(http.MethodPost, "/api/v1/domains/domain-1/issue", nil))
|
||||
if response.Code != http.StatusBadGateway || strings.Contains(response.Body.String(), "secret-path") || !strings.Contains(response.Body.String(), "lock_unavailable") {
|
||||
t.Fatalf("部署接口缺少安全的锁诊断:%d %s", response.Code, response.Body.String())
|
||||
}
|
||||
items, err := tasks.ListTasks(t.Context(), "", 10)
|
||||
if err != nil || len(items) != 1 {
|
||||
t.Fatalf("任务未保存:%+v %v", items, err)
|
||||
}
|
||||
response = httptest.NewRecorder()
|
||||
serveAdminHTTP(server, response, httptest.NewRequest(http.MethodGet, "/api/v1/tasks/"+items[0].ID+"/deployment-results", nil))
|
||||
var payload struct {
|
||||
Items []repository.TaskDeploymentResult `json:"items"`
|
||||
}
|
||||
if err := json.Unmarshal(response.Body.Bytes(), &payload); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if response.Code != http.StatusOK || len(payload.Items) != 1 || payload.Items[0].Message != deployment.PublicResult(raw).Message {
|
||||
t.Fatalf("任务查询丢失固定锁诊断:%d %s", response.Code, response.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskDeploymentResultsHTTPSFailurePreservesTransferEvidence(t *testing.T) {
|
||||
server, tasks, _, closeDB := newTaskAPITestServer(t, func(_ context.Context, id string) (certificate.IssueResult, deployment.Report, error) {
|
||||
return certificate.IssueResult{DomainID: id}, deployment.Report{
|
||||
|
||||
Reference in new issue
Block a user