From 61d2929ecf7c63aa9afd728c9ad4a220eb4e6cde Mon Sep 17 00:00:00 2001 From: yan Date: Thu, 4 Jan 2018 17:22:29 -0800 Subject: [PATCH] migrate fp site settings when fp has not been toggled globally fix https://github.com/brave/browser-laptop/issues/12497 by doing the site settings migration even when fingerprinting protection's global setting has not been changed. Test Plan: 1. in a fresh 0.19.x profile, go to any website and enable fingerprinting protection on it 2. now update to 0.20.x or later 3. re-open brave and go to the website from step 1 4. open page shields. it should say 'block all fingerprinting'. --- app/sessionStore.js | 13 +++++++--- test/unit/app/sessionStoreTest.js | 43 ++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/app/sessionStore.js b/app/sessionStore.js index 57fb0f68f94..a2ff34918de 100644 --- a/app/sessionStore.js +++ b/app/sessionStore.js @@ -835,10 +835,9 @@ module.exports.runPreMigrations = (data) => { return data } -module.exports.runPostMigrations = (immutableData) => { - const globalFpSetting = immutableData.getIn(['settings', 'privacy.block-canvas-fingerprinting']) - // fingerprinting protection migration - if (typeof globalFpSetting !== 'boolean') { +// 0.19.x -> 0.20.x fingerprinting protection migration +const fingerprintingProtectionMigration = (immutableData) => { + if (immutableData.get('fingerprintingProtectionAll')) { return immutableData } try { @@ -853,6 +852,7 @@ module.exports.runPostMigrations = (immutableData) => { return setting }) immutableData = immutableData.set('siteSettings', siteSettings) + const globalFpSetting = !!immutableData.getIn(['settings', 'privacy.block-canvas-fingerprinting']) immutableData = immutableData.setIn(['fingerprintingProtectionAll', 'enabled'], globalFpSetting).deleteIn(['settings', 'privacy.block-canvas-fingerprinting']) } catch (e) { @@ -861,6 +861,11 @@ module.exports.runPostMigrations = (immutableData) => { return immutableData } +module.exports.runPostMigrations = (immutableData) => { + immutableData = fingerprintingProtectionMigration(immutableData) + return immutableData +} + module.exports.runImportDefaultSettings = (data) => { // import default site settings list if (!data.defaultSiteSettingsListImported) { diff --git a/test/unit/app/sessionStoreTest.js b/test/unit/app/sessionStoreTest.js index 2831cce6c9a..51256ab6800 100644 --- a/test/unit/app/sessionStoreTest.js +++ b/test/unit/app/sessionStoreTest.js @@ -1742,6 +1742,47 @@ describe('sessionStore unit tests', function () { }) describe('runPostMigrations', function () { - // TODO: + describe('when `fingerprintingProtectionAll` is set', function () { + it('does not modify anything', function () { + let exampleState = Immutable.fromJS(sessionStore.defaultAppState()) + exampleState = exampleState.set('fingerprintingProtectionAll', {enabled: false}) + const returnedAppState = sessionStore.runPostMigrations(exampleState) + assert.equal(returnedAppState, exampleState) + }) + }) + + describe('when `fingerprintingProtectionAll` is not set', function () { + describe('when `fingerprintingProtection` is `true` for a site', function () { + it('updates to a text status of `blockAllFingerprinting`', function () { + let exampleState = Immutable.fromJS(sessionStore.defaultAppState()) + exampleState = exampleState.setIn(['siteSettings', 'example.com', 'fingerprintingProtection'], true) + const returnedAppState = sessionStore.runPostMigrations(exampleState) + assert.equal(returnedAppState.getIn(['siteSettings', 'example.com', 'fingerprintingProtection']), 'blockAllFingerprinting') + }) + }) + + describe('when `fingerprintingProtection` is `false` for a site', function () { + it('updates to a text status of `allowAllFingerprinting`', function () { + let exampleState = Immutable.fromJS(sessionStore.defaultAppState()) + exampleState = exampleState.setIn(['siteSettings', 'example.com', 'fingerprintingProtection'], false) + const returnedAppState = sessionStore.runPostMigrations(exampleState) + assert.equal(returnedAppState.getIn(['siteSettings', 'example.com', 'fingerprintingProtection']), 'allowAllFingerprinting') + }) + }) + + it('sets a new global fingerprinting value (based on existing value truthy-ness)', function () { + let exampleState = Immutable.fromJS(sessionStore.defaultAppState()) + exampleState = exampleState.setIn(['settings', 'privacy.block-canvas-fingerprinting'], 'EXAMPLE TRUTHY VALUE') + const returnedAppState = sessionStore.runPostMigrations(exampleState) + assert.equal(returnedAppState.getIn(['fingerprintingProtectionAll', 'enabled']), true) + }) + + it('deletes the old global fingerprinting value', function () { + let exampleState = Immutable.fromJS(sessionStore.defaultAppState()) + exampleState = exampleState.setIn(['settings', 'privacy.block-canvas-fingerprinting'], true) + const returnedAppState = sessionStore.runPostMigrations(exampleState) + assert.equal(returnedAppState.getIn(['siteSettings', 'privacy.block-canvas-fingerprinting']), undefined) + }) + }) }) })