From 9152179aa9843f0f2d82b116e6f5e7e6f572ac7b Mon Sep 17 00:00:00 2001 From: Cezar Augusto Date: Fri, 11 Aug 2017 18:24:49 -0300 Subject: [PATCH 1/3] add support for legacy ledger settings fix #10322 Auditors: @luixxiul, @bsclifton --- app/sessionStore.js | 25 ++++++++++++++++++++++++- js/constants/appConfig.js | 12 +++++++++++- js/constants/settings.js | 8 +++++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/app/sessionStore.js b/app/sessionStore.js index dfacca0009b..b1b5f2108e9 100644 --- a/app/sessionStore.js +++ b/app/sessionStore.js @@ -528,14 +528,37 @@ module.exports.runPreMigrations = (data) => { data.autofill.creditCards.guid = guids } } - // xml migration if (data.settings) { + // xml migration if (data.settings[settings.DEFAULT_SEARCH_ENGINE] === 'content/search/google.xml') { data.settings[settings.DEFAULT_SEARCH_ENGINE] = 'Google' } if (data.settings[settings.DEFAULT_SEARCH_ENGINE] === 'content/search/duckduckgo.xml') { data.settings[settings.DEFAULT_SEARCH_ENGINE] = 'DuckDuckGo' } + // ledger payments migration. see PR #10164 + // changes was introduced in 0.21.x. + // if legacy setting exist, make sure the new setting inherits the legacy value + if (data.settings[settings.AUTO_SUGGEST_SITES] != null) { + data.settings[settings.PAYMENTS_SITES_AUTO_SUGGEST] = data.settings[settings.AUTO_SUGGEST_SITES] + } + if (data.settings[settings.MINIMUM_VISIT_TIME] != null) { + data.settings[settings.PAYMENTS_MINIMUM_VISIT_TIME] = data.settings[settings.MINIMUM_VISIT_TIME] + } + if (data.settings[settings.MINIMUM_VISITS] != null) { + data.settings[settings.PAYMENTS_MINIMUM_VISITS] = data.settings[settings.MINIMUM_VISITS] + } + if (data.settings[settings.HIDE_LOWER_SITES] != null) { + data.settings[settings.PAYMENTS_SITES_SHOW_LESS] = data.settings[settings.HIDE_LOWER_SITES] + } + if (data.settings[settings.HIDE_EXCLUDED_SITES] != null) { + data.settings[settings.PAYMENTS_SITES_HIDE_EXCLUDED] = data.settings[settings.HIDE_EXCLUDED_SITES] + } + // PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED kept the same + // constant but has its value changed. + if (data.settings['payments.notificationTryPaymentsDismissed'] != null) { + data.settings[settings.PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED] = data.settings['payments.notificationTryPaymentsDismissed'] + } } if (data.sites) { diff --git a/js/constants/appConfig.js b/js/constants/appConfig.js index 320de6a5580..bbbb1ef43d1 100644 --- a/js/constants/appConfig.js +++ b/js/constants/appConfig.js @@ -221,7 +221,17 @@ module.exports = { 'general.bookmarks-toolbar-mode': null, 'general.is-default-browser': null, 'notification-add-funds-timestamp': null, - 'notification-reconcile-soon-timestamp': null + 'notification-reconcile-soon-timestamp': null, + // ---> payments -- payments-deprecated + // DO NOT CHANGE THESE VALUES + // these are handled by sessionStore and replaced with their new values. + // They're not used anywhere else other than unit tests. + 'advanced.hide-excluded-sites': false, + 'advanced.minimum-visit-time': 8000, + 'advanced.minimum-visits': 1, + 'advanced.auto-suggest-sites': true, + 'advanced.hide-lower-sites': true + // ---> end payments-deprecated }, defaultFavicon: 'img/empty_favicon.png' } diff --git a/js/constants/settings.js b/js/constants/settings.js index fb839a44933..942982d9e40 100644 --- a/js/constants/settings.js +++ b/js/constants/settings.js @@ -105,7 +105,13 @@ const settings = { VIMIUM_ENABLED: 'extensions.vimium.enabled', HONEY_ENABLED: 'extensions.honey.enabled', PINTEREST_ENABLED: 'extensions.pinterest.enabled', - METAMASK_ENABLED: 'extensions.metamask.enabled' + METAMASK_ENABLED: 'extensions.metamask.enabled', + // > phased out with 0.21.0 + HIDE_EXCLUDED_SITES: 'advanced.hide-excluded-sites', + HIDE_LOWER_SITES: 'advanced.hide-lower-sites', + MINIMUM_VISIT_TIME: 'advanced.minimum-visit-time', + MINIMUM_VISITS: 'advanced.minimum-visits', + AUTO_SUGGEST_SITES: 'advanced.auto-suggest-sites' } module.exports = settings From 489787943e6fac4f5b28a15f4c56823d1163a75a Mon Sep 17 00:00:00 2001 From: Cezar Augusto Date: Fri, 11 Aug 2017 18:24:55 -0300 Subject: [PATCH 2/3] add tests for sessionStore.runPreMigrations --- test/unit/app/sessionStoreTest.js | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/test/unit/app/sessionStoreTest.js b/test/unit/app/sessionStoreTest.js index b81d61e9ed8..bad61157d64 100644 --- a/test/unit/app/sessionStoreTest.js +++ b/test/unit/app/sessionStoreTest.js @@ -943,4 +943,56 @@ describe('sessionStore unit tests', function () { } }) }) + + describe('runPreMigrations', function () { + let data = { + settings: { + [settings.AUTO_SUGGEST_SITES]: 'sure thing', + [settings.MINIMUM_VISIT_TIME]: 'almost instantly', + [settings.MINIMUM_VISITS]: 'a million', + [settings.HIDE_LOWER_SITES]: 'pls do it', + [settings.HIDE_EXCLUDED_SITES]: 'no thanks', + 'payments.notificationTryPaymentsDismissed': 'why would I?' + } + } + + describe('if data.settings exist', function () { + it('PAYMENTS_SITES_AUTO_SUGGEST inherits data from AUTO_SUGGEST_SITES', function () { + const runPreMigrations = sessionStore.runPreMigrations(data) + const newValue = runPreMigrations.settings[settings.PAYMENTS_SITES_AUTO_SUGGEST] + const oldValue = runPreMigrations.settings[settings.AUTO_SUGGEST_SITES] + assert.equal(newValue, oldValue) + }) + it('PAYMENTS_MINIMUM_VISIT_TIME inherits data from MINIMUM_VISIT_TIME', function () { + const runPreMigrations = sessionStore.runPreMigrations(data) + const newValue = runPreMigrations.settings[settings.PAYMENTS_MINIMUM_VISIT_TIME] + const oldValue = runPreMigrations.settings[settings.MINIMUM_VISIT_TIME] + assert.equal(newValue, oldValue) + }) + it('PAYMENTS_MINIMUM_VISITS inherits data from MINIMUM_VISITS', function () { + const runPreMigrations = sessionStore.runPreMigrations(data) + const newValue = runPreMigrations.settings[settings.PAYMENTS_MINIMUM_VISITS] + const oldValue = runPreMigrations.settings[settings.MINIMUM_VISITS] + assert.equal(newValue, oldValue) + }) + it('PAYMENTS_SITES_SHOW_LESS inherits data from HIDE_LOWER_SITES', function () { + const runPreMigrations = sessionStore.runPreMigrations(data) + const newValue = runPreMigrations.settings[settings.PAYMENTS_SITES_SHOW_LESS] + const oldValue = runPreMigrations.settings[settings.HIDE_LOWER_SITES] + assert.equal(newValue, oldValue) + }) + it('PAYMENTS_SITES_HIDE_EXCLUDED inherits data from HIDE_EXCLUDED_SITES', function () { + const runPreMigrations = sessionStore.runPreMigrations(data) + const newValue = runPreMigrations.settings[settings.PAYMENTS_SITES_HIDE_EXCLUDED] + const oldValue = runPreMigrations.settings[settings.HIDE_EXCLUDED_SITES] + assert.equal(newValue, oldValue) + }) + it('PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED inherits data from payments.notificationTryPaymentsDismissed', function () { + const runPreMigrations = sessionStore.runPreMigrations(data) + const newValue = runPreMigrations.settings[settings.PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED] + const oldValue = runPreMigrations.settings['payments.notificationTryPaymentsDismissed'] + assert.equal(newValue, oldValue) + }) + }) + }) }) From 8a2ac16ff9c73e0aa90ae02eb9b11d3bc641ae6d Mon Sep 17 00:00:00 2001 From: Brian Clifton Date: Tue, 22 Aug 2017 17:27:39 -0700 Subject: [PATCH 3/3] Cleanup for deprecated settings - Somehow extension preferences got added into deprecated section. Moved these out - Made deprecated settings more explicit - updated state.md to call out deprecated settings - removed bitwarden/enpass tests and setting. This was never a value in 0.11.x or prior so no migration was needed Auditors: @cezaraugusto --- docs/state.md | 27 ++++++++++++++++++--------- js/constants/appConfig.js | 33 ++++++++++++++++++++++----------- js/constants/settings.js | 27 +++++++++++++++++---------- js/settings.js | 10 ++++------ test/unit/settingsTest.js | 26 +------------------------- 5 files changed, 62 insertions(+), 61 deletions(-) diff --git a/docs/state.md b/docs/state.md index cc87f030c59..e2450ddfc36 100644 --- a/docs/state.md +++ b/docs/state.md @@ -222,8 +222,6 @@ AppStore 'advanced.smooth-scroll-enabled': boolean, // false if smooth scrolling should be explicitly disabled 'advanced.torrent-viewer-enabled': boolean, // whether to render magnet links in the browser 'bookmarks.toolbar.show': boolean, // true if the bookmakrs toolbar should be shown - 'bookmarks.toolbar.showFavicon': boolean, // true if bookmark favicons should be shown on the bookmarks toolbar - 'bookmarks.toolbar.showOnlyFavicon': boolean, // true if only favicons should be shown on the bookmarks toolbar 'extensions.pocket.enabled': boolean, // true if pocket is enabled 'extensions.vimium.enabled': boolean, // true if vimium is enabled 'extensions.honey.enabled': boolean, // true if Honey is enabled @@ -268,12 +266,6 @@ AppStore 'shields.blocked-count-badge': boolean, // true if blocked counts on the shield button should be enabled 'shields.compact-bravery-panel': boolean, // true if the compact Bravery panel should be enabled 'security.passwords.active-password-manager': string, // name of active password manager - 'security.passwords.bitwarden-enabled': boolean, // true if the bitwarden extension should be enabled - 'security.passwords.dashlane-enabled': boolean, // true if the Dashlane extension should be enabled - 'security.passwords.enpass-enabled': boolean, // true if the Enpass extension should be enabled - 'security.passwords.last-pass-enabled': boolean, // true if the Last password extension should be enabled - 'security.passwords.manager-enabled': boolean, // whether to use default password manager - 'security.passwords.one-password-enabled': boolean, // true if the 1Password extension should be enabled 'security.fullscreen.content': string, // whether or not user choose to allow fullscreen content by default 'shutdown.clear-all-site-cookies': boolean, // true to clear all site cookies on shutdown 'shutdown.clear-autocomplete-data': boolean, // true to clear all autocomplete data on shutdown @@ -286,7 +278,24 @@ AppStore 'tabs.paint-tabs': boolean, // true if the page theme color and favicon color should be used for tabs 'tabs.show-tab-previews': boolean, // true to show tab previews 'tabs.switch-to-new-tabs': boolean, // true if newly opened tabs should be focused immediately - 'tabs.tabs-per-page': number // number of tabs per tab page + 'tabs.tabs-per-page': number, // number of tabs per tab page + + // DEPRECATED with 0.11.4 + 'security.passwords.dashlane-enabled': boolean, // true if the Dashlane extension should be enabled + 'security.passwords.last-pass-enabled': boolean, // true if the Last password extension should be enabled + 'security.passwords.manager-enabled': boolean, // whether to use default password manager + 'security.passwords.one-password-enabled': boolean, // true if the 1Password extension should be enabled + + // DEPRECATED with 0.12.6 + 'bookmarks.toolbar.showFavicon': boolean, // true if bookmark favicons should be shown on the bookmarks toolbar + 'bookmarks.toolbar.showOnlyFavicon': boolean, // true if only favicons should be shown on the bookmarks toolbar + + // DEPRECATED with 0.21.0 + 'advanced.hide-excluded-sites': boolean, // whether to hide excluded sites in the payments list + 'advanced.hide-lower-sites': boolean, + 'advanced.minimum-visit-time': number, + 'advanced.minimum-visits': number, + 'advanced.auto-suggest-sites': boolean // show auto suggestion }, locationSiteKeyCache: { [location]: Array. // location -> site keys diff --git a/js/constants/appConfig.js b/js/constants/appConfig.js index bbbb1ef43d1..f2aa9cdfaf4 100644 --- a/js/constants/appConfig.js +++ b/js/constants/appConfig.js @@ -150,15 +150,9 @@ module.exports = { 'privacy.autocomplete.history-size': 500, 'privacy.block-canvas-fingerprinting': false, 'bookmarks.toolbar.show': false, - 'bookmarks.toolbar.showFavicon': false, - 'bookmarks.toolbar.showOnlyFavicon': false, 'privacy.autofill-enabled': true, 'privacy.do-not-track': false, 'security.passwords.active-password-manager': null, // Set in settings.js by passwordManagerDefault (defaults to built in) - 'security.passwords.manager-enabled': true, - 'security.passwords.one-password-enabled': false, - 'security.passwords.dashlane-enabled': false, - 'security.passwords.last-pass-enabled': false, 'security.passwords.enpass-enabled': false, 'security.passwords.bitwarden-enabled': false, 'security.fullscreen.content': fullscreenOption.ALWAYS_ASK, @@ -222,16 +216,33 @@ module.exports = { 'general.is-default-browser': null, 'notification-add-funds-timestamp': null, 'notification-reconcile-soon-timestamp': null, - // ---> payments -- payments-deprecated - // DO NOT CHANGE THESE VALUES - // these are handled by sessionStore and replaced with their new values. - // They're not used anywhere else other than unit tests. + + // DEPRECATED settings + // DO NOT REMOVE OR CHANGE THESE VALUES + // ######################## + // These values should only ever be references from ./settings.js + // Any place using those should have a migration to convert the value + // ######################## + + // START - DEPRECATED WITH 0.11.4 + 'security.passwords.manager-enabled': true, + 'security.passwords.one-password-enabled': false, + 'security.passwords.dashlane-enabled': false, + 'security.passwords.last-pass-enabled': false, + // END - DEPRECATED WITH 0.11.4 + + // START - DEPRECATED WITH 0.12.6 + 'bookmarks.toolbar.showFavicon': false, + 'bookmarks.toolbar.showOnlyFavicon': false, + // END - DEPRECATED WITH 0.12.6 + + // START - DEPRECATED WITH 0.21.0 'advanced.hide-excluded-sites': false, 'advanced.minimum-visit-time': 8000, 'advanced.minimum-visits': 1, 'advanced.auto-suggest-sites': true, 'advanced.hide-lower-sites': true - // ---> end payments-deprecated + // END - DEPRECATED WITH 0.21.0 }, defaultFavicon: 'img/empty_favicon.png' } diff --git a/js/constants/settings.js b/js/constants/settings.js index 942982d9e40..ad325c0e357 100644 --- a/js/constants/settings.js +++ b/js/constants/settings.js @@ -86,32 +86,39 @@ const settings = { SYNC_TYPE_HISTORY: 'sync.type.history', SYNC_TYPE_SITE_SETTING: 'sync.type.siteSetting', SYNC_NETWORK_DISABLED: 'sync.network.disabled', // disable network connection to sync server. only used in testing. + // Extension settings + POCKET_ENABLED: 'extensions.pocket.enabled', + VIMIUM_ENABLED: 'extensions.vimium.enabled', + HONEY_ENABLED: 'extensions.honey.enabled', + PINTEREST_ENABLED: 'extensions.pinterest.enabled', + METAMASK_ENABLED: 'extensions.metamask.enabled', + // DEPRECATED settings + // DO NOT REMOVE OR CHANGE THESE VALUES // ######################## // these constants should not appear outside of this file, ../settings.js, and our tests // NOTE: these settings rely on default values being set in ./appConfig.js // ######################## - // > phased out with 0.11.4 + + // START - DEPRECATED WITH 0.11.4 PASSWORD_MANAGER_ENABLED: 'security.passwords.manager-enabled', ONE_PASSWORD_ENABLED: 'security.passwords.one-password-enabled', DASHLANE_ENABLED: 'security.passwords.dashlane-enabled', LAST_PASS_ENABLED: 'security.passwords.last-pass-enabled', - ENPASS_ENABLED: 'security.passwords.enpass-enabled', - BITWARDEN_ENABLED: 'security.passwords.bitwarden-enabled', - // > phased out with 0.12.6 + // END - DEPRECATED WITH 0.11.4 + + // START - DEPRECATED WITH 0.12.6 SHOW_BOOKMARKS_TOOLBAR_FAVICON: 'bookmarks.toolbar.showFavicon', SHOW_BOOKMARKS_TOOLBAR_ONLY_FAVICON: 'bookmarks.toolbar.showOnlyFavicon', - POCKET_ENABLED: 'extensions.pocket.enabled', - VIMIUM_ENABLED: 'extensions.vimium.enabled', - HONEY_ENABLED: 'extensions.honey.enabled', - PINTEREST_ENABLED: 'extensions.pinterest.enabled', - METAMASK_ENABLED: 'extensions.metamask.enabled', - // > phased out with 0.21.0 + // END - DEPRECATED WITH 0.12.6 + + // START - DEPRECATED WITH 0.21.0 HIDE_EXCLUDED_SITES: 'advanced.hide-excluded-sites', HIDE_LOWER_SITES: 'advanced.hide-lower-sites', MINIMUM_VISIT_TIME: 'advanced.minimum-visit-time', MINIMUM_VISITS: 'advanced.minimum-visits', AUTO_SUGGEST_SITES: 'advanced.auto-suggest-sites' + // END - DEPRECATED WITH 0.21.0 } module.exports = settings diff --git a/js/settings.js b/js/settings.js index 0df45a07341..1adf31151ba 100644 --- a/js/settings.js +++ b/js/settings.js @@ -8,6 +8,8 @@ const settings = require('./constants/settings') const {passwordManagers, defaultPasswordManager, extensionIds, displayNames} = require('./constants/passwordManagers') const {bookmarksToolbarMode} = require('../app/common/constants/settingsEnums') +// individual settings were deprecated with 0.11.4 +// DO NOT ADD TO THIS LIST const passwordManagerDefault = (settingKey, settingsCollection) => { const onePasswordEnabled = resolveValue(settings.ONE_PASSWORD_ENABLED, settingsCollection) === true if (onePasswordEnabled) return passwordManagers.ONE_PASSWORD @@ -18,18 +20,14 @@ const passwordManagerDefault = (settingKey, settingsCollection) => { const lastPassEnabled = resolveValue(settings.LAST_PASS_ENABLED, settingsCollection) === true if (lastPassEnabled) return passwordManagers.LAST_PASS - const enpassEnabled = resolveValue(settings.ENPASS_ENABLED, settingsCollection) === true - if (enpassEnabled) return passwordManagers.ENPASS - - const bitwardenEnabled = resolveValue(settings.BITWARDEN_ENABLED, settingsCollection) === true - if (bitwardenEnabled) return passwordManagers.BITWARDEN - const disabled = resolveValue(settings.PASSWORD_MANAGER_ENABLED, settingsCollection) === false if (disabled) return passwordManagers.UNMANAGED return defaultPasswordManager } +// individual settings were deprecated with 0.12.6 +// DO NOT ADD TO THIS LIST const bookmarksBarDefault = (settingKey, settingsCollection) => { const faviconsOnly = resolveValue(settings.SHOW_BOOKMARKS_TOOLBAR_ONLY_FAVICON, settingsCollection) === true if (faviconsOnly) return bookmarksToolbarMode.FAVICONS_ONLY diff --git a/test/unit/settingsTest.js b/test/unit/settingsTest.js index e056610b867..846322d9f41 100644 --- a/test/unit/settingsTest.js +++ b/test/unit/settingsTest.js @@ -76,25 +76,13 @@ describe('settings unit test', function () { assert.equal(response, passwordManagers.LAST_PASS) }) - it('returns `Enpass` if ENPASS_ENABLED was true', function () { - settingsCollection[settingsConst.ENPASS_ENABLED] = true - const response = settings.getSetting(settingsConst.ACTIVE_PASSWORD_MANAGER, settingsCollection) - assert.equal(response, passwordManagers.ENPASS) - }) - - it('returns `bitwarden` if BITWARDEN_ENABLED was true', function () { - settingsCollection[settingsConst.BITWARDEN_ENABLED] = true - const response = settings.getSetting(settingsConst.ACTIVE_PASSWORD_MANAGER, settingsCollection) - assert.equal(response, passwordManagers.BITWARDEN) - }) - it('returns `BuiltIn` if PASSWORD_MANAGER_ENABLED was true', function () { settingsCollection[settingsConst.PASSWORD_MANAGER_ENABLED] = true const response = settings.getSetting(settingsConst.ACTIVE_PASSWORD_MANAGER, settingsCollection) assert.equal(response, passwordManagers.BUILT_IN) }) - it('returns `1Password`/`Dashlane`/`LastPass`/`Enpass`/`bitwarden`, even if PASSWORD_MANAGER_ENABLED was true', function () { + it('returns `1Password`/`Dashlane`/`LastPass`, even if PASSWORD_MANAGER_ENABLED was true', function () { // 1Password settingsCollection[settingsConst.ONE_PASSWORD_ENABLED] = true settingsCollection[settingsConst.PASSWORD_MANAGER_ENABLED] = true @@ -112,18 +100,6 @@ describe('settings unit test', function () { settingsCollection[settingsConst.PASSWORD_MANAGER_ENABLED] = true response = settings.getSetting(settingsConst.ACTIVE_PASSWORD_MANAGER, settingsCollection) assert.equal(response, passwordManagers.LAST_PASS) - // Enpass - settingsCollection = {} - settingsCollection[settingsConst.ENPASS_ENABLED] = true - settingsCollection[settingsConst.PASSWORD_MANAGER_ENABLED] = true - response = settings.getSetting(settingsConst.ACTIVE_PASSWORD_MANAGER, settingsCollection) - assert.equal(response, passwordManagers.ENPASS) - // bitwarden - settingsCollection = {} - settingsCollection[settingsConst.BITWARDEN_ENABLED] = true - settingsCollection[settingsConst.PASSWORD_MANAGER_ENABLED] = true - response = settings.getSetting(settingsConst.ACTIVE_PASSWORD_MANAGER, settingsCollection) - assert.equal(response, passwordManagers.BITWARDEN) }) it('returns `Unmanaged` if PASSWORD_MANAGER_ENABLED was false', function () {