完善域名服务器多对多关联与共享路径预检,补齐回归源码及进度文档
支持同项目内域名与服务器双向复用,局部修改和清空不影响其他域名;在绑定保存、服务器编辑和部署前拒绝已知共享路径冲突。 新增仓储、接口、工作流与页面回归源码,同步任务状态和第三版接口交接。按要求先开发后统一测试,本批未运行测试、构建或部署,保留在途任务与主机别名等待办。
This commit is contained in:
1 parent
f38e290b22
commit
e2200534d3
25 files changed
+740
-41
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/domain"
|
||||
)
|
||||
|
||||
var ErrSharedPathConflict = errors.New("多个域名的远程证书路径冲突,请使用按域名区分的证书、证书链和私钥路径")
|
||||
|
||||
// 比较实际展开并规范化后的全部文件路径,不仅检查模板是否含有域名占位符。
|
||||
// 错误不携带其他域名名称、资源标识或远程私钥路径。
|
||||
func ValidateServerDomainPaths(server Server, domains []domain.Domain) error {
|
||||
paths := make([]string, 0, len(domains)*3)
|
||||
for _, item := range domains {
|
||||
resolved, err := ResolveServerPaths(server, item.Name, string(item.CertificateType))
|
||||
if err != nil {
|
||||
return fmt.Errorf("关联域名的远程证书路径无效:%w", err)
|
||||
}
|
||||
current := []string{resolved.CertificatePath, resolved.CertificateChainPath, resolved.PrivateKeyPath}
|
||||
for _, candidate := range current {
|
||||
for _, existing := range paths {
|
||||
if candidate == existing || strings.HasPrefix(candidate, existing+"/") || strings.HasPrefix(existing, candidate+"/") {
|
||||
return ErrSharedPathConflict
|
||||
}
|
||||
}
|
||||
}
|
||||
paths = append(paths, current...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package deployment
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/domain"
|
||||
)
|
||||
|
||||
func TestSharedServerDomainPaths(t *testing.T) {
|
||||
domains := []domain.Domain{
|
||||
{ID: "a", Name: "a.example.test", CertificateType: domain.CertificateSingle},
|
||||
{ID: "b", Name: "b.example.test", CertificateType: domain.CertificateSingle},
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
server Server
|
||||
conflict bool
|
||||
}{
|
||||
{name: "default_templates"},
|
||||
{name: "english_templates", server: Server{CertificatePath: "/ssl/{domain}/cert.pem", CertificateChainPath: "/ssl/{domain}/chain.pem", PrivateKeyPath: "/ssl/{domain}/key.pem"}},
|
||||
{name: "fixed_certificate", server: Server{CertificatePath: "/ssl/cert.pem"}, conflict: true},
|
||||
{name: "fixed_chain", server: Server{CertificateChainPath: "/ssl/chain.pem"}, conflict: true},
|
||||
{name: "fixed_key", server: Server{PrivateKeyPath: "/ssl/key.pem"}, conflict: true},
|
||||
{name: "collapsed_placeholder", server: Server{CertificatePath: "/ssl/{domain}/../cert.pem"}, conflict: true},
|
||||
{name: "cross_file_collision", server: Server{CertificatePath: "/ssl/{domain}/b.example.test", PrivateKeyPath: "/ssl/a.example.test/{domain}"}, conflict: true},
|
||||
{name: "file_directory_collision", server: Server{CertificatePath: "/ssl/{domain}/b.example.test", PrivateKeyPath: "/ssl/a.example.test/{domain}/key.pem"}, conflict: true},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
err := ValidateServerDomainPaths(tc.server, domains)
|
||||
if tc.conflict {
|
||||
if !errors.Is(err, ErrSharedPathConflict) {
|
||||
t.Fatalf("共享路径冲突未拒绝:%v", err)
|
||||
}
|
||||
} else if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
if err := ValidateServerDomainPaths(Server{CertificatePath: "/ssl/cert.pem"}, domains[:1]); err != nil {
|
||||
t.Fatalf("单域名固定路径应保持兼容:%v", err)
|
||||
}
|
||||
for _, item := range []domain.Domain{
|
||||
{ID: "other", Name: "a.example.test", CertificateType: domain.CertificateSingle},
|
||||
{ID: "wildcard", Name: "*.a.example.test", CertificateType: domain.CertificateSingle},
|
||||
} {
|
||||
if err := ValidateServerDomainPaths(Server{}, []domain.Domain{domains[0], item}); !errors.Is(err, ErrSharedPathConflict) {
|
||||
t.Fatalf("规范化后同路径的资源未拒绝:%v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user