Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
migrate fp site settings when fp has not been toggled globally
Browse files Browse the repository at this point in the history
fix #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'.
  • Loading branch information
diracdeltas committed Jan 11, 2018
1 parent 1181d07 commit 61d2929
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
13 changes: 9 additions & 4 deletions app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
43 changes: 42 additions & 1 deletion test/unit/app/sessionStoreTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
})

0 comments on commit 61d2929

Please sign in to comment.