Files
traefik-llmgateway/target_url_error_test.go
lukaszraczyloandGitHub f1b198bce4 fix(security): audit run-4 fixes and run-3 leftovers (#26)
Corrects passthrough metering, the cost gate, credential redaction, reload drain, response headers and the discovery cap.
2026-11-29 10:50:36 +00:00

44 lines
1.4 KiB
Go

package traefikllmgateway
import (
"context"
"net/http"
"strings"
"testing"
)
const targetErrMarker = "DUMMY-TARGET-SECRET-0006"
func TestNew_TargetURLErrorOmitsCredential(t *testing.T) {
urls := map[string]string{
"mistyped scheme": "htps://mcp.invalid/mcp?api-key=" + targetErrMarker,
"unparseable": "https://u:" + targetErrMarker + "@mcp.invalid:99x/mcp",
"scheme-less query": "mcp.invalid/mcp?api-key=" + targetErrMarker,
"scheme-less userinfo": targetErrMarker + ":[email protected]/mcp",
"scheme is the token": targetErrMarker + ":@mcp.invalid/mcp",
}
for name, raw := range urls {
for _, kind := range []string{"mcpServers", "agents"} {
t.Run(kind+"/"+name, func(t *testing.T) {
cfg := CreateConfig()
cfg.Providers = map[string]*ProviderConfig{"openai": {Type: "openai", APIKey: "k"}}
if kind == "mcpServers" {
cfg.MCPServers = map[string]*TargetConfig{"alpha": {URL: raw}}
} else {
cfg.Agents = map[string]*AgentConfig{"alpha": {URL: raw}}
}
_, err := New(context.Background(), http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}), cfg, "llmgw")
if err == nil {
t.Fatal("New accepted a bad target url")
}
if !strings.Contains(err.Error(), `"alpha"`) {
t.Errorf("error does not name the entry: %v", err)
}
if strings.Contains(err.Error(), targetErrMarker) {
t.Errorf("error carries the credential: %v", err)
}
})
}
}
}