Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cookies): reduce cookie lifetime #306

Merged
merged 3 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (BUILD_COMPAT_REACT_NATIVE) {
export default {
apiEndpoint: 'api.amplitude.com',
batchEvents: false,
cookieExpiration: 365 * 10,
cookieExpiration: 365, // 12 months is for GDPR compliance
cookieName: 'amplitude_id', // this is a deprecated option
sameSiteCookie: 'Lax', // cookie privacy policy
cookieForceUpgrade: false,
Expand Down Expand Up @@ -52,7 +52,7 @@ export default {
os_version: true,
platform: true,
region: true,
version_name: true
version_name: true,
},
unsetParamsReferrerOnNewSession: false,
unsentKey: 'amplitude_unsent',
Expand Down
6 changes: 3 additions & 3 deletions test/amplitude-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe('AmplitudeClient', function() {
amplitude.init(apiKey, userId, config);
assert.equal(amplitude.options.apiEndpoint, 'api.amplitude.com');
assert.equal(amplitude.options.batchEvents, false);
assert.equal(amplitude.options.cookieExpiration, 3650);
assert.equal(amplitude.options.cookieExpiration, 365);
assert.equal(amplitude.options.cookieName, 'amplitude_id');
assert.equal(amplitude.options.eventUploadPeriodMillis, 30000);
assert.equal(amplitude.options.eventUploadThreshold, 30);
Expand Down Expand Up @@ -3297,7 +3297,7 @@ describe('setVersionName', function() {
describe('setDomain', function() {
beforeEach(() => {
reset();
amplitude.init(apiKey, null, { cookieExpiration: 365, secureCookie: true });
amplitude.init(apiKey, null, { cookieExpiration: 1, secureCookie: true });
});

it('should set the cookie domain to null for an invalid domain', () => {
Expand All @@ -3309,7 +3309,7 @@ describe('setVersionName', function() {
it('should not change the expirationDays options', () => {
amplitude.setDomain('.foobar.com');
const options = cookie.options();
assert.equal(options.expirationDays, 365);
assert.equal(options.expirationDays, 1);
});

it('should not change the secureCookie options', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/amplitude.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ describe('Amplitude', function() {
amplitude.init(apiKey, userId, config);
assert.equal(amplitude.options.apiEndpoint, 'api.amplitude.com');
assert.equal(amplitude.options.batchEvents, false);
assert.equal(amplitude.options.cookieExpiration, 3650);
assert.equal(amplitude.options.cookieExpiration, 365);
assert.equal(amplitude.options.cookieName, 'amplitude_id');
assert.equal(amplitude.options.eventUploadPeriodMillis, 30000);
assert.equal(amplitude.options.eventUploadThreshold, 30);
Expand Down
41 changes: 19 additions & 22 deletions test/cookie.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,47 @@
import cookie from '../src/cookie.js';
import baseCookie from '../src/base-cookie';
import getLocation from '../src/get-location';

describe('Cookie', function() {

before(function() {
describe('Cookie', () => {
before(() => {
cookie.reset();
});

afterEach(function() {
afterEach(() => {
cookie.remove('x');
cookie.reset();
});

describe('get', function() {
it('should get an existing cookie', function() {
cookie.set('x', { a : 'b' });
assert.deepEqual(cookie.get('x'), { a : 'b' });
describe('get', () => {
it('should get an existing cookie', () => {
cookie.set('x', { a: 'b' });
assert.deepEqual(cookie.get('x'), { a: 'b' });
});

it('should not throw an error on a malformed cookie', function () {
document.cookie="x=y; path=/";
it('should not throw an error on a malformed cookie', () => {
document.cookie = 'x=y; path=/';
assert.isNull(cookie.get('x'));
});
});

describe('remove', function () {
it('should remove a cookie', function() {
cookie.set('x', { a : 'b' });
assert.deepEqual(cookie.get('x'), { a : 'b' });
describe('remove', () => {
it('should remove a cookie', () => {
cookie.set('x', { a: 'b' });
assert.deepEqual(cookie.get('x'), { a: 'b' });
cookie.remove('x');
assert.isNull(cookie.get('x'));
});
});

describe('options', function() {
it('should set default options', function() {
describe('options', () => {
it('should set default options', () => {
assert.deepEqual(cookie.options(), {
expirationDays: undefined,
domain: undefined
domain: undefined,
});
});

it('should save options', function() {
cookie.options({ expirationDays: 365 });
assert.equal(cookie.options().expirationDays, 365);
it('should save options', () => {
cookie.options({ expirationDays: 1 });
assert.equal(cookie.options().expirationDays, 1);
});
});
});