diff options
author | Aliaksandr Valialkin <valyala@gmail.com> | 2016-03-29 16:12:59 +0300 |
---|---|---|
committer | Aliaksandr Valialkin <valyala@gmail.com> | 2016-03-29 16:12:59 +0300 |
commit | 1498d8174e70a1b9a90faffbdaa529869633b3c1 (patch) | |
tree | f39bfa3da54b795483db2ae1cf28aafb831477b2 /cookie_test.go | |
parent | server: sleep for a while after reaching the concurrency limit, so other conc... (diff) | |
download | fasthttp-1498d8174e70a1b9a90faffbdaa529869633b3c1.tar.gz fasthttp-1498d8174e70a1b9a90faffbdaa529869633b3c1.tar.bz2 fasthttp-1498d8174e70a1b9a90faffbdaa529869633b3c1.zip |
Issue #73: added 'HttpOnly' and 'secure' flags support to Cookie
Diffstat (limited to 'cookie_test.go')
-rw-r--r-- | cookie_test.go | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/cookie_test.go b/cookie_test.go index dcddf79..d672d3b 100644 --- a/cookie_test.go +++ b/cookie_test.go @@ -6,6 +6,79 @@ import ( "time" ) +func TestCookieSecureHttpOnly(t *testing.T) { + var c Cookie + + if err := c.Parse("foo=bar; HttpOnly; secure"); err != nil { + t.Fatalf("unexpected error: %s", err) + } + if !c.Secure() { + t.Fatalf("secure must be set") + } + if !c.HTTPOnly() { + t.Fatalf("HttpOnly must be set") + } + s := c.String() + if !strings.Contains(s, "; secure") { + t.Fatalf("missing secure flag in cookie %q", s) + } + if !strings.Contains(s, "; HttpOnly") { + t.Fatalf("missing HttpOnly flag in cookie %q", s) + } +} + +func TestCookieSecure(t *testing.T) { + var c Cookie + + if err := c.Parse("foo=bar; secure"); err != nil { + t.Fatalf("unexpected error: %s", err) + } + if !c.Secure() { + t.Fatalf("secure must be set") + } + s := c.String() + if !strings.Contains(s, "; secure") { + t.Fatalf("missing secure flag in cookie %q", s) + } + + if err := c.Parse("foo=bar"); err != nil { + t.Fatalf("unexpected error: %s", err) + } + if c.HTTPOnly() { + t.Fatalf("Unexpected secure flag set") + } + s = c.String() + if strings.Contains(s, "secure") { + t.Fatalf("unexpected secure flag in cookie %q", s) + } +} + +func TestCookieHttpOnly(t *testing.T) { + var c Cookie + + if err := c.Parse("foo=bar; HttpOnly"); err != nil { + t.Fatalf("unexpected error: %s", err) + } + if !c.HTTPOnly() { + t.Fatalf("HTTPOnly must be set") + } + s := c.String() + if !strings.Contains(s, "; HttpOnly") { + t.Fatalf("missing HttpOnly flag in cookie %q", s) + } + + if err := c.Parse("foo=bar"); err != nil { + t.Fatalf("unexpected error: %s", err) + } + if c.HTTPOnly() { + t.Fatalf("Unexpected HTTPOnly flag set") + } + s = c.String() + if strings.Contains(s, "HttpOnly") { + t.Fatalf("unexpected HttpOnly flag in cookie %q", s) + } +} + func TestCookieAcquireReleaseSequential(t *testing.T) { testCookieAcquireRelease(t) } |