2012-05-22 01:17:53 -07:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
|
|
|
Cu.import("resource://services-sync/identity.js");
|
2011-01-18 16:23:30 -08:00
|
|
|
Cu.import("resource://services-sync/record.js");
|
2010-10-05 11:32:56 -07:00
|
|
|
Cu.import("resource://services-sync/engines.js");
|
2010-10-18 15:10:22 -07:00
|
|
|
Cu.import("resource://services-sync/util.js");
|
|
|
|
|
|
|
|
Svc.DefaultPrefs.set("registerEngines", "");
|
|
|
|
Cu.import("resource://services-sync/service.js");
|
2010-10-05 11:32:56 -07:00
|
|
|
|
|
|
|
|
|
|
|
function CanDecryptEngine() {
|
|
|
|
SyncEngine.call(this, "CanDecrypt");
|
|
|
|
}
|
|
|
|
CanDecryptEngine.prototype = {
|
|
|
|
__proto__: SyncEngine.prototype,
|
|
|
|
|
|
|
|
// Override these methods with mocks for the test
|
|
|
|
canDecrypt: function canDecrypt() {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
wasWiped: false,
|
|
|
|
wipeClient: function wipeClient() {
|
|
|
|
this.wasWiped = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Engines.register(CanDecryptEngine);
|
|
|
|
|
|
|
|
|
|
|
|
function CannotDecryptEngine() {
|
|
|
|
SyncEngine.call(this, "CannotDecrypt");
|
|
|
|
}
|
|
|
|
CannotDecryptEngine.prototype = {
|
|
|
|
__proto__: SyncEngine.prototype,
|
|
|
|
|
|
|
|
// Override these methods with mocks for the test
|
|
|
|
canDecrypt: function canDecrypt() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
wasWiped: false,
|
|
|
|
wipeClient: function wipeClient() {
|
|
|
|
this.wasWiped = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Engines.register(CannotDecryptEngine);
|
|
|
|
|
|
|
|
|
2012-05-22 01:17:53 -07:00
|
|
|
add_test(function test_withEngineList() {
|
2010-10-05 11:32:56 -07:00
|
|
|
try {
|
|
|
|
_("Ensure initial scenario.");
|
|
|
|
do_check_false(Engines.get("candecrypt").wasWiped);
|
|
|
|
do_check_false(Engines.get("cannotdecrypt").wasWiped);
|
2012-05-22 01:17:53 -07:00
|
|
|
|
2010-10-05 11:32:56 -07:00
|
|
|
_("Wipe local engine data.");
|
|
|
|
Service.wipeClient(["candecrypt", "cannotdecrypt"]);
|
|
|
|
|
|
|
|
_("Ensure only the engine that can decrypt was wiped.");
|
|
|
|
do_check_true(Engines.get("candecrypt").wasWiped);
|
|
|
|
do_check_false(Engines.get("cannotdecrypt").wasWiped);
|
|
|
|
} finally {
|
|
|
|
Engines.get("candecrypt").wasWiped = false;
|
|
|
|
Engines.get("cannotdecrypt").wasWiped = false;
|
|
|
|
Service.startOver();
|
|
|
|
}
|
|
|
|
|
2012-05-22 01:17:53 -07:00
|
|
|
run_next_test();
|
|
|
|
});
|
|
|
|
|
|
|
|
add_test(function test_startOver_clears_keys() {
|
2011-04-19 12:35:04 -07:00
|
|
|
generateNewKeys();
|
2010-12-07 16:30:06 -08:00
|
|
|
do_check_true(!!CollectionKeys.keyForCollection());
|
|
|
|
Service.startOver();
|
|
|
|
do_check_false(!!CollectionKeys.keyForCollection());
|
2012-05-22 01:17:53 -07:00
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
2010-12-07 16:30:06 -08:00
|
|
|
|
2010-10-05 11:32:56 -07:00
|
|
|
function run_test() {
|
2012-05-22 01:17:53 -07:00
|
|
|
initTestLogging();
|
|
|
|
|
|
|
|
run_next_test();
|
2010-10-05 11:32:56 -07:00
|
|
|
}
|