mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-27 09:35:56 -05:00
Puts back the original change but sets the default to Lax instead of Strict. Scratchr2 needs these cookies sent on top level navigations.
This commit is contained in:
parent
e4c517086e
commit
6078c3653b
2 changed files with 55 additions and 1 deletions
|
@ -78,7 +78,8 @@ const Jar = {
|
||||||
set: (name, value, opts) => {
|
set: (name, value, opts) => {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
defaults(opts, {
|
defaults(opts, {
|
||||||
expires: new Date(new Date().setYear(new Date().getFullYear() + 1))
|
expires: new Date(new Date().setYear(new Date().getFullYear() + 1)),
|
||||||
|
sameSite: 'Lax' // cookie library requires this capitialization of sameSite
|
||||||
});
|
});
|
||||||
opts.path = '/';
|
opts.path = '/';
|
||||||
const obj = cookie.serialize(name, value, opts);
|
const obj = cookie.serialize(name, value, opts);
|
||||||
|
|
53
test/unit/lib/jar.test.js
Normal file
53
test/unit/lib/jar.test.js
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
const jar = require('../../../src/lib/jar');
|
||||||
|
const cookie = require('cookie');
|
||||||
|
|
||||||
|
jest.mock('cookie', () => ({serialize: jest.fn()}));
|
||||||
|
describe('unit test lib/jar.js', () => {
|
||||||
|
|
||||||
|
test('simple set test with no opts', () => {
|
||||||
|
jar.set('name', 'value');
|
||||||
|
expect(cookie.serialize).toHaveBeenCalled();
|
||||||
|
expect(cookie.serialize).toHaveBeenCalledWith('name', 'value',
|
||||||
|
expect.objectContaining({
|
||||||
|
path: '/',
|
||||||
|
sameSite: 'Lax',
|
||||||
|
expires: expect.anything() // not specifically matching the date because it is hard to mock
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
test('test with opts', () => {
|
||||||
|
jar.set('a', 'b', {option: 'one'});
|
||||||
|
expect(cookie.serialize).toHaveBeenCalled();
|
||||||
|
expect(cookie.serialize).toHaveBeenCalledWith('a', 'b',
|
||||||
|
expect.objectContaining({
|
||||||
|
option: 'one',
|
||||||
|
path: '/',
|
||||||
|
sameSite: 'Lax',
|
||||||
|
expires: expect.anything() // not specifically matching the date because it is hard to mock
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
test('expires opts overrides default', () => {
|
||||||
|
jar.set('a', 'b', {
|
||||||
|
option: 'one',
|
||||||
|
expires: 'someday'
|
||||||
|
});
|
||||||
|
expect(cookie.serialize).toHaveBeenCalled();
|
||||||
|
expect(cookie.serialize).toHaveBeenCalledWith('a', 'b',
|
||||||
|
expect.objectContaining({
|
||||||
|
option: 'one',
|
||||||
|
path: '/',
|
||||||
|
expires: 'someday'
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
test('sameSite opts overrides default', () => {
|
||||||
|
jar.set('a', 'b', {
|
||||||
|
option: 'one',
|
||||||
|
sameSite: 'override'
|
||||||
|
});
|
||||||
|
expect(cookie.serialize).toHaveBeenCalled();
|
||||||
|
expect(cookie.serialize).toHaveBeenCalledWith('a', 'b',
|
||||||
|
expect.objectContaining({
|
||||||
|
option: 'one',
|
||||||
|
sameSite: 'override'
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue