[release-11.6.1] Org redirection: Fix linking between orgs (#102870)

Org redirection: Fix linking between orgs (#102021)

* don't trim path

* add unit test

(cherry picked from commit f3fb9592da)
This commit is contained in:
Ashley Harrison
2025-03-26 12:46:29 +00:00
committed by GitHub
parent 48662d8a1d
commit afa4843796
2 changed files with 15 additions and 2 deletions
+1 -2
View File
@@ -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)
}
+14
View File
@@ -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"
})
}