diff options
author | David Byttow <david.byttow@postmates.com> | 2018-09-13 00:19:38 -0400 |
---|---|---|
committer | Erik Dubbelboer <erik@dubbelboer.com> | 2018-09-13 12:19:38 +0800 |
commit | dbc9965d336c112cb19c4ba167e1d6b6ce7ab092 (patch) | |
tree | ebbbdb1ba3c211e9bb38ca0c4ca4c89f3573aab3 /cookie_test.go | |
parent | use proper "Deprecated" comment format (diff) | |
download | fasthttp-dbc9965d336c112cb19c4ba167e1d6b6ce7ab092.tar.gz fasthttp-dbc9965d336c112cb19c4ba167e1d6b6ce7ab092.tar.bz2 fasthttp-dbc9965d336c112cb19c4ba167e1d6b6ce7ab092.zip |
Adds support for max-age cookie value
Diffstat (limited to 'cookie_test.go')
-rw-r--r-- | cookie_test.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/cookie_test.go b/cookie_test.go index 332c0aa..cec8edd 100644 --- a/cookie_test.go +++ b/cookie_test.go @@ -85,6 +85,46 @@ func TestCookieSecure(t *testing.T) { } } +func TestCookieMaxAge(t *testing.T) { + var c Cookie + + maxAge := 100 + if err := c.Parse("foo=bar; max-age=100"); err != nil { + t.Fatalf("unexpected error: %s", err) + } + if maxAge != c.MaxAge() { + t.Fatalf("max-age must be set") + } + s := c.String() + if !strings.Contains(s, "; max-age=100") { + t.Fatalf("missing max-age flag in cookie %q", s) + } + + if err := c.Parse("foo=bar; expires=Tue, 10 Nov 2009 23:00:00 GMT; max-age=100;"); err != nil { + t.Fatalf("unexpected error: %s", err) + } + if maxAge != c.MaxAge() { + t.Fatalf("max-age ignored") + } + s = c.String() + if s != "foo=bar; max-age=100" { + t.Fatalf("missing max-age in cookie %q", s) + } + + expires := time.Unix(100, 0) + c.SetExpire(expires) + s = c.String() + if s != "foo=bar; max-age=100" { + t.Fatalf("expires should be ignored due to max-age: %q", s) + } + + c.SetMaxAge(0) + s = c.String() + if s != "foo=bar; expires=Thu, 01 Jan 1970 00:01:40 GMT" { + t.Fatalf("missing expires %q", s) + } +} + func TestCookieHttpOnly(t *testing.T) { var c Cookie @@ -176,6 +216,7 @@ func TestCookieParse(t *testing.T) { testCookieParse(t, `foo="bar"`, "foo=bar") testCookieParse(t, `"foo"=bar`, `"foo"=bar`) testCookieParse(t, "foo=bar; Domain=aaa.com; PATH=/foo/bar", "foo=bar; domain=aaa.com; path=/foo/bar") + testCookieParse(t, "foo=bar; max-age= 101 ; expires= Tue, 10 Nov 2009 23:00:00 GMT", "foo=bar; max-age=101") testCookieParse(t, " xxx = yyy ; path=/a/b;;;domain=foobar.com ; expires= Tue, 10 Nov 2009 23:00:00 GMT ; ;;", "xxx=yyy; expires=Tue, 10 Nov 2009 23:00:00 GMT; domain=foobar.com; path=/a/b") } |