Commit 3d3980eb authored by Tim Gross's avatar Tim Gross
Browse files

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.
parent 8dc69598
Showing with 18 additions and 5 deletions
+18 -5
......@@ -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)
}
})
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment