fix: 正确识别 Agent 安装与审计失败

- 下载脚本失败时立即终止安装并提示 WAF 拦截
- Agent 服务未运行时不再计为安装成功
- 审计列表兼容后端 status 成功失败字段
This commit is contained in:
Logan.Li committed 2026-07-25 15:08:04 +08:00
1 parent 7553ef54de
commit 827d9a31cd
3 files changed
+75 -25

No files matched your search

+23 -1
View File
@@ -1,6 +1,9 @@
package controller
import "testing"
import (
"strings"
"testing"
)
// TestValidateInstallServerURL 验证 Agent 公网地址仅接受安全的 HTTP(S) origin。 // Logan.Li
func TestValidateInstallServerURL(t *testing.T) {
@@ -36,3 +39,22 @@ func TestValidateInstallServerURL(t *testing.T) {
})
}
}
// TestAgentInstallCommand 验证下载失败不会被管道末端命令掩盖。 // Logan.Li
func TestAgentInstallCommand(t *testing.T) {
command := agentInstallCommand("https://aiops.example.com", "token-value")
if strings.Contains(command, "| bash") {
t.Fatalf("安装命令不应继续使用 curl 管道: %s", command)
}
if !strings.Contains(command, "curl -fsSL -o") || !strings.Contains(command, "https://aiops.example.com/agent/install.sh") {
t.Fatalf("安装命令缺少脚本下载步骤: %s", command)
}
}
// TestAgentInstallErrorMessage 验证 WAF 拒绝能返回明确提示。 // Logan.Li
func TestAgentInstallErrorMessage(t *testing.T) {
message := agentInstallErrorMessage("https://aiops.example.com", "curl: (22) The requested URL returned error: 403")
if !strings.Contains(message, "WAF") || !strings.Contains(message, "/agent/*") {
t.Fatalf("WAF 错误提示不完整: %s", message)
}
}