Skip to content

Commit

Permalink
support secure cookie option for identity cookies (#577)
Browse files Browse the repository at this point in the history
* support secure cookie option for identity cookies

* add changeset
  • Loading branch information
chrisradek authored Aug 11, 2022
1 parent 48f3c0b commit 8d48bdc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-vans-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@segment/analytics-next': patch
---

Fixes an issue where the 'secure' cookie setting was not being applied correctly when specified.
16 changes: 16 additions & 0 deletions packages/browser/src/core/user/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,22 @@ describe('user', () => {
expect(cookie['options'].domain).toBe('foo')
expect(cookie['options'].secure).toBe(true)
expect(cookie['options'].path).toBe('/test')
expect(cookie['options'].secure).toBe(true)
})

it('should pass options when creating cookie', () => {
const jarSpy = jest.spyOn(jar, 'set')
const cookie = new Cookie({ domain: 'foo', secure: true, path: '/test' })

cookie.set('foo', 'bar')

expect(jarSpy).toHaveBeenCalledWith('foo', 'bar', {
domain: 'foo',
expires: 365,
path: '/test',
sameSite: 'Lax',
secure: true,
})
})
})

Expand Down
1 change: 1 addition & 0 deletions packages/browser/src/core/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export class Cookie extends Store {
expires: this.options.maxage,
domain: this.options.domain,
path: this.options.path,
secure: this.options.secure,
}
}

Expand Down

0 comments on commit 8d48bdc

Please sign in to comment.