完善证书任务依赖缺失处理
This commit is contained in:
parent
527c0e7519
commit
e2b75d29ea
@ -20,6 +20,10 @@ func (s *Server) issueDomainAsTask(c *gin.Context) {
|
|||||||
s.writeError(c, http.StatusNotImplemented, "证书申请接口尚未配置", errors.New("证书申请工作流未配置"))
|
s.writeError(c, http.StatusNotImplemented, "证书申请接口尚未配置", errors.New("证书申请工作流未配置"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if s.repository == nil || s.tasks == nil {
|
||||||
|
s.writeError(c, http.StatusNotImplemented, "证书任务接口尚未配置", errors.New("域名仓储或任务仓储未配置"))
|
||||||
|
return
|
||||||
|
}
|
||||||
domainID := strings.TrimSpace(c.Param("id"))
|
domainID := strings.TrimSpace(c.Param("id"))
|
||||||
if _, err := s.repository.GetByID(c.Request.Context(), domainID); err != nil {
|
if _, err := s.repository.GetByID(c.Request.Context(), domainID); err != nil {
|
||||||
if repository.IsNotFound(err) {
|
if repository.IsNotFound(err) {
|
||||||
|
|||||||
@ -224,3 +224,19 @@ func TestTaskAPIReplaysIdempotentIssue(t *testing.T) {
|
|||||||
t.Fatalf("幂等键没有正确保存:%+v %v", items, err)
|
t.Fatalf("幂等键没有正确保存:%+v %v", items, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTaskAPIReturnsNotImplementedWhenTaskDependenciesAreMissing(t *testing.T) {
|
||||||
|
cfg := readyTestConfig(t.TempDir())
|
||||||
|
server := New(Dependencies{
|
||||||
|
Config: cfg,
|
||||||
|
Tasks: (*repository.SQLTaskRepository)(nil),
|
||||||
|
IssueCertificate: func(context.Context, string) (certificate.IssueResult, deployment.Report, error) {
|
||||||
|
return certificate.IssueResult{}, deployment.Report{}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
response := httptest.NewRecorder()
|
||||||
|
serveAdminHTTP(server, response, httptest.NewRequest(http.MethodPost, "/api/v1/domains/domain-1/issue", nil))
|
||||||
|
if response.Code != http.StatusNotImplemented || !strings.Contains(response.Body.String(), "证书任务接口尚未配置") {
|
||||||
|
t.Fatalf("任务依赖缺失时应返回 501:%d %s", response.Code, response.Body.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user