mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-12-06 11:03:52 +00:00
mergeQueryStrings now forwards a configured query that ParseQuery rejects, next to the client query, instead of dropping it.
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package traefikllmgateway
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestMergeQueryStrings_UnparseableTargetQueryIsKept(t *testing.T) {
|
|
if got, want := mergeQueryStrings("token=s;v=1", "a=1"), "token=s;v=1&a=1"; got != want {
|
|
t.Errorf("got %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestMergeQueryStrings_ParseableUnchanged(t *testing.T) {
|
|
cases := []struct{ target, req, want string }{
|
|
{"token=s", "", "token=s"},
|
|
{"", "a=1", "a=1"},
|
|
{"token=s", "a=1", "a=1&token=s"},
|
|
{"a=1", "a=2", "a=1&a=2"},
|
|
{"token=s", "a=1;b=2", "token=s"},
|
|
}
|
|
for _, c := range cases {
|
|
if got := mergeQueryStrings(c.target, c.req); got != c.want {
|
|
t.Errorf("merge(%q, %q) = %q, want %q", c.target, c.req, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestBuildUpstreamTargetURL_SemicolonTargetQueryReachesUpstream(t *testing.T) {
|
|
var gotRaw string
|
|
up := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
gotRaw = r.URL.RawQuery
|
|
}))
|
|
defer up.Close()
|
|
h := newTargetRedirectGateway(t, up.URL+"/mcp?token=s;v=1", up.URL+"/a2a")
|
|
if rec := doTarget(h, "/mcp/alpha?a=1"); rec.Code != http.StatusOK {
|
|
t.Fatalf("status = %d", rec.Code)
|
|
}
|
|
if gotRaw != "token=s;v=1&a=1" {
|
|
t.Errorf("upstream raw query = %q, want %q", gotRaw, "token=s;v=1&a=1")
|
|
}
|
|
}
|