Bug 749957; r=rnewman

This commit is contained in:
Gregory Szorc 2012-05-03 14:25:33 -07:00
parent 0c07aa9fc7
commit 8ab3dda40c
3 changed files with 70 additions and 9 deletions

View File

@ -251,8 +251,8 @@ IdentityManager.prototype = {
this._log.info("Sync Key being updated."); this._log.info("Sync Key being updated.");
this._syncKey = value; this._syncKey = value;
// Calling the getter has the side-effect of populating the object, which // Clear any cached Sync Key Bundle and regenerate it.
// we desire. this._syncKeyBundle = null;
let bundle = this.syncKeyBundle; let bundle = this.syncKeyBundle;
this._syncKeyUpdated = true; this._syncKeyUpdated = true;
@ -315,6 +315,12 @@ IdentityManager.prototype = {
return LOGIN_FAILED_NO_PASSPHRASE; return LOGIN_FAILED_NO_PASSPHRASE;
} }
// If we have a Sync Key but no bundle, bundle creation failed, which
// implies a bad Sync Key.
if (!this._syncKeyBundle) {
return LOGIN_FAILED_INVALID_PASSPHRASE;
}
return STATUS_OK; return STATUS_OK;
}, },

View File

@ -554,17 +554,16 @@ WeaveSvc.prototype = {
// Furthermore, we assume that our sync key is already upgraded, // Furthermore, we assume that our sync key is already upgraded,
// and fail if that assumption is invalidated. // and fail if that assumption is invalidated.
let syncKeyBundle = this._identity.syncKeyBundle; if (!this._identity.syncKey) {
if (!syncKeyBundle) {
this._log.error("No sync key: cannot fetch symmetric keys.");
Status.login = LOGIN_FAILED_NO_PASSPHRASE; Status.login = LOGIN_FAILED_NO_PASSPHRASE;
Status.sync = CREDENTIALS_CHANGED; // For want of a better option. Status.sync = CREDENTIALS_CHANGED;
return false; return false;
} }
// Not sure this validation is necessary now. let syncKeyBundle = this._identity.syncKeyBundle;
if (!Utils.isPassphrase(this._identity.syncKey)) { if (!syncKeyBundle) {
this._log.warn("Sync key input is invalid: cannot fetch symmetric keys."); this._log.error("Sync Key Bundle not set. Invalid Sync Key?");
Status.login = LOGIN_FAILED_INVALID_PASSPHRASE; Status.login = LOGIN_FAILED_INVALID_PASSPHRASE;
Status.sync = CREDENTIALS_CHANGED; Status.sync = CREDENTIALS_CHANGED;
return false; return false;

View File

@ -180,6 +180,62 @@ add_test(function test_sync_key() {
run_next_test(); run_next_test();
}); });
add_test(function test_sync_key_changes() {
_("Ensure changes to Sync Key have appropriate side-effects.");
let im = new IdentityManager();
let sk1 = Utils.generatePassphrase();
let sk2 = Utils.generatePassphrase();
im.account = "johndoe";
do_check_eq(im.syncKey, null);
do_check_eq(im.syncKeyBundle, null);
im.syncKey = sk1;
do_check_neq(im.syncKeyBundle, null);
let ek1 = im.syncKeyBundle.encryptionKeyB64;
let hk1 = im.syncKeyBundle.hmacKeyB64;
// Change the Sync Key and ensure the Sync Key Bundle is updated.
im.syncKey = sk2;
let ek2 = im.syncKeyBundle.encryptionKeyB64;
let hk2 = im.syncKeyBundle.hmacKeyB64;
do_check_neq(ek1, ek2);
do_check_neq(hk1, hk2);
im.account = null;
run_next_test();
});
add_test(function test_current_auth_state() {
_("Ensure current auth state is reported properly.");
let im = new IdentityManager();
do_check_eq(im.currentAuthState, LOGIN_FAILED_NO_USERNAME);
im.account = "johndoe";
do_check_eq(im.currentAuthState, LOGIN_FAILED_NO_PASSWORD);
im.basicPassword = "ilovejane";
do_check_eq(im.currentAuthState, LOGIN_FAILED_NO_PASSPHRASE);
im.syncKey = "foobar";
do_check_eq(im.currentAuthState, LOGIN_FAILED_INVALID_PASSPHRASE);
im.syncKey = null;
do_check_eq(im.currentAuthState, LOGIN_FAILED_NO_PASSPHRASE);
im.syncKey = Utils.generatePassphrase();
do_check_eq(im.currentAuthState, STATUS_OK);
im.account = null;
run_next_test();
});
add_test(function test_sync_key_persistence() { add_test(function test_sync_key_persistence() {
_("Ensure Sync Key persistence works as expected."); _("Ensure Sync Key persistence works as expected.");