Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | Cu.import("resource://services-sync/identity.js"); |
michael@0 | 5 | Cu.import("resource://services-sync/engines.js"); |
michael@0 | 6 | Cu.import("resource://services-sync/record.js"); |
michael@0 | 7 | Cu.import("resource://services-sync/service.js"); |
michael@0 | 8 | Cu.import("resource://services-sync/util.js"); |
michael@0 | 9 | Cu.import("resource://testing-common/services/sync/utils.js"); |
michael@0 | 10 | |
michael@0 | 11 | Service.engineManager.clear(); |
michael@0 | 12 | |
michael@0 | 13 | function CanDecryptEngine() { |
michael@0 | 14 | SyncEngine.call(this, "CanDecrypt", Service); |
michael@0 | 15 | } |
michael@0 | 16 | CanDecryptEngine.prototype = { |
michael@0 | 17 | __proto__: SyncEngine.prototype, |
michael@0 | 18 | |
michael@0 | 19 | // Override these methods with mocks for the test |
michael@0 | 20 | canDecrypt: function canDecrypt() { |
michael@0 | 21 | return true; |
michael@0 | 22 | }, |
michael@0 | 23 | |
michael@0 | 24 | wasWiped: false, |
michael@0 | 25 | wipeClient: function wipeClient() { |
michael@0 | 26 | this.wasWiped = true; |
michael@0 | 27 | } |
michael@0 | 28 | }; |
michael@0 | 29 | Service.engineManager.register(CanDecryptEngine); |
michael@0 | 30 | |
michael@0 | 31 | |
michael@0 | 32 | function CannotDecryptEngine() { |
michael@0 | 33 | SyncEngine.call(this, "CannotDecrypt", Service); |
michael@0 | 34 | } |
michael@0 | 35 | CannotDecryptEngine.prototype = { |
michael@0 | 36 | __proto__: SyncEngine.prototype, |
michael@0 | 37 | |
michael@0 | 38 | // Override these methods with mocks for the test |
michael@0 | 39 | canDecrypt: function canDecrypt() { |
michael@0 | 40 | return false; |
michael@0 | 41 | }, |
michael@0 | 42 | |
michael@0 | 43 | wasWiped: false, |
michael@0 | 44 | wipeClient: function wipeClient() { |
michael@0 | 45 | this.wasWiped = true; |
michael@0 | 46 | } |
michael@0 | 47 | }; |
michael@0 | 48 | Service.engineManager.register(CannotDecryptEngine); |
michael@0 | 49 | |
michael@0 | 50 | |
michael@0 | 51 | add_test(function test_withEngineList() { |
michael@0 | 52 | try { |
michael@0 | 53 | _("Ensure initial scenario."); |
michael@0 | 54 | do_check_false(Service.engineManager.get("candecrypt").wasWiped); |
michael@0 | 55 | do_check_false(Service.engineManager.get("cannotdecrypt").wasWiped); |
michael@0 | 56 | |
michael@0 | 57 | _("Wipe local engine data."); |
michael@0 | 58 | Service.wipeClient(["candecrypt", "cannotdecrypt"]); |
michael@0 | 59 | |
michael@0 | 60 | _("Ensure only the engine that can decrypt was wiped."); |
michael@0 | 61 | do_check_true(Service.engineManager.get("candecrypt").wasWiped); |
michael@0 | 62 | do_check_false(Service.engineManager.get("cannotdecrypt").wasWiped); |
michael@0 | 63 | } finally { |
michael@0 | 64 | Service.engineManager.get("candecrypt").wasWiped = false; |
michael@0 | 65 | Service.engineManager.get("cannotdecrypt").wasWiped = false; |
michael@0 | 66 | Service.startOver(); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | run_next_test(); |
michael@0 | 70 | }); |
michael@0 | 71 | |
michael@0 | 72 | add_test(function test_startOver_clears_keys() { |
michael@0 | 73 | generateNewKeys(Service.collectionKeys); |
michael@0 | 74 | do_check_true(!!Service.collectionKeys.keyForCollection()); |
michael@0 | 75 | Service.startOver(); |
michael@0 | 76 | do_check_false(!!Service.collectionKeys.keyForCollection()); |
michael@0 | 77 | |
michael@0 | 78 | run_next_test(); |
michael@0 | 79 | }); |
michael@0 | 80 | |
michael@0 | 81 | add_test(function test_credentials_preserved() { |
michael@0 | 82 | _("Ensure that credentials are preserved if client is wiped."); |
michael@0 | 83 | |
michael@0 | 84 | // Required for wipeClient(). |
michael@0 | 85 | ensureLegacyIdentityManager(); |
michael@0 | 86 | Service.identity.account = "testaccount"; |
michael@0 | 87 | Service.identity.basicPassword = "testpassword"; |
michael@0 | 88 | Service.clusterURL = "http://dummy:9000/"; |
michael@0 | 89 | let key = Utils.generatePassphrase(); |
michael@0 | 90 | Service.identity.syncKey = key; |
michael@0 | 91 | Service.identity.persistCredentials(); |
michael@0 | 92 | |
michael@0 | 93 | // Simulate passwords engine wipe without all the overhead. To do this |
michael@0 | 94 | // properly would require extra test infrastructure. |
michael@0 | 95 | Services.logins.removeAllLogins(); |
michael@0 | 96 | Service.wipeClient(); |
michael@0 | 97 | |
michael@0 | 98 | let id = new IdentityManager(); |
michael@0 | 99 | do_check_eq(id.account, "testaccount"); |
michael@0 | 100 | do_check_eq(id.basicPassword, "testpassword"); |
michael@0 | 101 | do_check_eq(id.syncKey, key); |
michael@0 | 102 | |
michael@0 | 103 | Service.startOver(); |
michael@0 | 104 | |
michael@0 | 105 | run_next_test(); |
michael@0 | 106 | }); |
michael@0 | 107 | |
michael@0 | 108 | function run_test() { |
michael@0 | 109 | initTestLogging(); |
michael@0 | 110 | |
michael@0 | 111 | run_next_test(); |
michael@0 | 112 | } |