Bug 1296328 - Update FxA device registration on password change. r=markh, a=ritu
authorPhil Booth <pmbooth@gmail.com>
Fri, 19 Aug 2016 04:18:00 -0400
changeset 350055 6d1a9befbdc318d41328ad086720d0dfb6cd5626
parent 350054 a0763ab5e61d1f23dd393892a46734625b2b1ea6
child 350056 8a65412e524b7b9515b5b6c4b54b5f7b813c23da
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh, ritu
bugs1296328
milestone50.0a2
Bug 1296328 - Update FxA device registration on password change. r=markh, a=ritu
services/fxaccounts/FxAccountsWebChannel.jsm
services/fxaccounts/tests/xpcshell/test_web_channel.js
--- a/services/fxaccounts/FxAccountsWebChannel.jsm
+++ b/services/fxaccounts/FxAccountsWebChannel.jsm
@@ -336,17 +336,18 @@ this.FxAccountsWebChannelHelpers.prototy
     let newCredentials = {};
     for (let name of Object.keys(credentials)) {
       if (name == "email" || name == "uid" || FxAccountsStorageManagerCanStoreField(name)) {
         newCredentials[name] = credentials[name];
       } else {
         log.info("changePassword ignoring unsupported field", name);
       }
     }
-    return this._fxAccounts.updateUserAccountData(newCredentials);
+    return this._fxAccounts.updateUserAccountData(newCredentials)
+      .then(() => this._fxAccounts.updateDeviceRegistration());
   },
 
   /**
    * Get the hash of account name of the previously signed in account
    */
   getPreviousAccountNameHashPref() {
     try {
       return Services.prefs.getComplexValue(PREF_LAST_FXA_USER, Ci.nsISupportsString).data;
--- a/services/fxaccounts/tests/xpcshell/test_web_channel.js
+++ b/services/fxaccounts/tests/xpcshell/test_web_channel.js
@@ -398,35 +398,72 @@ add_test(function test_helpers_open_sync
       run_next_test();
     }
   };
 
   helpers.openSyncPreferences(mockBrowser, "fxa:verification_complete");
 });
 
 add_task(function* test_helpers_change_password() {
-  let updateCalled = false;
+  let wasCalled = {
+    updateUserAccountData: false,
+    updateDeviceRegistration: false
+  };
   let helpers = new FxAccountsWebChannelHelpers({
     fxAccounts: {
       updateUserAccountData(credentials) {
         return new Promise(resolve => {
           do_check_true(credentials.hasOwnProperty("email"));
           do_check_true(credentials.hasOwnProperty("uid"));
           do_check_true(credentials.hasOwnProperty("kA"));
           // "foo" isn't a field known by storage, so should be dropped.
           do_check_false(credentials.hasOwnProperty("foo"));
-          updateCalled = true;
+          wasCalled.updateUserAccountData = true;
 
           resolve();
         });
+      },
+
+      updateDeviceRegistration() {
+        do_check_eq(arguments.length, 0);
+        wasCalled.updateDeviceRegistration = true;
+        return Promise.resolve()
       }
     }
   });
   yield helpers.changePassword({ email: "email", uid: "uid", kA: "kA", foo: "foo" });
-  do_check_true(updateCalled);
+  do_check_true(wasCalled.updateUserAccountData);
+  do_check_true(wasCalled.updateDeviceRegistration);
+});
+
+add_task(function* test_helpers_change_password_with_error() {
+  let wasCalled = {
+    updateUserAccountData: false,
+    updateDeviceRegistration: false
+  };
+  let helpers = new FxAccountsWebChannelHelpers({
+    fxAccounts: {
+      updateUserAccountData() {
+        wasCalled.updateUserAccountData = true;
+        return Promise.reject();
+      },
+
+      updateDeviceRegistration() {
+        wasCalled.updateDeviceRegistration = true;
+        return Promise.resolve()
+      }
+    }
+  });
+  try {
+    yield helpers.changePassword({});
+    do_check_false('changePassword should have rejected');
+  } catch (_) {
+    do_check_true(wasCalled.updateUserAccountData);
+    do_check_false(wasCalled.updateDeviceRegistration);
+  }
 });
 
 function run_test() {
   run_next_test();
 }
 
 function makeObserver(aObserveTopic, aObserveFunc) {
   let callback = function (aSubject, aTopic, aData) {