Scert/backend/internal/app/certificate_authorization_test.go

40 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package app
import (
"context"
"errors"
"testing"
"git.pcux.cn/xuans/Scert/backend/internal/certificate"
"git.pcux.cn/xuans/Scert/backend/internal/deployment"
)
type deniedWorkflowCertificateService struct {
workflowCertificateService
}
func (*deniedWorkflowCertificateService) Issue(context.Context, string) (certificate.IssueResult, error) {
return certificate.IssueResult{}, errors.New("DNS 凭据无权操作域名:Forbidden.NoPermission")
}
type forbiddenDeployer struct {
t *testing.T
}
func (d forbiddenDeployer) DeploySaved(context.Context, []deployment.Target, deployment.SavedFiles) (deployment.Report, error) {
d.t.Fatal("权限检查失败后不得发起 SSH/SFTP 部署")
return deployment.Report{}, nil
}
func TestWorkflowDoesNotDeployAfterDNSPermissionDenied(t *testing.T) {
workflow := &CertificateWorkflow{
Certificates: &deniedWorkflowCertificateService{},
Domains: &workflowDomainState{},
Servers: workflowServerLister{servers: []deployment.Server{{ID: "target"}}},
Deployment: forbiddenDeployer{t: t},
}
if _, err := workflow.IssueWithReport(t.Context(), "domain"); err == nil {
t.Fatal("权限失败不得报告工作流成功")
}
}