diff --git a/services/sync/modules/identity.js b/services/sync/modules/identity.js index 916ccaf01e9..10fe7c49fab 100644 --- a/services/sync/modules/identity.js +++ b/services/sync/modules/identity.js @@ -333,8 +333,8 @@ IdentityManager.prototype = { * If the password store is locked (e.g. if the master password hasn't been * entered), this could throw an exception. */ - persistCredentials: function persistCredentials() { - if (this._basicPasswordUpdated) { + persistCredentials: function persistCredentials(force) { + if (this._basicPasswordUpdated || force) { if (this._basicPassword) { this._setLogin(PWDMGR_PASSWORD_REALM, this.username, this._basicPassword); @@ -347,7 +347,7 @@ IdentityManager.prototype = { this._basicPasswordUpdated = false; } - if (this._syncKeyUpdated) { + if (this._syncKeyUpdated || force) { if (this._syncKey) { this._setLogin(PWDMGR_PASSPHRASE_REALM, this.username, this._syncKey); } else { diff --git a/services/sync/modules/service.js b/services/sync/modules/service.js index fc9383dc0e2..835ae3479e0 100644 --- a/services/sync/modules/service.js +++ b/services/sync/modules/service.js @@ -862,7 +862,7 @@ WeaveSvc.prototype = { persistLogin: function persistLogin() { try { - this._identity.persistCredentials(); + this._identity.persistCredentials(true); } catch (ex) { this._log.info("Unable to persist credentials: " + ex); } diff --git a/services/sync/tests/unit/test_service_wipeClient.js b/services/sync/tests/unit/test_service_wipeClient.js index c46035d3dde..0e8622fa74d 100644 --- a/services/sync/tests/unit/test_service_wipeClient.js +++ b/services/sync/tests/unit/test_service_wipeClient.js @@ -1,3 +1,7 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +Cu.import("resource://services-sync/identity.js"); Cu.import("resource://services-sync/record.js"); Cu.import("resource://services-sync/engines.js"); Cu.import("resource://services-sync/util.js"); @@ -44,12 +48,12 @@ CannotDecryptEngine.prototype = { Engines.register(CannotDecryptEngine); -function test_withEngineList() { +add_test(function test_withEngineList() { try { _("Ensure initial scenario."); do_check_false(Engines.get("candecrypt").wasWiped); do_check_false(Engines.get("cannotdecrypt").wasWiped); - + _("Wipe local engine data."); Service.wipeClient(["candecrypt", "cannotdecrypt"]); @@ -61,16 +65,48 @@ function test_withEngineList() { Engines.get("cannotdecrypt").wasWiped = false; Service.startOver(); } -} -function test_startOver_clears_keys() { + run_next_test(); +}); + +add_test(function test_startOver_clears_keys() { generateNewKeys(); do_check_true(!!CollectionKeys.keyForCollection()); Service.startOver(); do_check_false(!!CollectionKeys.keyForCollection()); -} + + run_next_test(); +}); + +add_test(function test_credentials_preserved() { + _("Ensure that credentials are preserved if client is wiped."); + + // Required for wipeClient(). + Service.clusterURL = TEST_CLUSTER_URL; + + Identity.account = "testaccount"; + Identity.basicPassword = "testpassword"; + let key = Utils.generatePassphrase(); + Identity.syncKey = key; + Identity.persistCredentials(); + + // Simulate passwords engine wipe without all the overhead. To do this + // properly would require extra test infrastructure. + Services.logins.removeAllLogins(); + Service.wipeClient(); + + let id = new IdentityManager(); + do_check_eq(id.account, "testaccount"); + do_check_eq(id.basicPassword, "testpassword"); + do_check_eq(id.syncKey, key); + + Service.startOver(); + + run_next_test(); +}); function run_test() { - test_withEngineList(); - test_startOver_clears_keys(); + initTestLogging(); + + run_next_test(); }