api/pkg/provider/proxy_internal_test.go
Virgil c9627729b5 fix(provider): harden proxy path stripping
Co-Authored-By: Virgil <virgil@lethean.io>
2026-04-01 20:08:55 +00:00

26 lines
768 B
Go

// SPDX-License-Identifier: EUPL-1.2
package provider
import "testing"
func TestStripBasePath_Good_ExactBoundary(t *testing.T) {
got := stripBasePath("/api/v1/cool-widget/items", "/api/v1/cool-widget")
if got != "/items" {
t.Fatalf("expected stripped path %q, got %q", "/items", got)
}
}
func TestStripBasePath_Good_RootPath(t *testing.T) {
got := stripBasePath("/api/v1/cool-widget", "/api/v1/cool-widget")
if got != "/" {
t.Fatalf("expected stripped root path %q, got %q", "/", got)
}
}
func TestStripBasePath_Good_DoesNotTrimPartialPrefix(t *testing.T) {
got := stripBasePath("/api/v1/cool-widget-2/items", "/api/v1/cool-widget")
if got != "/api/v1/cool-widget-2/items" {
t.Fatalf("expected partial prefix to remain unchanged, got %q", got)
}
}