Org redirection: Fix linking between orgs (#102021)
* don't trim path * add unit test
This commit is contained in:
@@ -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"
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user