mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
redirect from HTTP root to UI should include query params
The OTT feature relies on having a query parameter for a one-time token which gets handled by the UI. We need to make sure that query param is preserved when redirecting from the root URL to the `/ui/` URI.
This commit is contained in:
@@ -407,7 +407,11 @@ func (s *HTTPServer) handleUI(h http.Handler) http.Handler {
|
||||
func (s *HTTPServer) handleRootFallthrough() http.Handler {
|
||||
return s.auditHTTPHandler(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
if req.URL.Path == "/" {
|
||||
http.Redirect(w, req, "/ui/", 307)
|
||||
url := "/ui/"
|
||||
if req.URL.RawQuery != "" {
|
||||
url = url + "?" + req.URL.RawQuery
|
||||
}
|
||||
http.Redirect(w, req, url, 307)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
|
||||
@@ -74,10 +74,11 @@ func TestRootFallthrough(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
path string
|
||||
expectedPath string
|
||||
expectedCode int
|
||||
desc string
|
||||
path string
|
||||
expectedPath string
|
||||
expectedRawQuery string
|
||||
expectedCode int
|
||||
}{
|
||||
{
|
||||
desc: "unknown endpoint 404s",
|
||||
@@ -90,6 +91,13 @@ func TestRootFallthrough(t *testing.T) {
|
||||
expectedPath: "/ui/",
|
||||
expectedCode: 307,
|
||||
},
|
||||
{
|
||||
desc: "root path with one-time token redirects to ui",
|
||||
path: "/?ott=whatever",
|
||||
expectedPath: "/ui/",
|
||||
expectedRawQuery: "ott=whatever",
|
||||
expectedCode: 307,
|
||||
},
|
||||
}
|
||||
|
||||
s := makeHTTPServer(t, nil)
|
||||
@@ -115,6 +123,7 @@ func TestRootFallthrough(t *testing.T) {
|
||||
loc, err := resp.Location()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tc.expectedPath, loc.Path)
|
||||
require.Equal(t, tc.expectedRawQuery, loc.RawQuery)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user