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

This commit is contained in:
Sam Penrose 2014-04-21 16:45:58 -07:00
Родитель 9b6dac2b36
Коммит 583311c132
3 изменённых файлов: 27 добавлений и 19 удалений

Просмотреть файл

@ -545,27 +545,33 @@ 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)
);
);
} else {
currentState.whenKeysReadyDeferred.reject('No keyFetchToken');
}
}
return currentState.whenKeysReadyDeferred.promise;
}).then(result => currentState.resolve(result));
@ -577,6 +583,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;
}

Просмотреть файл

@ -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();
});
});

Просмотреть файл

@ -560,6 +560,7 @@ add_task(function test_getKeysMissing() {
// try and fetch them.
delete identityConfig.fxaccount.user.kA;
delete identityConfig.fxaccount.user.kB;
identityConfig.fxaccount.user.keyFetchToken = 'keyFetchToken';
configureFxAccountIdentity(browseridManager, identityConfig);