Skip to content

Commit

Permalink
Add SameSite test
Browse files Browse the repository at this point in the history
  • Loading branch information
Fenny authored and Sergio Andrés Virviescas Santana committed May 26, 2020
1 parent c332ef8 commit b3054d9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ func (c *cookie) get(ctx *fasthttp.RequestCtx, name string) []byte {
return ctx.Request.Header.Cookie(name)
}

func (c *cookie) set(ctx *fasthttp.RequestCtx, name string, value []byte, domain string, expiration time.Duration, secure bool, CookieSameSite fasthttp.CookieSameSite) {
func (c *cookie) set(ctx *fasthttp.RequestCtx, name string, value []byte, domain string, expiration time.Duration, secure bool, sameSite fasthttp.CookieSameSite) {
cookie := fasthttp.AcquireCookie()

cookie.SetKey(name)
cookie.SetPath("/")
cookie.SetHTTPOnly(true)
cookie.SetDomain(domain)
cookie.SetValueBytes(value)
cookie.SetSameSite(CookieSameSite)
cookie.SetSameSite(sameSite)

if expiration >= 0 {
if expiration == 0 {
Expand Down
4 changes: 4 additions & 0 deletions cookie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func TestCookie_set(t *testing.T) {
t.Errorf("cookie.set() Secure == %v, want %v", resultCookie.Secure(), secure)
}

if resultCookie.SameSite() != fasthttp.CookieSameSiteLaxMode {
t.Errorf("cookie.set() SameSite == %v, want %v", resultCookie.SameSite(), samesite)
}

if v := ctx.Request.Header.Cookie(key); string(v) != string(value) {
t.Errorf("cookie.set() request value == %s, want %s", v, value)
}
Expand Down

0 comments on commit b3054d9

Please sign in to comment.