Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Align Patrol prober with agent command policy

rcourtman6127d412d3ea
diff --git a/docs/release-control/v6/internal/records/agent-lifecycle-ai-discovery-adapter-origin-2026-05-01.md b/docs/release-control/v6/internal/records/agent-lifecycle-ai-discovery-adapter-origin-2026-05-01.md
new file mode 100644
index 0000000000..f671fa8f87
--- /dev/null
+++ b/docs/release-control/v6/internal/records/agent-lifecycle-ai-discovery-adapter-origin-2026-05-01.md
@@ -0,0 +1,48 @@
+# Agent Lifecycle AI Discovery Adapter Origin Record
+
+- Date: `2026-05-01`
+- Lane: `L16`
+- Gate: `known-rc-issue-closure-for-ga`
+- Result: `passed`
+
+## Context
+
+The v5 maintenance audit rechecked the oversized AI discovery response fix in
+the v6 candidate. The discovery token budget and service-discovery prompt caps
+were already present, but the broader proof command exposed stale assumptions in
+the AI-to-agent execution boundary:
+
+- the discovery command adapter and Patrol prober tests opened the secured agent
+ WebSocket without the same-origin `Origin` header now required by the
+ canonical agent execution server;
+- the production Patrol reachability prober still composed a compound shell ping
+ loop, which the current agent command policy correctly rejects because
+ compound commands require approval.
+
+## Disposition
+
+The AI agent-exec tests now derive the WebSocket origin through the shared
+security helper and send it on mock agent registration connections. The Patrol
+reachability prober now validates each target as an IP address and sends one
+single-target `ping -c 1 -W 1 <ip>` command per target; the agent command policy
+explicitly auto-approves only that read-only IP probe shape while still rejecting
+hostnames and compound ping commands.
+
+This keeps the test harness aligned with the production handshake and fixes the
+runtime reachability prober through the policy-owned command contract instead of
+weakening origin enforcement or bypassing command approval.
+
+## Proof
+
+- `go test ./internal/ai -run 'TestDiscoveryCommandAdapter|AnalyzeForDiscovery|Discovery.*Token|Token.*Discovery|MaxTokens' -count=1`
+- `go test ./internal/ai -run 'TestDiscoveryCommandAdapter|TestAgentExecProber|AnalyzeForDiscovery|Discovery.*Token|Token.*Discovery|MaxTokens' -count=1`
+- `go test ./internal/agentexec -run 'TestDefaultPolicyEvaluate|TestPolicyHelpers' -count=1`
+- `go test ./internal/servicediscovery -run 'Discovery|ServiceDiscovery|Prompt|Limit|Oversized|Large' -count=1`
+- `go test ./internal/ai ./internal/servicediscovery -run 'Discovery|ServiceDiscovery|MaxTokens|Token|oversized|Large' -count=1`
+- `go test ./internal/agentexec ./internal/ai ./internal/servicediscovery -count=1`
+
+## Outcome
+
+The v5 oversized-discovery-response fix remains present in v6, the RC3 proof
+command now exercises the secured agent WebSocket path successfully, and Patrol's
+agent-backed reachability probe is aligned with the current command policy.
diff --git a/docs/release-control/v6/internal/status.json b/docs/release-control/v6/internal/status.json
index e643e5fc7a..cee04cebd4 100644
--- a/docs/release-control/v6/internal/status.json
+++ b/docs/release-control/v6/internal/status.json
@@ -3337,6 +3337,11 @@
"path": "docs/release-control/v6/internal/records/agent-lifecycle-agent-privilege-docs-2026-05-01.md",
"kind": "file"
},
+ {
+ "repo": "pulse",
+ "path": "docs/release-control/v6/internal/records/agent-lifecycle-ai-discovery-adapter-origin-2026-05-01.md",
+ "kind": "file"
+ },
{
"repo": "pulse",
"path": "docs/release-control/v6/internal/records/unified-agent-v5-upgrade-continuity-2026-03-12.md",
@@ -4369,6 +4374,12 @@
"L16"
],
"evidence": [
+ {
+ "repo": "pulse",
+ "path": "docs/release-control/v6/internal/records/agent-lifecycle-ai-discovery-adapter-origin-2026-05-01.md",
+ "kind": "file",
+ "evidence_tier": "managed-runtime-exercise"
+ },
{
"repo": "pulse",
"path": "docs/release-control/v6/internal/records/known-rc-issue-closure-for-ga-2026-04-21.md",
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index cf5119b172..fbd8e10943 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -155,6 +155,13 @@ runtime cost control, and shared AI transport surfaces.
restart, settings-update, request-clone paths, and Patrol execution must
clamp those values through runtime entitlements before exposing or enforcing
them.
+14. Keep agent-backed Patrol reachability checks aligned with the agent command
+ policy. `internal/ai/patrol_prober.go` may use connected agents for
+ read-only guest ping probes, but it must validate each target as an IP
+ address and issue only the single-target `ping -c 1 -W 1 <ip>` command
+ shape covered by the agent-exec auto-approval policy. It must not compose
+ shell loops, accept hostnames, interpolate unvalidated targets, or bypass
+ approval requirements for compound commands.
## Current State
diff --git a/internal/agentexec/policy.go b/internal/agentexec/policy.go
index 33c20fe84d..58043695c9 100644
--- a/internal/agentexec/policy.go
+++ b/internal/agentexec/policy.go
@@ -44,6 +44,8 @@ func DefaultPolicy() *CommandPolicy {
`^ss(\s|$)`,
`^ip\s+(addr|route|link)`,
`^ifconfig`,
+ `^ping\s+-c\s*1\s+-w\s*1\s+([0-9]{1,3}\.){3}[0-9]{1,3}$`,
+ `^ping\s+-c\s*1\s+-w\s*1\s+[0-9a-f:]+$`,
`^w$`,
`^who$`,
`^last(\s|$)`,
diff --git a/internal/agentexec/policy_test.go b/internal/agentexec/policy_test.go
index 628d9ceaba..98f6775560 100644
--- a/internal/agentexec/policy_test.go
+++ b/internal/agentexec/policy_test.go
@@ -24,11 +24,15 @@ func TestDefaultPolicyEvaluate(t *testing.T) {
{"blocked proc kcore", "cat /proc/kcore", PolicyBlock},
{"auto approve", "df -h", PolicyAllow},
{"auto approve safe proc meminfo", "cat /proc/meminfo", PolicyAllow},
+ {"auto approve ipv4 ping probe", "ping -c 1 -W 1 10.0.0.1", PolicyAllow},
+ {"auto approve ipv6 ping probe", "ping -c 1 -W 1 2001:db8::1", PolicyAllow},
{"require approval", "systemctl restart nginx", PolicyRequireApproval},
{"generic proc read requires approval", "cat /proc/1/status", PolicyRequireApproval},
+ {"hostname ping requires approval", "ping -c 1 -W 1 example.com", PolicyRequireApproval},
{"unknown defaults to approval", "echo hello", PolicyRequireApproval},
{"sudo with flags remains conservative", "sudo -u root df -h", PolicyRequireApproval},
{"compound command requires approval", "df -h && echo ok", PolicyRequireApproval},
+ {"compound ping requires approval", "ping -c 1 -W 1 10.0.0.1; echo ok", PolicyRequireApproval},
{"find delete requires approval", "find /var -type f -delete", PolicyRequireApproval},
// Proxmox VM control - should require approval, not be blocked
@@ -76,4 +80,7 @@ func TestPolicyHelpers(t *testing.T) {
if !p.IsAutoApproved("cat /proc/meminfo") {
t.Fatalf("expected cat /proc/meminfo to be auto approved")
}
+ if !p.IsAutoApproved("ping -c 1 -W 1 10.0.0.1") {
+ t.Fatalf("expected single-target ping probe to be auto approved")
+ }
}
diff --git a/internal/ai/agent_exec_test_helpers_test.go b/internal/ai/agent_exec_test_helpers_test.go
new file mode 100644
index 0000000000..2187eeb1dc
--- /dev/null
+++ b/internal/ai/agent_exec_test_helpers_test.go
@@ -0,0 +1,26 @@
+package ai
+
+import (
+ "net/http"
+ "strings"
+ "testing"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/securityutil"
+)
+
+func agentExecWSURLForHTTP(serverURL string) string {
+ return "ws" + strings.TrimPrefix(serverURL, "http")
+}
+
+func agentExecWSHeadersForHTTP(t *testing.T, serverURL string) http.Header {
+ t.Helper()
+
+ origin, err := securityutil.HTTPOriginForWebSocketBaseURL(serverURL)
+ if err != nil {
+ t.Fatalf("failed to derive websocket origin: %v", err)
+ }
+
+ headers := http.Header{}
+ headers.Set("Origin", origin)
+ return headers
+}
diff --git a/internal/ai/discovery_adapter_test.go b/internal/ai/discovery_adapter_test.go
index 46a4d3ef47..7a9517c6b6 100644
--- a/internal/ai/discovery_adapter_test.go
+++ b/internal/ai/discovery_adapter_test.go
@@ -82,8 +82,7 @@ func TestDiscoveryCommandAdapter_ConnectedAgentsAndLookup(t *testing.T) {
}))
defer ts.Close()
- wsURL := "ws" + strings.TrimPrefix(ts.URL, "http")
- conn, _, err := websocket.DefaultDialer.Dial(wsURL, nil)
+ conn, _, err := websocket.DefaultDialer.Dial(agentExecWSURLForHTTP(ts.URL), agentExecWSHeadersForHTTP(t, ts.URL))
if err != nil {
t.Fatalf("dial websocket: %v", err)
}
@@ -159,8 +158,7 @@ func TestDiscoveryCommandAdapter_ExecuteCommandSuccess(t *testing.T) {
}))
defer ts.Close()
- wsURL := "ws" + strings.TrimPrefix(ts.URL, "http")
- conn, _, err := websocket.DefaultDialer.Dial(wsURL, nil)
+ conn, _, err := websocket.DefaultDialer.Dial(agentExecWSURLForHTTP(ts.URL), agentExecWSHeadersForHTTP(t, ts.URL))
if err != nil {
t.Fatalf("dial websocket: %v", err)
}
diff --git a/internal/ai/patrol_intelligence_test.go b/internal/ai/patrol_intelligence_test.go
index c2620b360e..81e9321938 100644
--- a/internal/ai/patrol_intelligence_test.go
+++ b/internal/ai/patrol_intelligence_test.go
@@ -334,61 +334,45 @@ func TestGatherGuestIntelligence_NilReadState(t *testing.T) {
}
}
-// --- parsePingOutput tests ---
-
-func TestParsePingOutput_Normal(t *testing.T) {
- output := "REACH:10.0.0.1:UP\nREACH:10.0.0.2:DOWN\nREACH:10.0.0.3:UP\n"
- results := parsePingOutput(output)
-
- if len(results) != 3 {
- t.Fatalf("expected 3 results, got %d", len(results))
- }
- if !results["10.0.0.1"].Reachable {
- t.Error("10.0.0.1 should be reachable")
- }
- if results["10.0.0.2"].Reachable {
- t.Error("10.0.0.2 should be unreachable")
- }
- if !results["10.0.0.3"].Reachable {
- t.Error("10.0.0.3 should be reachable")
- }
-}
-
-func TestParsePingOutput_Empty(t *testing.T) {
- results := parsePingOutput("")
- if len(results) != 0 {
- t.Fatalf("expected 0 results for empty output, got %d", len(results))
- }
-}
-
-func TestParsePingOutput_NoiseLines(t *testing.T) {
- output := "bash: some warning\nREACH:10.0.0.1:UP\nsome other output\n"
- results := parsePingOutput(output)
-
- if len(results) != 1 {
- t.Fatalf("expected 1 result, got %d", len(results))
- }
- if !results["10.0.0.1"].Reachable {
- t.Error("10.0.0.1 should be reachable")
+// --- agent-exec ping probe helper tests ---
+
+func TestCanonicalPingIP(t *testing.T) {
+ cases := []struct {
+ name string
+ raw string
+ want string
+ }{
+ {"ipv4", " 10.0.0.1 ", "10.0.0.1"},
+ {"ipv6", "2001:db8::1", "2001:db8::1"},
+ {"ipv4 mapped ipv6", "::ffff:10.0.0.2", "10.0.0.2"},
+ }
+
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ got, err := canonicalPingIP(tc.raw)
+ if err != nil {
+ t.Fatalf("canonicalPingIP(%q) returned error: %v", tc.raw, err)
+ }
+ if got != tc.want {
+ t.Fatalf("canonicalPingIP(%q) = %q, want %q", tc.raw, got, tc.want)
+ }
+ })
}
}
-func TestParsePingOutput_MalformedLines(t *testing.T) {
- output := "REACH:\nREACH:10.0.0.1\nREACH:10.0.0.2:UP\n"
- results := parsePingOutput(output)
-
- // Only the well-formed line should parse
- if len(results) != 1 {
- t.Fatalf("expected 1 result, got %d", len(results))
+func TestCanonicalPingIPRejectsInvalidTargets(t *testing.T) {
+ for _, raw := range []string{"", "example.com", "10.0.0.1; rm -rf /"} {
+ t.Run(raw, func(t *testing.T) {
+ if _, err := canonicalPingIP(raw); err == nil {
+ t.Fatalf("expected canonicalPingIP(%q) to reject target", raw)
+ }
+ })
}
}
-func TestParsePingOutput_WhitespaceHandling(t *testing.T) {
- output := " REACH:10.0.0.1:UP \n\n REACH:10.0.0.2:DOWN\n"
- results := parsePingOutput(output)
-
- if len(results) != 2 {
- t.Fatalf("expected 2 results, got %d", len(results))
+func TestPingCommandForIP(t *testing.T) {
+ if got := pingCommandForIP("10.0.0.1"); got != "ping -c 1 -W 1 10.0.0.1" {
+ t.Fatalf("pingCommandForIP() = %q", got)
}
}
diff --git a/internal/ai/patrol_prober.go b/internal/ai/patrol_prober.go
index ab275b1006..93774a73b4 100644
--- a/internal/ai/patrol_prober.go
+++ b/internal/ai/patrol_prober.go
@@ -5,12 +5,22 @@ package ai
import (
"context"
"fmt"
+ "net/netip"
"strings"
+ "sync"
"github.com/google/uuid"
"github.com/rcourtman/pulse-go-rewrite/internal/agentexec"
)
+const maxConcurrentGuestPings = 16
+
+type guestPingProbeResult struct {
+ ip string
+ reachable bool
+ err error
+}
+
// agentExecProber implements GuestProber using the agent execution server.
type agentExecProber struct {
server *agentexec.Server
@@ -30,8 +40,8 @@ func (p *agentExecProber) GetAgentForHost(hostname string) (string, bool) {
}
// PingGuests pings a list of IPs from a specific agent and returns results.
-// It composes a batch shell command that runs all pings concurrently as background
-// subshells, so total wall time is ~1 second regardless of guest count.
+// It sends one validated read-only ping command per target so the agent-exec
+// policy can auto-approve the command without permitting compound shell input.
func (p *agentExecProber) PingGuests(ctx context.Context, agentID string, ips []string) (map[string]PingResult, error) {
if p.server == nil {
return nil, fmt.Errorf("agent exec server not available")
@@ -40,45 +50,86 @@ func (p *agentExecProber) PingGuests(ctx context.Context, agentID string, ips []
return map[string]PingResult{}, nil
}
- // Build batch ping command: all pings run as background subshells
- // Each outputs REACH:<ip>:UP or REACH:<ip>:DOWN
- var sb strings.Builder
- sb.WriteString("for ip in")
- for _, ip := range ips {
- sb.WriteString(" ")
- sb.WriteString(ip)
+ targets := make([]string, 0, len(ips))
+ for _, rawIP := range ips {
+ ip, err := canonicalPingIP(rawIP)
+ if err != nil {
+ return nil, err
+ }
+ targets = append(targets, ip)
}
- sb.WriteString("; do (ping -c1 -W1 \"$ip\" >/dev/null 2>&1 && echo \"REACH:$ip:UP\" || echo \"REACH:$ip:DOWN\") & done; wait")
-
- result, err := p.server.ExecuteCommand(ctx, agentID, agentexec.ExecuteCommandPayload{
- RequestID: uuid.New().String(),
- Command: sb.String(),
- TargetType: "agent",
- Timeout: 5, // seconds — generous for parallel pings
- })
- if err != nil {
- return nil, fmt.Errorf("ping command failed: %w", err)
+
+ results := make(map[string]PingResult, len(targets))
+ workerLimit := maxConcurrentGuestPings
+ if len(targets) < workerLimit {
+ workerLimit = len(targets)
}
+ sem := make(chan struct{}, workerLimit)
+ resultCh := make(chan guestPingProbeResult, len(targets))
- return parsePingOutput(result.Stdout), nil
-}
+ var wg sync.WaitGroup
+ for _, ip := range targets {
+ ip := ip
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
-// parsePingOutput parses the output of the batch ping command.
-// Expected lines: "REACH:<ip>:UP" or "REACH:<ip>:DOWN"
-func parsePingOutput(output string) map[string]PingResult {
- results := make(map[string]PingResult)
- for _, line := range strings.Split(output, "\n") {
- line = strings.TrimSpace(line)
- if !strings.HasPrefix(line, "REACH:") {
- continue
- }
- parts := strings.SplitN(line, ":", 3)
- if len(parts) != 3 {
+ select {
+ case sem <- struct{}{}:
+ defer func() { <-sem }()
+ case <-ctx.Done():
+ resultCh <- guestPingProbeResult{ip: ip, err: ctx.Err()}
+ return
+ }
+
+ result, err := p.server.ExecuteCommand(ctx, agentID, agentexec.ExecuteCommandPayload{
+ RequestID: uuid.New().String(),
+ Command: pingCommandForIP(ip),
+ TargetType: "agent",
+ Timeout: 3,
+ })
+ if err != nil {
+ resultCh <- guestPingProbeResult{ip: ip, err: fmt.Errorf("ping %s failed: %w", ip, err)}
+ return
+ }
+ if result == nil {
+ resultCh <- guestPingProbeResult{ip: ip, err: fmt.Errorf("ping %s returned no result", ip)}
+ return
+ }
+
+ resultCh <- guestPingProbeResult{ip: ip, reachable: result.ExitCode == 0}
+ }()
+ }
+
+ wg.Wait()
+ close(resultCh)
+
+ var firstErr error
+ for item := range resultCh {
+ if item.err != nil {
+ if firstErr == nil {
+ firstErr = item.err
+ }
continue
}
- ip := parts[1]
- up := parts[2] == "UP"
- results[ip] = PingResult{Reachable: up}
+ results[item.ip] = PingResult{Reachable: item.reachable}
}
- return results
+ if firstErr != nil {
+ return nil, firstErr
+ }
+
+ return results, nil
+}
+
+func canonicalPingIP(rawIP string) (string, error) {
+ rawIP = strings.TrimSpace(rawIP)
+ addr, err := netip.ParseAddr(rawIP)
+ if err != nil {
+ return "", fmt.Errorf("invalid ping target %q: expected an IP address", rawIP)
+ }
+ return addr.Unmap().String(), nil
+}
+
+func pingCommandForIP(ip string) string {
+ return "ping -c 1 -W 1 " + ip
}
diff --git a/internal/ai/patrol_prober_test.go b/internal/ai/patrol_prober_test.go
index ec802f431b..669720d308 100644
--- a/internal/ai/patrol_prober_test.go
+++ b/internal/ai/patrol_prober_test.go
@@ -3,6 +3,7 @@ package ai
import (
"context"
"encoding/json"
+ "fmt"
"net/http"
"net/http/httptest"
"strings"
@@ -23,14 +24,10 @@ type pingAgentResult struct {
err error
}
-func wsURLFromHTTP(serverURL string) string {
- return "ws" + strings.TrimPrefix(serverURL, "http")
-}
-
-func dialAndRegisterAgent(t *testing.T, wsURL, agentID, hostname string) *websocket.Conn {
+func dialAndRegisterAgent(t *testing.T, serverURL, agentID, hostname string) *websocket.Conn {
t.Helper()
- conn, _, err := websocket.DefaultDialer.Dial(wsURL, nil)
+ conn, _, err := websocket.DefaultDialer.Dial(agentExecWSURLForHTTP(serverURL), agentExecWSHeadersForHTTP(t, serverURL))
if err != nil {
t.Fatalf("Dial: %v", err)
}
@@ -99,7 +96,7 @@ func TestAgentExecProber_RoundTripViaAgentExecServer(t *testing.T) {
}))
defer ts.Close()
- conn := dialAndRegisterAgent(t, wsURLFromHTTP(ts.URL), "agent-1", "node-a")
+ conn := dialAndRegisterAgent(t, ts.URL, "agent-1", "node-a")
defer conn.Close()
prober := NewAgentExecProber(server)
@@ -112,36 +109,58 @@ func TestAgentExecProber_RoundTripViaAgentExecServer(t *testing.T) {
done := make(chan pingAgentResult, 1)
go func() {
- _ = conn.SetReadDeadline(time.Now().Add(2 * time.Second))
- var msg agentExecRawMessage
- if err := conn.ReadJSON(&msg); err != nil {
- done <- pingAgentResult{err: err}
- return
- }
- if msg.Type != agentexec.MsgTypeExecuteCmd {
- done <- pingAgentResult{err: nil}
- return
- }
-
- var payload agentexec.ExecuteCommandPayload
- if err := json.Unmarshal(msg.Payload, &payload); err != nil {
- done <- pingAgentResult{err: err}
- return
+ commands := make([]string, 0, 2)
+ for i := 0; i < 2; i++ {
+ _ = conn.SetReadDeadline(time.Now().Add(2 * time.Second))
+ var msg agentExecRawMessage
+ if err := conn.ReadJSON(&msg); err != nil {
+ done <- pingAgentResult{err: err}
+ return
+ }
+ if msg.Type != agentexec.MsgTypeExecuteCmd {
+ done <- pingAgentResult{err: fmt.Errorf("message type = %q, want %q", msg.Type, agentexec.MsgTypeExecuteCmd)}
+ return
+ }
+
+ var payload agentexec.ExecuteCommandPayload
+ if err := json.Unmarshal(msg.Payload, &payload); err != nil {
+ done <- pingAgentResult{err: err}
+ return
+ }
+ commands = append(commands, payload.Command)
+ if strings.ContainsAny(payload.Command, ";&|`$<>") {
+ done <- pingAgentResult{err: fmt.Errorf("ping command uses shell control: %q", payload.Command)}
+ return
+ }
+
+ exitCode := 1
+ success := false
+ switch payload.Command {
+ case "ping -c 1 -W 1 10.0.0.1":
+ exitCode = 0
+ success = true
+ case "ping -c 1 -W 1 10.0.0.2":
+ default:
+ done <- pingAgentResult{err: fmt.Errorf("unexpected ping command: %q", payload.Command)}
+ return
+ }
+
+ cmdResult, _ := json.Marshal(agentexec.CommandResultPayload{
+ RequestID: payload.RequestID,
+ Success: success,
+ ExitCode: exitCode,
+ })
+ _ = conn.SetWriteDeadline(time.Now().Add(2 * time.Second))
+ if err := conn.WriteJSON(agentexec.Message{
+ Type: agentexec.MsgTypeCommandResult,
+ Timestamp: time.Now(),
+ Payload: cmdResult,
+ }); err != nil {
+ done <- pingAgentResult{err: err}
+ return
+ }
}
-
- cmdResult, _ := json.Marshal(agentexec.CommandResultPayload{
- RequestID: payload.RequestID,
- Success: true,
- Stdout: "REACH:10.0.0.1:UP\nREACH:10.0.0.2:DOWN\n",
- ExitCode: 0,
- })
- _ = conn.SetWriteDeadline(time.Now().Add(2 * time.Second))
- err := conn.WriteJSON(agentexec.Message{
- Type: agentexec.MsgTypeCommandResult,
- Timestamp: time.Now(),
- Payload: cmdResult,
- })
- done <- pingAgentResult{command: payload.Command, err: err}
+ done <- pingAgentResult{command: strings.Join(commands, "\n")}
}()
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
@@ -165,10 +184,16 @@ func TestAgentExecProber_RoundTripViaAgentExecServer(t *testing.T) {
if agent.err != nil {
t.Fatalf("agent loop error: %v", agent.err)
}
- if !strings.Contains(agent.command, "for ip in 10.0.0.1 10.0.0.2; do") {
- t.Fatalf("unexpected command: %q", agent.command)
+ if !strings.Contains(agent.command, "ping -c 1 -W 1 10.0.0.1") || !strings.Contains(agent.command, "ping -c 1 -W 1 10.0.0.2") {
+ t.Fatalf("commands did not include expected IPs: %s", agent.command)
}
- if !strings.Contains(agent.command, "REACH:$ip:UP") {
- t.Fatalf("unexpected command output marker: %q", agent.command)
+}
+
+func TestAgentExecProber_RejectsInvalidPingTargets(t *testing.T) {
+ prober := NewAgentExecProber(agentexec.NewServer(func(string, string, string) bool { return true }))
+
+ _, err := prober.PingGuests(context.Background(), "agent-1", []string{"10.0.0.1; rm -rf /"})
+ if err == nil || !strings.Contains(err.Error(), "invalid ping target") {
+ t.Fatalf("expected invalid ping target error, got: %v", err)
}
}