From b7dd5120ef35e1ed60c497d770495aa3054e6ab1 Mon Sep 17 00:00:00 2001 From: cyal1 <33282478+cyal1@users.noreply.github.com> Date: Mon, 1 Apr 2024 14:52:28 +0800 Subject: [PATCH] add open redirect test case https://github.com/gin-gonic/gin/pull/3907 --- routes_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/routes_test.go b/routes_test.go index 73f393e7..43eb82e8 100644 --- a/routes_test.go +++ b/routes_test.go @@ -149,8 +149,13 @@ func TestRouteRedirectTrailingSlash(t *testing.T) { router.GET("/path2/", func(c *Context) {}) router.POST("/path3", func(c *Context) {}) router.PUT("/path4/", func(c *Context) {}) + router.GET("/:param1/:param2", func(c *Context) {}) - w := PerformRequest(router, http.MethodGet, "/path/") + w := PerformRequest(router, http.MethodGet, "//path/") + assert.Equal(t, "/path", w.Header().Get("Location")) + assert.Equal(t, http.StatusMovedPermanently, w.Code) + + w = PerformRequest(router, http.MethodGet, "/path/") assert.Equal(t, "/path", w.Header().Get("Location")) assert.Equal(t, http.StatusMovedPermanently, w.Code)