@@ -243,3 +243,59 @@ func TestDiscoverProviderWithRetry(t *testing.T) {
243243 }
244244 })
245245}
246+
247+ // TestNewServer_BasePathServesBothPrefixes: with a BasePath the console must answer both the
248+ // prefixed URLs it hands out (so a proxy can forward /console/* untouched) and the root.
249+ func TestNewServer_BasePathServesBothPrefixes (t * testing.T ) {
250+ controlPlane := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
251+ w .WriteHeader (http .StatusOK ) // empty /info: no OIDC, which the console tolerates
252+ }))
253+ defer controlPlane .Close ()
254+
255+ srv , err := NewServer (Config {
256+ ControlPlaneURL : controlPlane .URL ,
257+ AdminToken : "test-admin-token" ,
258+ StaticDir : t .TempDir (),
259+ BasePath : "/console" ,
260+ })
261+ if err != nil {
262+ t .Fatalf ("failed to create server: %v" , err )
263+ }
264+ console := httptest .NewServer (srv .Handler ())
265+ defer console .Close ()
266+
267+ client := & http.Client {CheckRedirect : func (* http.Request , []* http.Request ) error { return http .ErrUseLastResponse }}
268+ for path , want := range map [string ]int {
269+ "/info" : http .StatusOK ,
270+ "/console/info" : http .StatusOK ,
271+ "/console" : http .StatusMovedPermanently , // ServeMux redirects to the subtree root
272+ } {
273+ resp , err := client .Get (console .URL + path )
274+ if err != nil {
275+ t .Fatalf ("GET %s: %v" , path , err )
276+ }
277+ _ = resp .Body .Close ()
278+ if resp .StatusCode != want {
279+ t .Errorf ("GET %s: got %d, want %d" , path , resp .StatusCode , want )
280+ }
281+ }
282+ }
283+
284+ // BasePath is concatenated into cookie paths, redirect URLs and mux patterns, so malformed
285+ // flag values (trailing slash, missing leading slash) must be normalized where the flag is read.
286+ func TestNormalizeBasePath (t * testing.T ) {
287+ for input , want := range map [string ]string {
288+ "" : "" ,
289+ "/" : "" ,
290+ "/console" : "/console" ,
291+ "/console/" : "/console" ,
292+ "console" : "/console" ,
293+ "console//" : "/console" ,
294+ "//console" : "/console" ,
295+ "/console//sub/" : "/console/sub" ,
296+ } {
297+ if got := NormalizeBasePath (input ); got != want {
298+ t .Errorf ("NormalizeBasePath(%q) = %q, want %q" , input , got , want )
299+ }
300+ }
301+ }
0 commit comments