michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: Cu.import("resource://services-sync/identity.js"); michael@0: Cu.import("resource://services-sync/engines.js"); michael@0: Cu.import("resource://services-sync/record.js"); michael@0: Cu.import("resource://services-sync/service.js"); michael@0: Cu.import("resource://services-sync/util.js"); michael@0: Cu.import("resource://testing-common/services/sync/utils.js"); michael@0: michael@0: Service.engineManager.clear(); michael@0: michael@0: function CanDecryptEngine() { michael@0: SyncEngine.call(this, "CanDecrypt", Service); michael@0: } michael@0: CanDecryptEngine.prototype = { michael@0: __proto__: SyncEngine.prototype, michael@0: michael@0: // Override these methods with mocks for the test michael@0: canDecrypt: function canDecrypt() { michael@0: return true; michael@0: }, michael@0: michael@0: wasWiped: false, michael@0: wipeClient: function wipeClient() { michael@0: this.wasWiped = true; michael@0: } michael@0: }; michael@0: Service.engineManager.register(CanDecryptEngine); michael@0: michael@0: michael@0: function CannotDecryptEngine() { michael@0: SyncEngine.call(this, "CannotDecrypt", Service); michael@0: } michael@0: CannotDecryptEngine.prototype = { michael@0: __proto__: SyncEngine.prototype, michael@0: michael@0: // Override these methods with mocks for the test michael@0: canDecrypt: function canDecrypt() { michael@0: return false; michael@0: }, michael@0: michael@0: wasWiped: false, michael@0: wipeClient: function wipeClient() { michael@0: this.wasWiped = true; michael@0: } michael@0: }; michael@0: Service.engineManager.register(CannotDecryptEngine); michael@0: michael@0: michael@0: add_test(function test_withEngineList() { michael@0: try { michael@0: _("Ensure initial scenario."); michael@0: do_check_false(Service.engineManager.get("candecrypt").wasWiped); michael@0: do_check_false(Service.engineManager.get("cannotdecrypt").wasWiped); michael@0: michael@0: _("Wipe local engine data."); michael@0: Service.wipeClient(["candecrypt", "cannotdecrypt"]); michael@0: michael@0: _("Ensure only the engine that can decrypt was wiped."); michael@0: do_check_true(Service.engineManager.get("candecrypt").wasWiped); michael@0: do_check_false(Service.engineManager.get("cannotdecrypt").wasWiped); michael@0: } finally { michael@0: Service.engineManager.get("candecrypt").wasWiped = false; michael@0: Service.engineManager.get("cannotdecrypt").wasWiped = false; michael@0: Service.startOver(); michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: add_test(function test_startOver_clears_keys() { michael@0: generateNewKeys(Service.collectionKeys); michael@0: do_check_true(!!Service.collectionKeys.keyForCollection()); michael@0: Service.startOver(); michael@0: do_check_false(!!Service.collectionKeys.keyForCollection()); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: add_test(function test_credentials_preserved() { michael@0: _("Ensure that credentials are preserved if client is wiped."); michael@0: michael@0: // Required for wipeClient(). michael@0: ensureLegacyIdentityManager(); michael@0: Service.identity.account = "testaccount"; michael@0: Service.identity.basicPassword = "testpassword"; michael@0: Service.clusterURL = "http://dummy:9000/"; michael@0: let key = Utils.generatePassphrase(); michael@0: Service.identity.syncKey = key; michael@0: Service.identity.persistCredentials(); michael@0: michael@0: // Simulate passwords engine wipe without all the overhead. To do this michael@0: // properly would require extra test infrastructure. michael@0: Services.logins.removeAllLogins(); michael@0: Service.wipeClient(); michael@0: michael@0: let id = new IdentityManager(); michael@0: do_check_eq(id.account, "testaccount"); michael@0: do_check_eq(id.basicPassword, "testpassword"); michael@0: do_check_eq(id.syncKey, key); michael@0: michael@0: Service.startOver(); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: function run_test() { michael@0: initTestLogging(); michael@0: michael@0: run_next_test(); michael@0: }