[release-11.5.3] Org redirection: Fix linking between orgs (#102089)

Org redirection: Fix linking between orgs (#102021)

* don't trim path

* add unit test

(cherry picked from commit f3fb9592da)
pull/102094/head
Ashley Harrison 4 months ago committed by GitHub
parent 4da21c2a61
commit be1aa19642
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      pkg/middleware/org_redirect.go
  2. 14
      pkg/middleware/org_redirect_test.go

@ -4,7 +4,6 @@ import (
"fmt"
"net/http"
"strconv"
"strings"
"github.com/grafana/grafana/pkg/services/contexthandler"
"github.com/grafana/grafana/pkg/services/user"
@ -50,7 +49,7 @@ func OrgRedirect(cfg *setting.Cfg, userSvc user.Service) web.Handler {
qs = fmt.Sprintf("%s&kiosk", urlParams.Encode())
}
newURL := fmt.Sprintf("%s%s?%s", cfg.AppSubURL, strings.TrimPrefix(c.Req.URL.Path, "/"), qs)
newURL := fmt.Sprintf("%s%s?%s", cfg.AppSubURL, c.Req.URL.Path, qs)
c.Redirect(newURL, 302)
}

@ -7,6 +7,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/services/authn"
"github.com/grafana/grafana/pkg/setting"
)
func TestOrgRedirectMiddleware(t *testing.T) {
@ -62,4 +63,17 @@ func TestOrgRedirectMiddleware(t *testing.T) {
require.Equal(t, 404, sc.resp.Code)
})
middlewareScenario(t, "works correctly when grafana is served under a subpath", func(t *testing.T, sc *scenarioContext) {
sc.withIdentity(&authn.Identity{})
sc.m.Get("/", sc.defaultHandler)
sc.fakeReq("GET", "/?orgId=3").exec()
require.Equal(t, 302, sc.resp.Code)
require.Equal(t, "/grafana/?orgId=3", sc.resp.Header().Get("Location"))
}, func(cfg *setting.Cfg) {
cfg.AppURL = "http://localhost:3000/grafana/"
cfg.AppSubURL = "/grafana"
})
}

Loading…
Cancel
Save