Skip to content

Commit

Permalink
#272: feat: Add support for paritioned attribute in cookies as per ch…
Browse files Browse the repository at this point in the history
…rome 3rd party cookie phaseout (#273)

<!--
For Work In Progress Pull Requests, please use the Draft PR feature,
see https://github.blog/2019-02-14-introducing-draft-pull-requests/ for
further details.

     For a timely review/response, please avoid force-pushing additional
     commits if your PR already received reviews or comments.

     Before submitting a Pull Request, please ensure that you have:
- 📖 Read the Contributing guide:
https://github.com/gorilla/.github/blob/main/CONTRIBUTING.md
- 📖 Read the Code of Conduct:
https://github.com/gorilla/.github/blob/main/CODE_OF_CONDUCT.md

     - Provide tests for your changes.
     - Use descriptive commit messages.
	 - Comment your code where appropriate.
	 - Squash your commits
     - Update any related documentation.

     - Add gorilla/pull-request-reviewers as a Reviewer
-->

## What type of PR is this? (check all applicable)

- [ ] Refactor
- [x] Feature
- [ ] Bug Fix
- [ ] Optimization
- [ ] Documentation Update
- [ ] Go Version Update
- [ ] Dependency Update

## Description
The PR contains the change to add Partitioned attribute in the cookies.
As chrome will be deprecating support for 3rd Party cookies, we need to
add support for CHIPS to make cookies partitioned to the website.
## Related Tickets & Documents

<!--
For pull requests that relate or close an issue, please include them
below. We like to follow [Github's guidance on linking issues to pull
requests](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue).

For example having the text: "closes #1234" would connect the current
pull
request to issue 1234.  And when we merge the pull request, Github will
automatically close the issue.
-->

- Related Issue #
- Closes #272

## Added/updated tests?

- [x] Yes
- [ ] No, and this is why: _please replace this line with details on why
tests
      have not been included_
- [ ] I need help with writing tests

## Run verifications and test

- [ ] `make verify` is passing
- [ ] `make test` is passing
  • Loading branch information
kashishbehl committed May 4, 2024
1 parent e308bfd commit bdabf0a
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,

Check failure on line 19 in cookie_go111.go

View workflow job for this annotation

GitHub Actions / unit (1.20, ubuntu-latest)

unknown field Partitioned in struct literal of type http.Cookie

Check failure on line 19 in cookie_go111.go

View workflow job for this annotation

GitHub Actions / lint (1.20)

unknown field Partitioned in struct literal of type http.Cookie

Check failure on line 19 in cookie_go111.go

View workflow job for this annotation

GitHub Actions / scan (1.20)

unknown field Partitioned in struct literal of type http.Cookie

Check failure on line 19 in cookie_go111.go

View workflow job for this annotation

GitHub Actions / unit (1.20, macos-latest)

unknown field Partitioned in struct literal of type http.Cookie

Check failure on line 19 in cookie_go111.go

View workflow job for this annotation

GitHub Actions / scan (1.21)

unknown field Partitioned in struct literal of type http.Cookie

Check failure on line 19 in cookie_go111.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

unknown field Partitioned in struct literal of type http.Cookie

Check failure on line 19 in cookie_go111.go

View workflow job for this annotation

GitHub Actions / unit (1.21, ubuntu-latest)

unknown field Partitioned in struct literal of type http.Cookie

Check failure on line 19 in cookie_go111.go

View workflow job for this annotation

GitHub Actions / unit (1.21, macos-latest)

unknown field Partitioned in struct literal of type http.Cookie
}

}
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 {

Check failure on line 59 in cookie_test.go

View workflow job for this annotation

GitHub Actions / unit (1.20, ubuntu-latest)

cookie.Partitioned undefined (type *http.Cookie has no field or method Partitioned)

Check failure on line 59 in cookie_test.go

View workflow job for this annotation

GitHub Actions / lint (1.20)

cookie.Partitioned undefined (type *http.Cookie has no field or method Partitioned)

Check failure on line 59 in cookie_test.go

View workflow job for this annotation

GitHub Actions / unit (1.20, macos-latest)

cookie.Partitioned undefined (type *http.Cookie has no field or method Partitioned)

Check failure on line 59 in cookie_test.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

cookie.Partitioned undefined (type *http.Cookie has no field or method Partitioned)

Check failure on line 59 in cookie_test.go

View workflow job for this annotation

GitHub Actions / unit (1.21, ubuntu-latest)

cookie.Partitioned undefined (type *http.Cookie has no field or method Partitioned)

Check failure on line 59 in cookie_test.go

View workflow job for this annotation

GitHub Actions / unit (1.21, macos-latest)

cookie.Partitioned undefined (type *http.Cookie has no field or method Partitioned)
t.Fatalf("%v: bad cookie partitioned: got %v, want %v", i+1, cookie.Partitioned, v.partitioned)

Check failure on line 60 in cookie_test.go

View workflow job for this annotation

GitHub Actions / unit (1.20, ubuntu-latest)

cookie.Partitioned undefined (type *http.Cookie has no field or method Partitioned)

Check failure on line 60 in cookie_test.go

View workflow job for this annotation

GitHub Actions / lint (1.20)

cookie.Partitioned undefined (type *http.Cookie has no field or method Partitioned) (typecheck)

Check failure on line 60 in cookie_test.go

View workflow job for this annotation

GitHub Actions / unit (1.20, macos-latest)

cookie.Partitioned undefined (type *http.Cookie has no field or method Partitioned)

Check failure on line 60 in cookie_test.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

cookie.Partitioned undefined (type *http.Cookie has no field or method Partitioned) (typecheck)

Check failure on line 60 in cookie_test.go

View workflow job for this annotation

GitHub Actions / unit (1.21, ubuntu-latest)

cookie.Partitioned undefined (type *http.Cookie has no field or method Partitioned)

Check failure on line 60 in cookie_test.go

View workflow job for this annotation

GitHub Actions / unit (1.21, macos-latest)

cookie.Partitioned undefined (type *http.Cookie has no field or method 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 bdabf0a

Please sign in to comment.