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
+67
View File
@@ -34,6 +34,29 @@ func TestLoadOrCreateMachineIDSharedByInstances(t *testing.T) {
}
}
func TestValidateServerURLRequiresControlCenterRoot(t *testing.T) {
for _, raw := range []string{
"https://control.example.com/#admin=secret",
"https://control.example.com/control",
"https://control.example.com/?token=secret",
"https://user:pass@control.example.com",
} {
if err := ValidateServerURL(raw); err == nil {
t.Fatalf("ValidateServerURL(%q) should fail", raw)
}
}
for _, raw := range []string{
"https://control.example.com",
"https://control.example.com/",
"http://127.0.0.1:18080",
"wss://control.example.com",
} {
if err := ValidateServerURL(raw); err != nil {
t.Fatalf("ValidateServerURL(%q): %v", raw, err)
}
}
}
func TestEventSpoolPersistsOffset(t *testing.T) {
dir := t.TempDir()
spool, err := NewEventSpool(dir)
@@ -209,6 +232,50 @@ func TestAgentAutoEnrollsWithoutManualToken(t *testing.T) {
}
}
func TestAgentEnrollsWithConfiguredEnrollmentToken(t *testing.T) {
server, err := NewServer(ServerOptions{
DataDir: t.TempDir(),
OperatorToken: "operator-token",
EnrollToken: "enroll-secret",
})
if err != nil {
t.Fatal(err)
}
defer server.Close()
httpServer := httptest.NewServer(server.Handler())
defer httpServer.Close()
dataDir := t.TempDir()
agent, err := NewAgent(AgentOptions{
DataDir: dataDir,
ServerURL: httpServer.URL,
EnrollmentToken: "enroll-secret",
MachineID: "machine-secure",
MachineName: "PC-SECURE",
InstanceID: "实例 4",
Instance: "实例 4",
Version: "test",
})
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
agent.Start(ctx)
defer agent.Close()
waitUntil(t, 5*time.Second, func() bool {
instances := server.hub.Dashboard().Instances
return len(instances) == 1 && instances[0].Online
})
token, err := loadAgentCredential(dataDir, httpServer.URL, "machine-secure", "实例 4")
if err != nil {
t.Fatal(err)
}
if token == "" || token == "enroll-secret" {
t.Fatalf("unexpected issued instance token %q", token)
}
}
func TestHubAggregatesDynamicInstanceCount(t *testing.T) {
hub, err := NewHub(t.TempDir())
if err != nil {