55package sessions
66
77import (
8+ "net/http"
89 "testing"
910)
1011
@@ -19,15 +20,16 @@ func TestNewCookieFromOptions(t *testing.T) {
1920 secure bool
2021 httpOnly bool
2122 partitioned bool
23+ sameSite http.SameSite
2224 }{
23- {"" , "bar" , "/foo/bar" , "foo.example.com" , 3600 , true , true , true },
24- {"foo" , "" , "/foo/bar" , "foo.example.com" , 3600 , true , true , true },
25- {"foo" , "bar" , "" , "foo.example.com" , 3600 , true , true , true },
26- {"foo" , "bar" , "/foo/bar" , "" , 3600 , true , true , true },
27- {"foo" , "bar" , "/foo/bar" , "foo.example.com" , 0 , true , true , true },
28- {"foo" , "bar" , "/foo/bar" , "foo.example.com" , 3600 , false , true , true },
29- {"foo" , "bar" , "/foo/bar" , "foo.example.com" , 3600 , true , false , true },
30- {"foo" , "bar" , "/foo/bar" , "foo.example.com" , 3600 , true , true , false },
25+ {"" , "bar" , "/foo/bar" , "foo.example.com" , 3600 , true , true , true , http . SameSiteDefaultMode },
26+ {"foo" , "" , "/foo/bar" , "foo.example.com" , 3600 , true , true , true , http . SameSiteLaxMode },
27+ {"foo" , "bar" , "" , "foo.example.com" , 3600 , true , true , true , http . SameSiteStrictMode },
28+ {"foo" , "bar" , "/foo/bar" , "" , 3600 , true , true , true , http . SameSiteNoneMode },
29+ {"foo" , "bar" , "/foo/bar" , "foo.example.com" , 0 , true , true , true , http . SameSiteDefaultMode },
30+ {"foo" , "bar" , "/foo/bar" , "foo.example.com" , 3600 , false , true , true , http . SameSiteLaxMode },
31+ {"foo" , "bar" , "/foo/bar" , "foo.example.com" , 3600 , true , false , true , http . SameSiteStrictMode },
32+ {"foo" , "bar" , "/foo/bar" , "foo.example.com" , 3600 , true , true , false , http . SameSiteNoneMode },
3133 }
3234 for i , v := range tests {
3335 options := & Options {
@@ -37,6 +39,7 @@ func TestNewCookieFromOptions(t *testing.T) {
3739 Secure : v .secure ,
3840 HttpOnly : v .httpOnly ,
3941 Partitioned : v .partitioned ,
42+ SameSite : v .sameSite ,
4043 }
4144 cookie := newCookieFromOptions (v .name , v .value , options )
4245 if cookie .Name != v .name {
@@ -63,5 +66,8 @@ func TestNewCookieFromOptions(t *testing.T) {
6366 if cookie .Partitioned != v .partitioned {
6467 t .Fatalf ("%v: bad cookie partitioned: got %v, want %v" , i + 1 , cookie .Partitioned , v .partitioned )
6568 }
69+ if cookie .SameSite != v .sameSite {
70+ t .Fatalf ("%v: bad cookie sameSite: got %v, want %v" , i + 1 , cookie .SameSite , v .sameSite )
71+ }
6672 }
6773}
0 commit comments