From 80b2f9e8570fee57b3c66886fea836d2b1c115f4 Mon Sep 17 00:00:00 2001 From: Mark Hammond Date: Mon, 24 Mar 2014 11:44:43 +1100 Subject: [PATCH] Bug 985212 - check if the username looks like an email address to determine what sync to use. r=rnewman --- services/common/tests/unit/head_helpers.js | 11 +++++------ services/sync/Weave.js | 19 +++++-------------- services/sync/modules-testing/utils.js | 16 ++++++++++++++-- services/sync/modules/service.js | 1 - .../sync/tests/unit/test_bookmark_record.js | 2 ++ .../sync/tests/unit/test_clients_engine.js | 1 + .../sync/tests/unit/test_clients_escape.js | 2 ++ services/sync/tests/unit/test_corrupt_keys.js | 2 ++ services/sync/tests/unit/test_errorhandler.js | 2 ++ .../sync/tests/unit/test_fxa_startOver.js | 11 ++++------- services/sync/tests/unit/test_healthreport.js | 9 --------- services/sync/tests/unit/test_hmac_error.js | 1 + services/sync/tests/unit/test_jpakeclient.js | 1 + .../tests/unit/test_password_mpenabled.js | 13 ++++++++++--- .../sync/tests/unit/test_records_crypto.js | 2 ++ services/sync/tests/unit/test_records_wbo.js | 2 ++ services/sync/tests/unit/test_resource_ua.js | 1 + .../unit/test_sendcredentials_controller.js | 1 + .../tests/unit/test_service_attributes.js | 2 ++ .../tests/unit/test_service_changePassword.js | 2 ++ .../tests/unit/test_service_checkAccount.js | 1 + .../sync/tests/unit/test_service_cluster.js | 3 ++- .../tests/unit/test_service_detect_upgrade.js | 2 ++ .../tests/unit/test_service_getStorageInfo.js | 1 + .../sync/tests/unit/test_service_login.js | 1 + .../tests/unit/test_service_passwordUTF8.js | 2 ++ .../tests/unit/test_service_persistLogin.js | 1 + .../unit/test_service_sync_remoteSetup.js | 1 + .../tests/unit/test_service_verifyLogin.js | 1 + .../tests/unit/test_service_wipeClient.js | 1 + .../sync/tests/unit/test_status_checkSetup.js | 2 ++ .../sync/tests/unit/test_syncscheduler.js | 7 +++++++ .../tests/unit/test_syncstoragerequest.js | 2 ++ .../tests/unit/test_upgrade_old_sync_key.js | 2 ++ .../sync/tps/extensions/tps/resource/tps.jsm | 9 ++++----- 35 files changed, 89 insertions(+), 48 deletions(-) diff --git a/services/common/tests/unit/head_helpers.js b/services/common/tests/unit/head_helpers.js index bfd56fc2dcae..61cc62ba705d 100644 --- a/services/common/tests/unit/head_helpers.js +++ b/services/common/tests/unit/head_helpers.js @@ -173,16 +173,15 @@ function uninstallFakePAC() { Cm.nsIComponentRegistrar.unregisterFactory(CID, PACSystemSettings); } -// We want to ensure the legacy provider is used for most of these tests, -// including after a service.startOver. The tests that know how to deal with +// Many tests do service.startOver() and don't expect the provider type to +// change (whereas by default, a startOver will do exactly that so FxA is +// subsequently used). The tests that know how to deal with // the Firefox Accounts identity hack things to ensure that still works. -function setDefaultIdentityConfig() { +function ensureStartOverKeepsIdentity() { Cu.import("resource://gre/modules/Services.jsm"); - Services.prefs.setBoolPref("services.sync.fxaccounts.enabled", false); Services.prefs.setBoolPref("services.sync-testing.startOverKeepIdentity", true); do_register_cleanup(function() { - Services.prefs.clearUserPref("services.sync.fxaccounts.enabled"); Services.prefs.clearUserPref("services.sync-testing.startOverKeepIdentity"); }); } -setDefaultIdentityConfig(); +ensureStartOverKeepsIdentity(); diff --git a/services/sync/Weave.js b/services/sync/Weave.js index 4e962543d0ce..f5b25721af3c 100644 --- a/services/sync/Weave.js +++ b/services/sync/Weave.js @@ -98,23 +98,14 @@ WeaveService.prototype = { * @return bool */ get fxAccountsEnabled() { - // work out what identity manager to use. This is stored in a preference; - // if the preference exists, we trust it. - let fxAccountsEnabled; try { - fxAccountsEnabled = Services.prefs.getBoolPref("services.sync.fxaccounts.enabled"); + // Old sync guarantees '@' will never appear in the username while FxA + // uses the FxA email address - so '@' is the flag we use. + let username = Services.prefs.getCharPref(SYNC_PREFS_BRANCH + "username"); + return !username || username.contains('@'); } catch (_) { - // That pref doesn't exist - so let's assume this is a first-run. - // If sync already appears configured, we assume it's for the legacy - // provider. - let prefs = Services.prefs.getBranch(SYNC_PREFS_BRANCH); - fxAccountsEnabled = !prefs.prefHasUserValue("username"); - Services.prefs.setBoolPref("services.sync.fxaccounts.enabled", fxAccountsEnabled); + return true; // No username == only allow FxA to be configured. } - // Currently we don't support toggling this pref after initialization - - // except when sync is reset - but this 1 exception is enough that we can't - // cache the value. - return fxAccountsEnabled; }, /** diff --git a/services/sync/modules-testing/utils.js b/services/sync/modules-testing/utils.js index b8c64311ec50..3d12ab168ef1 100644 --- a/services/sync/modules-testing/utils.js +++ b/services/sync/modules-testing/utils.js @@ -7,6 +7,7 @@ this.EXPORTED_SYMBOLS = [ "btoa", // It comes from a module import. "encryptPayload", + "ensureLegacyIdentityManager", "setBasicCredentials", "makeIdentityConfig", "configureFxAccountIdentity", @@ -49,6 +50,17 @@ this.waitForZeroTimer = function waitForZeroTimer(callback) { CommonUtils.namedTimer(wait, 150, {}, "timer"); } +/** + * Ensure Sync is configured with the "legacy" identity provider. + */ +this.ensureLegacyIdentityManager = function() { + let ns = {}; + Cu.import("resource://services-sync/service.js", ns); + + Status.__authManager = ns.Service.identity = new IdentityManager(); + ns.Service._clusterManager = ns.Service.identity.createClusterManager(ns.Service); +} + this.setBasicCredentials = function setBasicCredentials(username, password, syncKey) { let ns = {}; @@ -170,7 +182,7 @@ this.SyncTestingInfrastructure = function (server, username, password, syncKey) let ns = {}; Cu.import("resource://services-sync/service.js", ns); - let auth = ns.Service.identity; + ensureLegacyIdentityManager(); let config = makeIdentityConfig(); // XXX - hacks for the sync identity provider. if (username) @@ -233,7 +245,7 @@ this.add_identity_test = function(test, testFunction) { test.add_task(function() { note("sync"); let oldIdentity = Status._authManager; - Status.__authManager = ns.Service.identity = new IdentityManager(); + ensureLegacyIdentityManager(); yield testFunction(); Status.__authManager = ns.Service.identity = oldIdentity; }); diff --git a/services/sync/modules/service.js b/services/sync/modules/service.js index 65c501d5bd47..f5e8e19ca07d 100644 --- a/services/sync/modules/service.js +++ b/services/sync/modules/service.js @@ -910,7 +910,6 @@ Sync11Service.prototype = { this.identity.finalize().then( () => { this.identity.username = ""; - Services.prefs.clearUserPref("services.sync.fxaccounts.enabled"); this.status.__authManager = null; this.identity = Status._authManager; this._clusterManager = this.identity.createClusterManager(this); diff --git a/services/sync/tests/unit/test_bookmark_record.js b/services/sync/tests/unit/test_bookmark_record.js index da4c4d1dbdcb..194fef5e23d0 100644 --- a/services/sync/tests/unit/test_bookmark_record.js +++ b/services/sync/tests/unit/test_bookmark_record.js @@ -7,6 +7,7 @@ Cu.import("resource://services-sync/keys.js"); Cu.import("resource://services-sync/record.js"); Cu.import("resource://services-sync/service.js"); Cu.import("resource://services-sync/util.js"); +Cu.import("resource://testing-common/services/sync/utils.js"); function prepareBookmarkItem(collection, id) { let b = new Bookmark(collection, id); @@ -15,6 +16,7 @@ function prepareBookmarkItem(collection, id) { } function run_test() { + ensureLegacyIdentityManager(); Service.identity.username = "john@example.com"; Service.identity.syncKey = "abcdeabcdeabcdeabcdeabcdea"; generateNewKeys(Service.collectionKeys); diff --git a/services/sync/tests/unit/test_clients_engine.js b/services/sync/tests/unit/test_clients_engine.js index 0508661fa9e1..c4cec0c8360d 100644 --- a/services/sync/tests/unit/test_clients_engine.js +++ b/services/sync/tests/unit/test_clients_engine.js @@ -81,6 +81,7 @@ add_test(function test_bad_hmac() { } try { + ensureLegacyIdentityManager(); let passphrase = "abcdeabcdeabcdeabcdeabcdea"; Service.serverURL = server.baseURI; Service.login("foo", "ilovejane", passphrase); diff --git a/services/sync/tests/unit/test_clients_escape.js b/services/sync/tests/unit/test_clients_escape.js index 3512087d8973..8c8cd63e3ed8 100644 --- a/services/sync/tests/unit/test_clients_escape.js +++ b/services/sync/tests/unit/test_clients_escape.js @@ -5,10 +5,12 @@ Cu.import("resource://services-sync/keys.js"); Cu.import("resource://services-sync/record.js"); Cu.import("resource://services-sync/service.js"); Cu.import("resource://services-sync/util.js"); +Cu.import("resource://testing-common/services/sync/utils.js"); function run_test() { _("Set up test fixtures."); + ensureLegacyIdentityManager(); Service.identity.username = "john@example.com"; Service.clusterURL = "http://fakebase/"; let baseUri = "http://fakebase/1.1/foo/storage/"; diff --git a/services/sync/tests/unit/test_corrupt_keys.js b/services/sync/tests/unit/test_corrupt_keys.js index 200ec9f7835e..f27cad0354e3 100644 --- a/services/sync/tests/unit/test_corrupt_keys.js +++ b/services/sync/tests/unit/test_corrupt_keys.js @@ -204,6 +204,8 @@ function run_test() { let logger = Log.repository.rootLogger; Log.repository.rootLogger.addAppender(new Log.DumpAppender()); + ensureLegacyIdentityManager(); + run_next_test(); } diff --git a/services/sync/tests/unit/test_errorhandler.js b/services/sync/tests/unit/test_errorhandler.js index 4ac55c7bbe66..702063f51a84 100644 --- a/services/sync/tests/unit/test_errorhandler.js +++ b/services/sync/tests/unit/test_errorhandler.js @@ -55,6 +55,8 @@ function run_test() { Log.repository.getLogger("Sync.SyncScheduler").level = Log.Level.Trace; Log.repository.getLogger("Sync.ErrorHandler").level = Log.Level.Trace; + ensureLegacyIdentityManager(); + run_next_test(); } diff --git a/services/sync/tests/unit/test_fxa_startOver.js b/services/sync/tests/unit/test_fxa_startOver.js index b9ace9ebf180..87becbeec6f4 100644 --- a/services/sync/tests/unit/test_fxa_startOver.js +++ b/services/sync/tests/unit/test_fxa_startOver.js @@ -15,10 +15,10 @@ add_task(function* test_startover() { let oldValue = Services.prefs.getBoolPref("services.sync-testing.startOverKeepIdentity", true); Services.prefs.setBoolPref("services.sync-testing.startOverKeepIdentity", false); + ensureLegacyIdentityManager(); yield configureIdentity({username: "johndoe"}); - // The pref that forces FxA identities should not be set. - do_check_false(Services.prefs.getBoolPref("services.sync.fxaccounts.enabled")); - // And the boolean flag on the xpcom service should reflect this. + + // The boolean flag on the xpcom service should reflect a legacy provider. let xps = Cc["@mozilla.org/weave/service;1"] .getService(Components.interfaces.nsISupports) .wrappedJSObject; @@ -43,9 +43,7 @@ add_task(function* test_startover() { Service.startOver(); yield deferred.promise; // wait for the observer to fire. - // should have reset the pref that indicates if FxA is enabled. - do_check_true(Services.prefs.getBoolPref("services.sync.fxaccounts.enabled")); - // the xpcom service should agree FxA is enabled. + // the xpcom service should indicate FxA is enabled. do_check_true(xps.fxAccountsEnabled); // should have swapped identities. do_check_true(Service.identity instanceof BrowserIDManager); @@ -57,6 +55,5 @@ add_task(function* test_startover() { do_check_neq(oldClusterManager, Service._clusterManager); // reset the world. - Services.prefs.setBoolPref("services.sync.fxaccounts.enabled", false); Services.prefs.setBoolPref("services.sync-testing.startOverKeepIdentity", oldValue); }); diff --git a/services/sync/tests/unit/test_healthreport.js b/services/sync/tests/unit/test_healthreport.js index 37746d160d1e..da9f85f6be6d 100644 --- a/services/sync/tests/unit/test_healthreport.js +++ b/services/sync/tests/unit/test_healthreport.js @@ -14,15 +14,6 @@ Cu.import("resource://testing-common/services/healthreport/utils.jsm", this); function run_test() { initTestLogging(); - // A head JS file always sets the - // services.sync.fxaccounts.enabled pref. This prevents us from testing - // pristine profile conditions and likely indicates there isn't test - // coverage of the Sync service's fxAccountsEnabled property. Check - // that pre-condition and hack around it. - let branch = new Preferences("services.sync."); - Assert.ok(branch.isSet("fxaccounts.enabled"), "Check precondition"); - branch.reset("fxaccounts.enabled"); - run_next_test(); } diff --git a/services/sync/tests/unit/test_hmac_error.js b/services/sync/tests/unit/test_hmac_error.js index e068fe528a4a..e41ff3797413 100644 --- a/services/sync/tests/unit/test_hmac_error.js +++ b/services/sync/tests/unit/test_hmac_error.js @@ -21,6 +21,7 @@ function shared_setup() { hmacErrorCount = 0; // Do not instantiate SyncTestingInfrastructure; we need real crypto. + ensureLegacyIdentityManager(); setBasicCredentials("foo", "foo", "aabcdeabcdeabcdeabcdeabcde"); // Make sure RotaryEngine is the only one we sync. diff --git a/services/sync/tests/unit/test_jpakeclient.js b/services/sync/tests/unit/test_jpakeclient.js index a5475823a80a..ff13c5716fb2 100644 --- a/services/sync/tests/unit/test_jpakeclient.js +++ b/services/sync/tests/unit/test_jpakeclient.js @@ -186,6 +186,7 @@ function run_test() { // Simulate Sync setup with credentials in place. We want to make // sure the J-PAKE requests don't include those data. + ensureLegacyIdentityManager(); setBasicCredentials("johndoe", "ilovejane"); initTestLogging("Trace"); diff --git a/services/sync/tests/unit/test_password_mpenabled.js b/services/sync/tests/unit/test_password_mpenabled.js index 2ef1507dab3a..339ac86265db 100644 --- a/services/sync/tests/unit/test_password_mpenabled.js +++ b/services/sync/tests/unit/test_password_mpenabled.js @@ -14,7 +14,14 @@ function run_test() { } add_test(function test_simple() { - Services.prefs.setBoolPref("services.sync.fxaccounts.enabled", true); + ensureLegacyIdentityManager(); + // Stub fxAccountsEnabled + let xpcs = Cc["@mozilla.org/weave/service;1"] + .getService(Components.interfaces.nsISupports) + .wrappedJSObject; + let fxaEnabledGetter = xpcs.__lookupGetter__("fxAccountsEnabled"); + xpcs.__defineGetter__("fxAccountsEnabled", () => true); + // Stub mpEnabled. let mpEnabledF = Utils.mpEnabled; let mpEnabled = false; @@ -122,9 +129,9 @@ add_test(function test_simple() { // restore the damage we did above... engine.wipeServer = engineWipeServerF; engine._store.wipe(); - // Un-stub mpEnabled. + // Un-stub mpEnabled and fxAccountsEnabled Utils.mpEnabled = mpEnabledF; - Services.prefs.clearUserPref("services.sync.fxaccounts.enabled"); + xpcs.__defineGetter__("fxAccountsEnabled", fxaEnabledGetter); server.stop(run_next_test); } }); diff --git a/services/sync/tests/unit/test_records_crypto.js b/services/sync/tests/unit/test_records_crypto.js index ae3fcf3cc065..4d623c917a1e 100644 --- a/services/sync/tests/unit/test_records_crypto.js +++ b/services/sync/tests/unit/test_records_crypto.js @@ -8,6 +8,7 @@ Cu.import("resource://services-sync/record.js"); Cu.import("resource://services-sync/resource.js"); Cu.import("resource://services-sync/service.js"); Cu.import("resource://services-sync/util.js"); +Cu.import("resource://testing-common/services/sync/utils.js"); let cryptoWrap; @@ -30,6 +31,7 @@ function run_test() { let server; do_test_pending(); + ensureLegacyIdentityManager(); Service.identity.username = "john@example.com"; Service.identity.syncKey = "a-abcde-abcde-abcde-abcde-abcde"; let keyBundle = Service.identity.syncKeyBundle; diff --git a/services/sync/tests/unit/test_records_wbo.js b/services/sync/tests/unit/test_records_wbo.js index 28ab141027ba..e3277b0a70a5 100644 --- a/services/sync/tests/unit/test_records_wbo.js +++ b/services/sync/tests/unit/test_records_wbo.js @@ -6,6 +6,7 @@ Cu.import("resource://services-sync/identity.js"); Cu.import("resource://services-sync/resource.js"); Cu.import("resource://services-sync/service.js"); Cu.import("resource://services-sync/util.js"); +Cu.import("resource://testing-common/services/sync/utils.js"); function test_toJSON() { @@ -78,6 +79,7 @@ function test_fetch() { function run_test() { initTestLogging("Trace"); + ensureLegacyIdentityManager(); test_toJSON(); test_fetch(); diff --git a/services/sync/tests/unit/test_resource_ua.js b/services/sync/tests/unit/test_resource_ua.js index d5a1df3cd846..279a2b3e6956 100644 --- a/services/sync/tests/unit/test_resource_ua.js +++ b/services/sync/tests/unit/test_resource_ua.js @@ -31,6 +31,7 @@ function run_test() { "/1.1/johndoe/storage/meta/global": uaHandler(meta_global.handler()), }); + ensureLegacyIdentityManager(); setBasicCredentials("johndoe", "ilovejane"); Service.serverURL = server.baseURI + "/"; Service.clusterURL = server.baseURI + "/"; diff --git a/services/sync/tests/unit/test_sendcredentials_controller.js b/services/sync/tests/unit/test_sendcredentials_controller.js index e1111f92c037..42e5ec8e80e0 100644 --- a/services/sync/tests/unit/test_sendcredentials_controller.js +++ b/services/sync/tests/unit/test_sendcredentials_controller.js @@ -8,6 +8,7 @@ Cu.import("resource://services-sync/util.js"); Cu.import("resource://testing-common/services/sync/utils.js"); function run_test() { + ensureLegacyIdentityManager(); setBasicCredentials("johndoe", "ilovejane", Utils.generatePassphrase()); Service.serverURL = "http://weave.server/"; diff --git a/services/sync/tests/unit/test_service_attributes.js b/services/sync/tests/unit/test_service_attributes.js index 1491e8ef539f..dc82f5edb213 100644 --- a/services/sync/tests/unit/test_service_attributes.js +++ b/services/sync/tests/unit/test_service_attributes.js @@ -5,10 +5,12 @@ Cu.import("resource://services-sync/constants.js"); Cu.import("resource://services-sync/service.js"); Cu.import("resource://services-sync/util.js"); Cu.import("resource://testing-common/services/sync/fakeservices.js"); +Cu.import("resource://testing-common/services/sync/utils.js"); function test_urls() { _("URL related Service properties correspond to preference settings."); try { + ensureLegacyIdentityManager(); do_check_true(!!Service.serverURL); // actual value may change do_check_eq(Service.clusterURL, ""); do_check_eq(Service.userBaseURL, undefined); diff --git a/services/sync/tests/unit/test_service_changePassword.js b/services/sync/tests/unit/test_service_changePassword.js index 02a8fe9c19e3..475e0668592d 100644 --- a/services/sync/tests/unit/test_service_changePassword.js +++ b/services/sync/tests/unit/test_service_changePassword.js @@ -13,6 +13,8 @@ function run_test() { Log.repository.getLogger("Sync.Resource").level = Log.Level.Trace; Log.repository.getLogger("Sync.Service").level = Log.Level.Trace; + ensureLegacyIdentityManager(); + run_next_test(); } diff --git a/services/sync/tests/unit/test_service_checkAccount.js b/services/sync/tests/unit/test_service_checkAccount.js index ca21dc17b778..618348d1afce 100644 --- a/services/sync/tests/unit/test_service_checkAccount.js +++ b/services/sync/tests/unit/test_service_checkAccount.js @@ -7,6 +7,7 @@ Cu.import("resource://testing-common/services/sync/utils.js"); function run_test() { do_test_pending(); + ensureLegacyIdentityManager(); let server = httpd_setup({ "/user/1.0/johndoe": httpd_handler(200, "OK", "1"), "/user/1.0/janedoe": httpd_handler(200, "OK", "0"), diff --git a/services/sync/tests/unit/test_service_cluster.js b/services/sync/tests/unit/test_service_cluster.js index af0532fc9c5e..65f0c3a9568a 100644 --- a/services/sync/tests/unit/test_service_cluster.js +++ b/services/sync/tests/unit/test_service_cluster.js @@ -18,11 +18,12 @@ function do_check_throws(func) { add_test(function test_findCluster() { _("Test Service._findCluster()"); let server; + ensureLegacyIdentityManager(); try { _("_findCluster() throws on network errors (e.g. connection refused)."); do_check_throws(function() { Service.serverURL = "http://dummy:9000/"; - Service.identify.account = "johndoe"; + Service.identity.account = "johndoe"; Service._clusterManager._findCluster(); }); diff --git a/services/sync/tests/unit/test_service_detect_upgrade.js b/services/sync/tests/unit/test_service_detect_upgrade.js index ec9b155f60a3..528bd751b133 100644 --- a/services/sync/tests/unit/test_service_detect_upgrade.js +++ b/services/sync/tests/unit/test_service_detect_upgrade.js @@ -43,6 +43,8 @@ add_test(function v4_upgrade() { "/1.1/johndoe/storage/prefs": new ServerCollection().handler() }); + ensureLegacyIdentityManager(); + try { _("Set up some tabs."); diff --git a/services/sync/tests/unit/test_service_getStorageInfo.js b/services/sync/tests/unit/test_service_getStorageInfo.js index b0d5a301ac8d..4d463044bdde 100644 --- a/services/sync/tests/unit/test_service_getStorageInfo.js +++ b/services/sync/tests/unit/test_service_getStorageInfo.js @@ -16,6 +16,7 @@ function run_test() { Log.repository.getLogger("Sync.StorageRequest").level = Log.Level.Trace; initTestLogging(); + ensureLegacyIdentityManager(); setBasicCredentials("johndoe", "ilovejane"); run_next_test(); diff --git a/services/sync/tests/unit/test_service_login.js b/services/sync/tests/unit/test_service_login.js index 423b19c91090..0af5ea4517a5 100644 --- a/services/sync/tests/unit/test_service_login.js +++ b/services/sync/tests/unit/test_service_login.js @@ -72,6 +72,7 @@ add_test(function test_login_logout() { try { _("Force the initial state."); + ensureLegacyIdentityManager(); Service.status.service = STATUS_OK; do_check_eq(Service.status.service, STATUS_OK); diff --git a/services/sync/tests/unit/test_service_passwordUTF8.js b/services/sync/tests/unit/test_service_passwordUTF8.js index 2da484f5e7ed..733911291bcc 100644 --- a/services/sync/tests/unit/test_service_passwordUTF8.js +++ b/services/sync/tests/unit/test_service_passwordUTF8.js @@ -58,6 +58,8 @@ function run_test() { let upd = collectionsHelper.with_updated_collection; let collections = collectionsHelper.collections; + ensureLegacyIdentityManager(); + do_test_pending(); let server = httpd_setup({ "/1.1/johndoe/info/collections": login_handling(collectionsHelper.handler), diff --git a/services/sync/tests/unit/test_service_persistLogin.js b/services/sync/tests/unit/test_service_persistLogin.js index c0d78e525260..9d4a1e51a7f6 100644 --- a/services/sync/tests/unit/test_service_persistLogin.js +++ b/services/sync/tests/unit/test_service_persistLogin.js @@ -9,6 +9,7 @@ Cu.import("resource://testing-common/services/sync/utils.js"); function run_test() { try { // Ensure we have a blank slate to start. + ensureLegacyIdentityManager(); Services.logins.removeAllLogins(); setBasicCredentials("johndoe", "ilovejane", "abbbbbcccccdddddeeeeefffff"); diff --git a/services/sync/tests/unit/test_service_sync_remoteSetup.js b/services/sync/tests/unit/test_service_sync_remoteSetup.js index ce56e39100c2..852ba64d5e5b 100644 --- a/services/sync/tests/unit/test_service_sync_remoteSetup.js +++ b/services/sync/tests/unit/test_service_sync_remoteSetup.js @@ -65,6 +65,7 @@ function run_test() { try { _("Log in."); + ensureLegacyIdentityManager(); Service.serverURL = server.baseURI; _("Checking Status.sync with no credentials."); diff --git a/services/sync/tests/unit/test_service_verifyLogin.js b/services/sync/tests/unit/test_service_verifyLogin.js index 9f60e0298070..2a27fd1b0e82 100644 --- a/services/sync/tests/unit/test_service_verifyLogin.js +++ b/services/sync/tests/unit/test_service_verifyLogin.js @@ -30,6 +30,7 @@ function run_test() { let logger = Log.repository.rootLogger; Log.repository.rootLogger.addAppender(new Log.DumpAppender()); + ensureLegacyIdentityManager(); // This test expects a clean slate -- no saved passphrase. Services.logins.removeAllLogins(); let johnHelper = track_collections_helper(); diff --git a/services/sync/tests/unit/test_service_wipeClient.js b/services/sync/tests/unit/test_service_wipeClient.js index 855086b0bef7..aab7692298c7 100644 --- a/services/sync/tests/unit/test_service_wipeClient.js +++ b/services/sync/tests/unit/test_service_wipeClient.js @@ -82,6 +82,7 @@ add_test(function test_credentials_preserved() { _("Ensure that credentials are preserved if client is wiped."); // Required for wipeClient(). + ensureLegacyIdentityManager(); Service.identity.account = "testaccount"; Service.identity.basicPassword = "testpassword"; Service.clusterURL = "http://dummy:9000/"; diff --git a/services/sync/tests/unit/test_status_checkSetup.js b/services/sync/tests/unit/test_status_checkSetup.js index f68b1b693af5..64a6aac932f2 100644 --- a/services/sync/tests/unit/test_status_checkSetup.js +++ b/services/sync/tests/unit/test_status_checkSetup.js @@ -4,9 +4,11 @@ Cu.import("resource://services-sync/constants.js"); Cu.import("resource://services-sync/status.js"); Cu.import("resource://services-sync/util.js"); +Cu.import("resource://testing-common/services/sync/utils.js"); function run_test() { initTestLogging("Trace"); + ensureLegacyIdentityManager(); try { _("Ensure fresh config."); diff --git a/services/sync/tests/unit/test_syncscheduler.js b/services/sync/tests/unit/test_syncscheduler.js index 04b6ffa31cc3..af6d8da26dc6 100644 --- a/services/sync/tests/unit/test_syncscheduler.js +++ b/services/sync/tests/unit/test_syncscheduler.js @@ -85,6 +85,13 @@ function run_test() { Log.repository.getLogger("Sync.Service").level = Log.Level.Trace; Log.repository.getLogger("Sync.scheduler").level = Log.Level.Trace; + // The scheduler checks Weave.fxaEnabled to determine whether to use + // FxA defaults or legacy defaults. As .fxaEnabled checks the username, we + // set a username here then reset the default to ensure they are used. + ensureLegacyIdentityManager(); + setBasicCredentials("johndoe"); + scheduler.setDefaults(); + run_next_test(); } diff --git a/services/sync/tests/unit/test_syncstoragerequest.js b/services/sync/tests/unit/test_syncstoragerequest.js index 4a43bd0d672c..7c5246babac7 100644 --- a/services/sync/tests/unit/test_syncstoragerequest.js +++ b/services/sync/tests/unit/test_syncstoragerequest.js @@ -12,6 +12,8 @@ function run_test() { Log.repository.getLogger("Sync.RESTRequest").level = Log.Level.Trace; initTestLogging(); + ensureLegacyIdentityManager(); + run_next_test(); } diff --git a/services/sync/tests/unit/test_upgrade_old_sync_key.js b/services/sync/tests/unit/test_upgrade_old_sync_key.js index f9f5210d621e..ff75a435adb3 100644 --- a/services/sync/tests/unit/test_upgrade_old_sync_key.js +++ b/services/sync/tests/unit/test_upgrade_old_sync_key.js @@ -4,11 +4,13 @@ Cu.import("resource://services-sync/constants.js"); Cu.import("resource://services-sync/service.js"); Cu.import("resource://services-sync/util.js"); +Cu.import("resource://testing-common/services/sync/utils.js"); // Test upgrade of a dashed old-style sync key. function run_test() { const PBKDF2_KEY_BYTES = 16; initTestLogging("Trace"); + ensureLegacyIdentityManager(); let passphrase = "abcde-abcde-abcde-abcde"; do_check_false(Utils.isPassphrase(passphrase)); diff --git a/services/sync/tps/extensions/tps/resource/tps.jsm b/services/sync/tps/extensions/tps/resource/tps.jsm index 19c8a31348b3..a0540f6ec390 100644 --- a/services/sync/tps/extensions/tps/resource/tps.jsm +++ b/services/sync/tps/extensions/tps/resource/tps.jsm @@ -95,11 +95,10 @@ let TPS = { * Check if the Firefox Accounts feature is enabled */ get fxaccounts_enabled() { - try { - return Services.prefs.getBoolPref("services.sync.fxaccounts.enabled"); - } catch (e) { - return false; - } + let service = Cc["@mozilla.org/weave/service;1"] + .getService(Components.interfaces.nsISupports) + .wrappedJSObject; + return service.fxAccountsEnabled; }, DumpError: function (msg) {