Skip to content

Commit

Permalink
Merge pull request brave#14178 from bsclifton/session-migration-cleanup
Browse files Browse the repository at this point in the history
Add a session migration for uphold fingerprinting
  • Loading branch information
NejcZdovc authored May 22, 2018
2 parents 26b6691 + 2eb1138 commit ec60238
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 2 deletions.
39 changes: 39 additions & 0 deletions app/migrations/20180518_uphold.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const compareVersions = require('compare-versions')

// per https://github.com/brave/browser-laptop/issues/14152
// add fingerprint exception for existing users for uphold.com
module.exports = (data) => {
// don't apply if:
// - user chooses to block all fingerprinting (global setting)
// - user is not upgrading from 0.22.714 or earlier
if ((data.fingerprintingProtectionAll && data.fingerprintingProtectionAll.enabled) ||
!data.lastAppVersion) {
return false
}

let migrationNeeded = false

try {
migrationNeeded = compareVersions(data.lastAppVersion, '0.22.714') !== 1
} catch (e) {}

if (migrationNeeded) {
const pattern = 'https?://uphold.com'
if (!data.siteSettings) {
data.siteSettings = {}
}
if (!data.siteSettings[pattern]) {
data.siteSettings[pattern] = {}
}
let targetSetting = data.siteSettings[pattern]
if (targetSetting.fingerprintingProtection == null) {
targetSetting.fingerprintingProtection = 'allowAllFingerprinting'
}
}

return migrationNeeded
}
14 changes: 14 additions & 0 deletions app/migrations/pre.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

module.exports = (data) => {
let migrations = [
require('./20180518_uphold')
// TODO: put additional migrations here
]

migrations.forEach((migration) => {
migration(data)
})
}
5 changes: 5 additions & 0 deletions app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,11 @@ module.exports.runPreMigrations = (data) => {
}
}

// TODO: consider moving all of the above logic into here
// see https://github.com/brave/browser-laptop/issues/10488
const runMigrations = require('./migrations/pre')
runMigrations(data)

return data
}

Expand Down
2 changes: 1 addition & 1 deletion js/data/siteSettingsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports.defaultSiteSettingsList = [
},
{
"name" : "fingerprintingProtection",
"pattern" : "https://uphold.com",
"pattern" : "https?://uphold.com",
"value" : "allowAllFingerprinting"
}
]
69 changes: 69 additions & 0 deletions test/unit/app/migrations/20180518_upholdTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

/* global describe, it */
const assert = require('assert')

const migration = require('../../../../app/migrations/20180518_uphold')

require('../../braveUnit')

describe('20180518_uphold migration', function () {
it('does not run if global fingerprint protection is enabled', function () {
let data = {
fingerprintingProtectionAll: {
enabled: true
},
lastAppVersion: '0.22.714'
}
assert.equal(migration(data), false)
})

it('does not run if last app version is missing (new installs)', function () {
let data = {}
assert.equal(migration(data), false)
})

it('does not run if last app version is greater than 0.22.714', function () {
let data = {
lastAppVersion: '0.22.715'
}
assert.equal(migration(data), false)
})

it('runs if last app version is 0.22.714', function () {
let data = {
lastAppVersion: '0.22.714'
}
assert.equal(migration(data), true)
})

it('runs if last app version is older than 0.22.714', function () {
let data = {
lastAppVersion: '0.22.13'
}
assert.equal(migration(data), true)
})

it('sets fingerprintingProtection for the site (if not already set)', function () {
let data = {
lastAppVersion: '0.22.13'
}
migration(data)
assert.equal(data.siteSettings['https?://uphold.com'].fingerprintingProtection, 'allowAllFingerprinting')
})

it('does not overwrite an existing fingerprintingProtection setting for the site', function () {
let data = {
lastAppVersion: '0.22.13',
siteSettings: {
'https?://uphold.com': {
fingerprintingProtection: 'blockAllFingerprinting'
}
}
}
migration(data)
assert.equal(data.siteSettings['https?://uphold.com'].fingerprintingProtection, 'blockAllFingerprinting')
})
})
2 changes: 1 addition & 1 deletion test/unit/app/sessionStoreTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ describe('sessionStore unit tests', function () {
'https://www.youtube.com': {
autoplay: true
},
'https://uphold.com': {
'https?://uphold.com': {
fingerprintingProtection: 'allowAllFingerprinting'
}
}
Expand Down

0 comments on commit ec60238

Please sign in to comment.