feat: 优化代理准备并完善远端部署

- 增加严格代理、两分钟预取、白名单去重与分组状态展示\n- 增加远端注册令牌和安全地址校验\n- 增加 Docker Compose、Caddy 示例与控制中心部署文档
This commit is contained in:
yml
2026-11-21 20:59:35 +08:00
parent d176c421a8
commit 9c83be798d
43 changed files with 2755 additions and 119 deletions
+35
View File
@@ -137,6 +137,12 @@ func TestLoadConfigNormalizesProxySparePercent(t *testing.T) {
if got := LoadConfig(path).ProxySparePercent; got != constants.DefaultProxySparePercent {
t.Fatalf("ProxySparePercent=%d, want %d", got, constants.DefaultProxySparePercent)
}
if err := os.WriteFile(path, []byte(`{"proxySparePercent":25}`), 0600); err != nil {
t.Fatal(err)
}
if got := LoadConfig(path).ProxySparePercent; got != constants.MinProxySparePercent {
t.Fatalf("legacy ProxySparePercent=%d, want minimum %d", got, constants.MinProxySparePercent)
}
if err := os.WriteFile(path, []byte(`{"proxySparePercent":999}`), 0600); err != nil {
t.Fatal(err)
}
@@ -145,6 +151,35 @@ func TestLoadConfigNormalizesProxySparePercent(t *testing.T) {
}
}
func TestLoadConfigDefaultsToStrictProxyMode(t *testing.T) {
path := filepath.Join(t.TempDir(), "config.json")
if got := LoadConfig(path).ProxyRequired; !got {
t.Fatal("new config should default to strict proxy mode")
}
if err := os.WriteFile(path, []byte(`{}`), 0600); err != nil {
t.Fatal(err)
}
if got := LoadConfig(path).ProxyRequired; !got {
t.Fatal("legacy config without proxyRequired should inherit strict mode")
}
if err := os.WriteFile(path, []byte(`{"proxyRequired":false}`), 0600); err != nil {
t.Fatal(err)
}
if got := LoadConfig(path).ProxyRequired; got {
t.Fatal("explicit proxyRequired=false should disable strict mode")
}
}
func TestLoadConfigNormalizesRemoteEnrollmentToken(t *testing.T) {
path := filepath.Join(t.TempDir(), "config.json")
if err := os.WriteFile(path, []byte(`{"remoteEnrollmentToken":" enroll-secret "}`), 0600); err != nil {
t.Fatal(err)
}
if got := LoadConfig(path).RemoteEnrollmentToken; got != "enroll-secret" {
t.Fatalf("RemoteEnrollmentToken=%q, want trimmed token", got)
}
}
func TestLoadConfigMigratesLegacyTimeAPI(t *testing.T) {
path := filepath.Join(t.TempDir(), "config.json")
content := []byte(`{"timeApiUrl":"` + constants.LegacyDefaultTimeAPI + `"}`)