Expand test coverage across server, agent, and web; fix bugs found during audit.
Adds hundreds of unit/integration/e2e tests, fixes WS bcrypt auth, config merge, fleet analytics, agent schedule/log tail, and documents stale PROBLEMS items. Updates PROBLEMS.md, README, and test scripts; ignores local spread-kits and coverage dirs.
This commit is contained in:
@@ -180,11 +180,12 @@ func TestAIHandleDecideSuccess(t *testing.T) {
|
||||
srv := mockOllamaChatServer(t, content, http.StatusOK)
|
||||
defer srv.Close()
|
||||
|
||||
// Engine must be pre-registered via WS auth (caller-supplied endpoint is ignored to prevent SSRF).
|
||||
h.SetEngineForAgent("agent-decide-ok", srv.URL, "test-model")
|
||||
|
||||
body, _ := json.Marshal(map[string]interface{}{
|
||||
"agent_id": "agent-decide-ok",
|
||||
"ollama_endpoint": srv.URL,
|
||||
"model": "test-model",
|
||||
"hostname": "host1",
|
||||
"agent_id": "agent-decide-ok",
|
||||
"hostname": "host1",
|
||||
})
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/v1/agent/decide", bytes.NewReader(body))
|
||||
w := httptest.NewRecorder()
|
||||
@@ -220,9 +221,11 @@ func TestAIHandleDecideOllamaFailureFallback(t *testing.T) {
|
||||
srv := mockOllamaChatServer(t, "", http.StatusInternalServerError)
|
||||
defer srv.Close()
|
||||
|
||||
// Engine must be pre-registered; caller-supplied endpoint is ignored (SSRF prevention).
|
||||
h.SetEngineForAgent("agent-decide-fail", srv.URL, "")
|
||||
|
||||
body, _ := json.Marshal(map[string]interface{}{
|
||||
"agent_id": "agent-decide-fail",
|
||||
"ollama_endpoint": srv.URL,
|
||||
"agent_id": "agent-decide-fail",
|
||||
})
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/v1/agent/decide", bytes.NewReader(body))
|
||||
w := httptest.NewRecorder()
|
||||
@@ -251,25 +254,27 @@ func TestAIHandleDecideOllamaFailureFallback(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAIHandleDecideCreatesEngineOnFirstRequest(t *testing.T) {
|
||||
// TestAIHandleDecideRejectsUnregisteredAgent verifies that decide returns 403
|
||||
// when the agent has not first authenticated via WebSocket. This prevents SSRF
|
||||
// by ensuring the server never initiates an outbound Ollama request to a
|
||||
// caller-supplied URL.
|
||||
func TestAIHandleDecideRejectsUnregisteredAgent(t *testing.T) {
|
||||
h := newTestAIHandler(t)
|
||||
content := ollamaDecideContent("idle", nil)
|
||||
srv := mockOllamaChatServer(t, content, http.StatusOK)
|
||||
defer srv.Close()
|
||||
|
||||
body, _ := json.Marshal(map[string]interface{}{
|
||||
"agent_id": "agent-new",
|
||||
"ollama_endpoint": srv.URL,
|
||||
"agent_id": "agent-not-in-ws",
|
||||
"ollama_endpoint": "http://internal-server/v1/chat",
|
||||
"model": "m1",
|
||||
})
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/v1/agent/decide", bytes.NewReader(body))
|
||||
w := httptest.NewRecorder()
|
||||
h.HandleDecide(w, req)
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("status %d %s", w.Code, w.Body.String())
|
||||
if w.Code != http.StatusForbidden {
|
||||
t.Fatalf("unregistered agent should get 403, got %d body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
if h.GetEngine("agent-new") == nil {
|
||||
t.Fatal("engine should exist after first decide")
|
||||
// Engine must NOT be created from the caller-supplied URL.
|
||||
if h.GetEngine("agent-not-in-ws") != nil {
|
||||
t.Fatal("engine should NOT be created from caller-supplied endpoint")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user