Bug 1443115 - Handle FxA pushEndpointExpired flag. r=markh
authorEdouard Oger <eoger@fastmail.com>
Tue, 10 Apr 2018 15:47:26 -0400
changeset 412898 425022df8add48407655b3849145500efecc5dcc
parent 412897 b714d7b304178c5b6a685249ba91505300a0324f
child 412899 1fe53fae0f8d5429bea94dced05cc43f2616c8f9
push id33823
push userebalazs@mozilla.com
push dateThu, 12 Apr 2018 09:38:35 +0000
treeherdermozilla-central@abd91e812e7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs1443115
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1443115 - Handle FxA pushEndpointExpired flag. r=markh MozReview-Commit-ID: B0YIrtoSpOI
services/fxaccounts/FxAccounts.jsm
services/fxaccounts/tests/xpcshell/test_accounts_device_registration.js
--- 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) {