mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-12-06 11:03:52 +00:00
Corrects passthrough metering, the cost gate, credential redaction, reload drain, response headers and the discovery cap.
44 lines
1.4 KiB
Go
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)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|