Bug 983445 - Verification causes logout on device. r=jedp

This commit is contained in:
Sam Penrose 2014-04-15 16:05:16 -07:00
parent 1322056c01
commit 7b40268321
2 changed files with 24 additions and 19 deletions

View File

@ -505,27 +505,31 @@ FxAccountsInternal.prototype = {
*/
getKeys: function() {
let currentState = this.currentAccountState;
return currentState.getUserAccountData().then((data) => {
if (!data) {
return currentState.getUserAccountData().then((userData) => {
if (!userData) {
throw new Error("Can't get keys; User is not signed in");
}
if (data.kA && data.kB) {
return data;
if (userData.kA && userData.kB) {
return userData;
}
if (!currentState.whenKeysReadyDeferred) {
currentState.whenKeysReadyDeferred = Promise.defer();
this.fetchAndUnwrapKeys(data.keyFetchToken).then(
data => {
if (!data.kA || !data.kB) {
currentState.whenKeysReadyDeferred.reject(
new Error("user data missing kA or kB")
);
return;
if (userData.keyFetchToken) {
this.fetchAndUnwrapKeys(userData.keyFetchToken).then(
(dataWithKeys) => {
if (!dataWithKeys.kA || !dataWithKeys.kB) {
currentState.whenKeysReadyDeferred.reject(
new Error("user data missing kA or kB")
);
return;
}
currentState.whenKeysReadyDeferred.resolve(dataWithKeys);
},
(err) => {
currentState.whenKeysReadyDeferred.reject(err);
}
currentState.whenKeysReadyDeferred.resolve(data);
},
err => currentState.whenKeysReadyDeferred.reject(err)
);
);
}
}
return currentState.whenKeysReadyDeferred.promise;
}).then(result => currentState.resolve(result));
@ -537,6 +541,7 @@ FxAccountsInternal.prototype = {
return Task.spawn(function* task() {
// Sign out if we don't have a key fetch token.
if (!keyFetchToken) {
log.warn("improper fetchAndUnwrapKeys() call: token missing");
yield this.signOut();
return null;
}

View File

@ -305,8 +305,8 @@ add_test(function test_getKeys() {
});
});
// getKeys with no keyFetchToken should trigger signOut
add_test(function test_getKeys_no_token() {
// fetchAndUnwrapKeys with no keyFetchToken should trigger signOut
add_test(function test_fetchAndUnwrapKeys_no_token() {
do_test_pending();
let fxa = new MockFxAccounts();
@ -314,7 +314,7 @@ add_test(function test_getKeys_no_token() {
delete user.keyFetchToken
makeObserver(ONLOGOUT_NOTIFICATION, function() {
log.debug("test_getKeys_no_token observed logout");
log.debug("test_fetchAndUnwrapKeys_no_token observed logout");
fxa.internal.getUserAccountData().then(user => {
do_test_finished();
run_next_test();
@ -322,7 +322,7 @@ add_test(function test_getKeys_no_token() {
});
fxa.setSignedInUser(user).then((user) => {
fxa.internal.getKeys();
fxa.internal.fetchAndUnwrapKeys();
});
});