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