通过本机Unix套接字报告HTTPS监听状态,同步服务配置与安装模板,保持初始化业务就绪隔离。补充生命周期回归并修复旧CLI测试误用正式目录的问题。更新Linux原生测试证据,明确新候选尚未部署、生产验收未放行。
36 lines
1.1 KiB
Go
36 lines
1.1 KiB
Go
package cli
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.pcux.cn/xuans/Scert/backend/internal/config"
|
|
)
|
|
|
|
// isolatedCLIConfig 明确覆盖 Linux 的正式安装路径,测试不得访问现有服务数据。
|
|
func isolatedCLIConfig(root string) config.Config {
|
|
cfg := config.Default(root)
|
|
cfg.Paths = config.PathsConfig{
|
|
Install: root,
|
|
Config: filepath.Join(root, "conf"),
|
|
Data: filepath.Join(root, "data"),
|
|
Certificate: filepath.Join(root, "ssl"),
|
|
Log: filepath.Join(root, "log"),
|
|
Backup: filepath.Join(root, "backups"),
|
|
}
|
|
cfg.Database.DSN = filepath.Join(cfg.Paths.Data, "scert.db")
|
|
return cfg
|
|
}
|
|
|
|
func TestCLIConfigStaysInTempRoot(t *testing.T) {
|
|
root := t.TempDir()
|
|
cfg := isolatedCLIConfig(root)
|
|
for _, path := range []string{cfg.Paths.Install, cfg.Paths.Config, cfg.Paths.Data, cfg.Paths.Certificate, cfg.Paths.Log, cfg.Paths.Backup, cfg.Database.DSN} {
|
|
relative, err := filepath.Rel(root, path)
|
|
if err != nil || filepath.IsAbs(relative) || relative == ".." || strings.HasPrefix(relative, ".."+string(filepath.Separator)) {
|
|
t.Fatalf("测试配置逃逸出临时目录:%s", path)
|
|
}
|
|
}
|
|
}
|