resp := MakeRequest(t, req, http.StatusFound)
assert.EqualValues(t, path.Join(setting.AppSubURL, redirectLink), test.RedirectURL(resp))
}
+
+ var temporaryRedirects = map[string]string{
+ "/user2/repo1/": "/user2/repo1",
+ }
+ for link, redirectLink := range temporaryRedirects {
+ req := NewRequest(t, "GET", link)
+ resp := MakeRequest(t, req, http.StatusTemporaryRedirect)
+ assert.EqualValues(t, path.Join(setting.AppSubURL, redirectLink), test.RedirectURL(resp))
+ }
+
}
func TestNoLoginNotExist(t *testing.T) {
session.MakeRequest(t, req, http.StatusFound)
// try to view a private repo, should fail
- req = NewRequest(t, "GET", "/user2/repo2/")
+ req = NewRequest(t, "GET", "/user2/repo2")
session.MakeRequest(t, req, http.StatusNotFound)
// invalidate cached cookies for user2, for subsequent tests
if setting.API.EnableSwagger {
m.Get("/swagger.v1.json", SwaggerV1Json)
}
+ m.NotFound(func(w http.ResponseWriter, req *http.Request) {
+ escapedPath := req.URL.EscapedPath()
+ if len(escapedPath) > 1 && escapedPath[len(escapedPath)-1] == '/' {
+ http.Redirect(w, req, setting.AppSubURL+escapedPath[:len(escapedPath)-1], http.StatusTemporaryRedirect)
+ return
+ }
+ ctx := context.GetContext(req)
+ ctx.NotFound("", nil)
+ })
+
}