Skip to content

Agent Mesh

bridge: escape mesh path segments and harden startup coverage

Tomas Tormo7387dd1234b2
diff --git a/cmd/sam-a2a-bridge/a2a.go b/cmd/sam-a2a-bridge/a2a.go
index e7ebced4..a537b88e 100644
--- a/cmd/sam-a2a-bridge/a2a.go
+++ b/cmd/sam-a2a-bridge/a2a.go
@@ -17,6 +17,7 @@ package main
import (
"context"
"net/http"
+ "net/url"
"strings"
"time"
@@ -31,7 +32,7 @@ type bridgeConfig struct {
// meshURL is the sidecar's raw egress path for one remote a2a service.
func (c bridgeConfig) meshURL(peer, service string) string {
- return strings.TrimRight(c.sidecarURL, "/") + "/sam/" + peer + "/a2a/" + service
+ return strings.TrimRight(c.sidecarURL, "/") + "/sam/" + url.PathEscape(peer) + "/a2a/" + url.PathEscape(service)
}
type sendAgentTaskParams struct {
diff --git a/cmd/sam-a2a-bridge/a2a_test.go b/cmd/sam-a2a-bridge/a2a_test.go
index 479e6aee..ab938c88 100644
--- a/cmd/sam-a2a-bridge/a2a_test.go
+++ b/cmd/sam-a2a-bridge/a2a_test.go
@@ -156,3 +156,12 @@ func TestGetAgentTaskMapsResult(t *testing.T) {
t.Errorf("state = %q, want it to convey 'completed'", got.State)
}
}
+
+func TestMeshURLEscapesPathSegments(t *testing.T) {
+ cfg := bridgeConfig{sidecarURL: "http://localhost:8080"}
+ got := cfg.meshURL("12D3KooWpeer", "../../sam/service/register")
+ want := "http://localhost:8080/sam/12D3KooWpeer/a2a/..%2F..%2Fsam%2Fservice%2Fregister"
+ if got != want {
+ t.Fatalf("meshURL = %q, want %q", got, want)
+ }
+}
diff --git a/cmd/sam-a2a-bridge/main_test.go b/cmd/sam-a2a-bridge/main_test.go
index ad00c7f2..d88693e2 100644
--- a/cmd/sam-a2a-bridge/main_test.go
+++ b/cmd/sam-a2a-bridge/main_test.go
@@ -101,3 +101,9 @@ func TestHandleGetAgentTask(t *testing.T) {
t.Errorf("got %+v", got)
}
}
+
+func TestNewBridgeServerConstructs(t *testing.T) {
+ if s := newBridgeServer(bridgeConfig{sidecarURL: "http://localhost:8080"}); s == nil {
+ t.Fatal("newBridgeServer returned nil")
+ }
+}
diff --git a/cmd/sam-a2a-bridge/transport.go b/cmd/sam-a2a-bridge/transport.go
index 66d52e4e..410fd86e 100644
--- a/cmd/sam-a2a-bridge/transport.go
+++ b/cmd/sam-a2a-bridge/transport.go
@@ -21,9 +21,8 @@ import (
"strings"
)
-// Mirrors api.HeaderSamAuthentication / api.HeaderSamRequiredLabels
-// (api/network.go:114,133); literals because this module must not
-// depend on the root module.
+// Mirrors api.HeaderSamAuthentication / api.HeaderSamRequiredLabels in the root module's api/network.go;
+// literals because this module must not depend on it.
const (
headerSamAuthentication = "X-Sam-Authentication"
headerSamRequiredLabels = "X-Sam-Required-Labels"