Bug 1365375 - Disconnect Sync on account destroyed. r=markh

This connects to the fxa-auth-server PR:
https://github.com/mozilla/fxa-auth-server/pull/1900

MozReview-Commit-ID: IIYnytYGIpw

--HG--
extra : rebase_source : 04a6adb81252c0c4aa0eaaa01b68e3943791aadc
This commit is contained in:
Edouard Oger 2017-05-17 16:25:00 -04:00
Родитель 3ddfb3c1ce
Коммит 69602ba5f2
4 изменённых файлов: 55 добавлений и 1 удалений

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

@ -52,6 +52,7 @@ var publicProperties = [
"getSignedInUser",
"getSignedInUserProfile",
"handleDeviceDisconnection",
"handleAccountDestroyed",
"invalidateCertificate",
"loadAndPoll",
"localtimeOffsetMsec",
@ -1568,7 +1569,7 @@ FxAccountsInternal.prototype = {
return null;
}
if (deviceId == localDeviceId) {
this.notifyObservers(ON_DEVICE_DISCONNECTED_NOTIFICATION, deviceId);
this.notifyObservers(ON_DEVICE_DISCONNECTED_NOTIFICATION);
return this.signOut(true);
}
log.error(
@ -1578,6 +1579,25 @@ FxAccountsInternal.prototype = {
});
},
handleAccountDestroyed(uid) {
return this.currentAccountState.getUserAccountData()
.then(data => data ? data.uid : null)
.then(localUid => {
if (!localUid) {
log.info(`Account destroyed push notification received, but we're already logged-out`);
return null;
}
if (uid == localUid) {
this.notifyObservers(ON_DEVICE_DISCONNECTED_NOTIFICATION);
return this.signOut(true);
}
log.info(
`The destroyed account uid doesn't match with the local uid. ` +
`Local: ${localUid}, account uid destroyed: ${uid}`);
return null;
});
},
/**
* Delete all the cached persisted credentials we store for FxA.
*

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

@ -94,6 +94,7 @@ exports.ON_DEVICE_DISCONNECTED_NOTIFICATION = "fxaccounts:device_disconnected";
exports.ON_PROFILE_UPDATED_NOTIFICATION = "fxaccounts:profile_updated"; // Push
exports.ON_PASSWORD_CHANGED_NOTIFICATION = "fxaccounts:password_changed";
exports.ON_PASSWORD_RESET_NOTIFICATION = "fxaccounts:password_reset";
exports.ON_ACCOUNT_DESTROYED_NOTIFICATION = "fxaccounts:account_destroyed";
exports.ON_COLLECTION_CHANGED_NOTIFICATION = "sync:collection_changed";
exports.FXA_PUSH_SCOPE_ACCOUNT_UPDATE = "chrome://fxa-device-update";

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

@ -179,6 +179,9 @@ FxAccountsPushService.prototype = {
case ON_PASSWORD_RESET_NOTIFICATION:
this._onPasswordChanged();
return;
case ON_ACCOUNT_DESTROYED_NOTIFICATION:
this.fxAccounts.handleAccountDestroyed(payload.data.uid);
return;
case ON_COLLECTION_CHANGED_NOTIFICATION:
Services.obs.notifyObservers(null, ON_COLLECTION_CHANGED_NOTIFICATION, payload.data.collections);
default:

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

@ -201,6 +201,36 @@ add_test(function observePushTopicDeviceDisconnected() {
pushService.observe(msg, mockPushService.pushTopic, FXA_PUSH_SCOPE_ACCOUNT_UPDATE);
});
add_test(function observePushTopicAccountDestroyed() {
const uid = "bogusuid";
let msg = {
data: {
json: () => ({
command: ON_ACCOUNT_DESTROYED_NOTIFICATION,
data: {
uid: uid
}
})
},
QueryInterface() {
return this;
}
};
let customAccounts = Object.assign(mockFxAccounts, {
handleAccountDestroyed() {
// checking verification status on push messages without data
run_next_test();
}
});
let pushService = new FxAccountsPushService({
pushService: mockPushService,
fxAccounts: customAccounts,
});
pushService.observe(msg, mockPushService.pushTopic, FXA_PUSH_SCOPE_ACCOUNT_UPDATE);
});
add_test(function observePushTopicProfileUpdated() {
let msg = {
data: {