完善证书管理与初始化流程

This commit is contained in:
xuans committed 2026-08-27 22:16:10 +08:00
1 parent 07636abe44
commit c74372284a
84 files changed
+10151 -3502

No files matched your search

+40
View File
@@ -4,6 +4,7 @@ import (
"os"
"path/filepath"
"runtime"
"strings"
"testing"
)
@@ -76,3 +77,42 @@ func TestValidateRejectsInvalidPort(t *testing.T) {
t.Fatal("无效端口未被拒绝")
}
}
func TestResetURLUsesWebHostnameWithoutPort(t *testing.T) {
cfg := Default(t.TempDir())
cfg.Web.Hostname = "scert.example.test"
cfg.Server.Port = 8443
if value := cfg.ResetURL(); value != "https://scert.example.test/reset" {
t.Fatalf("域名密码重置地址不正确:%s", value)
}
cfg.Server.Port = 443
if value := cfg.ResetURL(); value != "https://scert.example.test/reset" {
t.Fatalf("默认 HTTPS 端口不应显示端口号:%s", value)
}
}
func TestResetURLSupportsPublicIPv6(t *testing.T) {
cfg := Default(t.TempDir())
cfg.Web.PublicIP = "2001:db8::10"
cfg.Server.Port = 8443
if value := cfg.ResetURL(); value != "https://[2001:db8::10]/reset" {
t.Fatalf("IPv6 密码重置地址不正确:%s", value)
}
}
func TestSavedConfigDoesNotContainIndependentResetPort(t *testing.T) {
dir := t.TempDir()
cfg := Default(dir)
path := filepath.Join(dir, "config", "scert.json")
if err := cfg.Save(path); err != nil {
t.Fatalf("保存配置失败:%v", err)
}
data, err := os.ReadFile(path)
if err != nil {
t.Fatalf("读取配置失败:%v", err)
}
content := string(data)
if strings.Contains(content, "reset_service_port") || strings.Contains(content, "reset_service_host") {
t.Fatalf("配置文件不应再包含独立密码重置监听配置:%s", content)
}
}