mirror of
https://github.com/kataras/iris.git
synced 2025-12-22 20:37:05 +00:00
Fix tests
This commit is contained in:
@@ -744,15 +744,20 @@ func (ctx *Context) SetCookieKV(key, value string) {
|
|||||||
|
|
||||||
// RemoveCookie deletes a cookie by it's name/key
|
// RemoveCookie deletes a cookie by it's name/key
|
||||||
func (ctx *Context) RemoveCookie(name string) {
|
func (ctx *Context) RemoveCookie(name string) {
|
||||||
|
ctx.Response.Header.DelCookie(name)
|
||||||
|
|
||||||
cookie := fasthttp.AcquireCookie()
|
cookie := fasthttp.AcquireCookie()
|
||||||
cookie.SetKey(name)
|
cookie.SetKey(name)
|
||||||
cookie.SetValue("")
|
cookie.SetValue("")
|
||||||
cookie.SetPath("/")
|
cookie.SetPath("/")
|
||||||
cookie.SetHTTPOnly(true)
|
cookie.SetHTTPOnly(true)
|
||||||
exp := time.Now().Add(-time.Duration(1) * time.Minute) //RFC says 1 second, but make sure 1 minute because we are using fasthttp
|
exp := time.Now().Add(-time.Duration(1) * time.Minute) //RFC says 1 second, but let's do it 1 minute to make sure is working...
|
||||||
cookie.SetExpire(exp)
|
cookie.SetExpire(exp)
|
||||||
ctx.Response.Header.SetCookie(cookie)
|
ctx.Response.Header.SetCookie(cookie)
|
||||||
fasthttp.ReleaseCookie(cookie)
|
fasthttp.ReleaseCookie(cookie)
|
||||||
|
// delete respone's cookie also, which is temporarly available
|
||||||
|
ctx.Request.Header.DelCookie(name)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFlashes returns all the flash messages for available for this request
|
// GetFlashes returns all the flash messages for available for this request
|
||||||
|
|||||||
@@ -447,8 +447,13 @@ func TestContextFlashMessages(t *testing.T) {
|
|||||||
Get("/get_last_flash", func(ctx *Context) {
|
Get("/get_last_flash", func(ctx *Context) {
|
||||||
for i, v := range values {
|
for i, v := range values {
|
||||||
if i == len(values)-1 {
|
if i == len(values)-1 {
|
||||||
val, _ := ctx.GetFlash(v.Key)
|
val, err := ctx.GetFlash(v.Key)
|
||||||
|
if err == nil {
|
||||||
ctx.JSON(StatusOK, map[string]string{v.Key: val})
|
ctx.JSON(StatusOK, map[string]string{v.Key: val})
|
||||||
|
} else {
|
||||||
|
ctx.JSON(StatusOK, nil) // return nil
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -576,6 +581,10 @@ func TestContextSessions(t *testing.T) {
|
|||||||
// the cookie and all values should be empty
|
// the cookie and all values should be empty
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// request cookie should be empty
|
||||||
|
Get("/after_destroy", func(ctx *Context) {
|
||||||
|
})
|
||||||
|
|
||||||
e := Tester(t)
|
e := Tester(t)
|
||||||
|
|
||||||
e.POST("/set").WithJSON(values).Expect().Status(StatusOK).Cookies().NotEmpty()
|
e.POST("/set").WithJSON(values).Expect().Status(StatusOK).Cookies().NotEmpty()
|
||||||
@@ -588,7 +597,10 @@ func TestContextSessions(t *testing.T) {
|
|||||||
// test destory which also clears first
|
// test destory which also clears first
|
||||||
d := e.GET("/destroy").Expect().Status(StatusOK)
|
d := e.GET("/destroy").Expect().Status(StatusOK)
|
||||||
d.JSON().Object().Empty()
|
d.JSON().Object().Empty()
|
||||||
d.Cookies().ContainsOnly(Config.Sessions.Cookie)
|
// This removed: d.Cookies().Empty(). Reason:
|
||||||
|
// httpexpect counts the cookies setted or deleted at the response time, but cookie is not removed, to be really removed needs to SetExpire(now-1second) so,
|
||||||
|
// test if the cookies removed on the next request, like the browser's behavior.
|
||||||
|
e.GET("/after_destroy").Expect().Status(StatusOK).Cookies().Empty()
|
||||||
// set and clear again
|
// set and clear again
|
||||||
e.POST("/set").WithJSON(values).Expect().Status(StatusOK).Cookies().NotEmpty()
|
e.POST("/set").WithJSON(values).Expect().Status(StatusOK).Cookies().NotEmpty()
|
||||||
e.GET("/clear").Expect().Status(StatusOK).JSON().Object().Empty()
|
e.GET("/clear").Expect().Status(StatusOK).JSON().Object().Empty()
|
||||||
|
|||||||
Reference in New Issue
Block a user