Skip to content

Commit

Permalink
feat: Add support for paritioned attribute in cooki as per chrome 3rd…
Browse files Browse the repository at this point in the history
… party deprication
  • Loading branch information
kashishbehl authored and AlexVulaj committed May 4, 2024
1 parent e308bfd commit d53f077
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func newCookieFromOptions(name, value string, options *Options) *http.Cookie {
MaxAge: options.MaxAge,
Secure: options.Secure,
HttpOnly: options.HttpOnly,
Partitioned: options.Partitioned,
}

}
1 change: 1 addition & 0 deletions cookie_go111.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func newCookieFromOptions(name, value string, options *Options) *http.Cookie {
Secure: options.Secure,
HttpOnly: options.HttpOnly,
SameSite: options.SameSite,
Partitioned options.Partitioned,
}

}
20 changes: 13 additions & 7 deletions cookie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ func TestNewCookieFromOptions(t *testing.T) {
maxAge int
secure bool
httpOnly bool
partitioned bool
}{
{"", "bar", "/foo/bar", "foo.example.com", 3600, true, true},
{"foo", "", "/foo/bar", "foo.example.com", 3600, true, true},
{"foo", "bar", "", "foo.example.com", 3600, true, true},
{"foo", "bar", "/foo/bar", "", 3600, true, true},
{"foo", "bar", "/foo/bar", "foo.example.com", 0, true, true},
{"foo", "bar", "/foo/bar", "foo.example.com", 3600, false, true},
{"foo", "bar", "/foo/bar", "foo.example.com", 3600, true, false},
{"", "bar", "/foo/bar", "foo.example.com", 3600, true, true, true},
{"foo", "", "/foo/bar", "foo.example.com", 3600, true, true, true},
{"foo", "bar", "", "foo.example.com", 3600, true, true, true},
{"foo", "bar", "/foo/bar", "", 3600, true, true, true},
{"foo", "bar", "/foo/bar", "foo.example.com", 0, true, true, true},
{"foo", "bar", "/foo/bar", "foo.example.com", 3600, false, true, true},
{"foo", "bar", "/foo/bar", "foo.example.com", 3600, true, false, true},
{"foo", "bar", "/foo/bar", "foo.example.com", 3600, true, true, false},
}
for i, v := range tests {
options := &Options{
Expand All @@ -30,6 +32,7 @@ func TestNewCookieFromOptions(t *testing.T) {
MaxAge: v.maxAge,
Secure: v.secure,
HttpOnly: v.httpOnly,
Partitioned: v.partitioned
}
cookie := newCookieFromOptions(v.name, v.value, options)
if cookie.Name != v.name {
Expand All @@ -53,5 +56,8 @@ func TestNewCookieFromOptions(t *testing.T) {
if cookie.HttpOnly != v.httpOnly {
t.Fatalf("%v: bad cookie httpOnly: got %v, want %v", i+1, cookie.HttpOnly, v.httpOnly)
}
if cookie.Partitioned != v.partitioned {
t.Fatalf("%v: bad cookie partitioned: got %v, want %v", i+1, cookie.Partitioned, v.partitioned)
}
}
}
1 change: 1 addition & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ type Options struct {
MaxAge int
Secure bool
HttpOnly bool
Partitioned bool
}
1 change: 1 addition & 0 deletions options_go111.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Options struct {
MaxAge int
Secure bool
HttpOnly bool
Partitioned bool
// Defaults to http.SameSiteDefaultMode
SameSite http.SameSite
}
1 change: 1 addition & 0 deletions vendor/github.com/gorilla/securecookie/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d53f077

Please sign in to comment.