Bug 1443115 - Handle FxA pushEndpointExpired flag. r?markh
MozReview-Commit-ID: B0YIrtoSpOI
--- a/services/fxaccounts/FxAccounts.jsm
+++ b/services/fxaccounts/FxAccounts.jsm
@@ -687,18 +687,27 @@ FxAccountsInternal.prototype = {
// before returning the id to the caller.
return this._registerOrUpdateDevice(data);
}
// Return the device id that we already registered with the server.
return device.id;
},
async getDeviceList() {
- let accountData = await this._getVerifiedAccountOrReject();
- return this.fxAccountsClient.getDeviceList(accountData.sessionToken);
+ const accountData = await this._getVerifiedAccountOrReject();
+ const devices = await this.fxAccountsClient.getDeviceList(accountData.sessionToken);
+
+ // Check if our push registration is still good.
+ const ourDevice = devices.find(device => device.isCurrentDevice);
+ if (ourDevice.pushEndpointExpired) {
+ await this.fxaPushService.unsubscribe();
+ await this._registerOrUpdateDevice(accountData);
+ }
+
+ return devices;
},
/**
* Resend the verification email fot the currently signed-in user.
*
*/
resendVerificationEmail: function resendVerificationEmail() {
let currentState = this.currentAccountState;
--- a/services/fxaccounts/tests/xpcshell/test_accounts_device_registration.js
+++ b/services/fxaccounts/tests/xpcshell/test_accounts_device_registration.js
@@ -126,17 +126,17 @@ function MockFxAccounts(device = {}) {
add_task(async function test_updateDeviceRegistration_with_new_device() {
const deviceName = "foo";
const deviceType = "bar";
const credentials = getTestUser("baz");
const fxa = new MockFxAccounts({ name: deviceName });
await fxa.internal.setSignedInUser(credentials);
- // Remove the current device registration (setSIgnedInUser does one!).
+ // Remove the current device registration (setSignedInUser does one!).
await fxa.updateUserAccountData({uid: credentials.uid, device: null});
const spy = {
registerDevice: { count: 0, args: [] },
updateDevice: { count: 0, args: [] },
getDeviceList: { count: 0, args: [] }
};
const client = fxa.internal.fxAccountsClient;
@@ -527,16 +527,50 @@ add_task(async function test_migration_t
const state = fxa.internal.currentAccountState;
const data = await state.getUserAccountData();
Assert.deepEqual(data.device, {id: "mydeviceid", registrationVersion: DEVICE_REGISTRATION_VERSION});
Assert.ok(!data.deviceId);
Assert.ok(!data.deviceRegistrationVersion);
});
+add_task(async function test_devicelist_pushendpointexpired() {
+ const deviceId = "mydeviceid";
+ const credentials = getTestUser("baz");
+ credentials.verified = true;
+ const fxa = new MockFxAccounts();
+ await fxa.internal.setSignedInUser(credentials);
+ await fxa.updateUserAccountData({uid: credentials.uid, device: {
+ id: deviceId,
+ registrationVersion: 1 // < 42
+ }});
+
+ const spy = {
+ updateDevice: { count: 0, args: [] },
+ getDeviceList: { count: 0, args: [] }
+ };
+ const client = fxa.internal.fxAccountsClient;
+ client.updateDevice = function() {
+ spy.updateDevice.count += 1;
+ spy.updateDevice.args.push(arguments);
+ return Promise.resolve({});
+ };
+ client.getDeviceList = function() {
+ spy.getDeviceList.count += 1;
+ spy.getDeviceList.args.push(arguments);
+ return Promise.resolve([{id: "mydeviceid", name: "foo", type: "desktop",
+ isCurrentDevice: true, pushEndpointExpired: true}]);
+ };
+
+ await fxa.getDeviceList();
+
+ Assert.equal(spy.getDeviceList.count, 1);
+ Assert.equal(spy.updateDevice.count, 1);
+});
+
function expandHex(two_hex) {
// Return a 64-character hex string, encoding 32 identical bytes.
let eight_hex = two_hex + two_hex + two_hex + two_hex;
let thirtytwo_hex = eight_hex + eight_hex + eight_hex + eight_hex;
return thirtytwo_hex + thirtytwo_hex;
}
function expandBytes(two_hex) {