Bug 981210 - FxAccountsManager.jsm and consumers: change "accountId" attribute to "email" r=jedp
authorSam Penrose <spenrose@mozilla.com>
Tue, 29 Apr 2014 14:47:59 -0700
changeset 180943 d05f273a2d1d73487f882840054c752497e7f864
parent 180942 6888e03eb62724a66c8864b15a40c0d86a28f88e
child 180944 8cb07945825cc2500fd0e8ec537e9e295682fd81
push idunknown
push userunknown
push dateunknown
reviewersjedp
bugs981210
milestone32.0a1
Bug 981210 - FxAccountsManager.jsm and consumers: change "accountId" attribute to "email" r=jedp
b2g/components/FxAccountsMgmtService.jsm
b2g/components/FxAccountsUIGlue.js
b2g/components/test/unit/test_fxaccounts.js
services/fxaccounts/FxAccountsCommon.js
services/fxaccounts/FxAccountsManager.jsm
services/fxaccounts/interfaces/nsIFxAccountsUIGlue.idl
services/fxaccounts/tests/xpcshell/test_manager.js
--- a/b2g/components/FxAccountsMgmtService.jsm
+++ b/b2g/components/FxAccountsMgmtService.jsm
@@ -81,16 +81,21 @@ this.FxAccountsMgmtService = {
     if (!msg.id) {
       return;
     }
 
     let data = msg.data;
     if (!data) {
       return;
     }
+    // Backwards compatibility: handle accountId coming from Gaia
+    if (data.accountId && typeof(data.email === "undefined")) {
+      data.email = data.accountId;
+      delete data.accountId;
+    }
 
     switch(data.method) {
       case "getAccounts":
         FxAccountsManager.getAccount().then(
           account => {
             // We only expose the email and verification status so far.
             self._onFulfill(msg.id, account);
           },
@@ -105,29 +110,29 @@ this.FxAccountsMgmtService = {
             self._onFulfill(msg.id);
           },
           reason => {
             self._onReject(msg.id, reason);
           }
         ).then(null, Components.utils.reportError);
         break;
       case "queryAccount":
-        FxAccountsManager.queryAccount(data.accountId).then(
+        FxAccountsManager.queryAccount(data.email).then(
           result => {
             self._onFulfill(msg.id, result);
           },
           reason => {
             self._onReject(msg.id, reason);
           }
         ).then(null, Components.utils.reportError);
         break;
       case "signIn":
       case "signUp":
       case "refreshAuthentication":
-        FxAccountsManager[data.method](data.accountId, data.password).then(
+        FxAccountsManager[data.method](data.email, data.password).then(
           user => {
             self._onFulfill(msg.id, user);
           },
           reason => {
             self._onReject(msg.id, reason);
           }
         ).then(null, Components.utils.reportError);
         break;
--- a/b2g/components/FxAccountsUIGlue.js
+++ b/b2g/components/FxAccountsUIGlue.js
@@ -59,19 +59,19 @@ FxAccountsUIGlue.prototype = {
 
     return deferred.promise;
   },
 
   signInFlow: function() {
     return this._contentRequest("openFlow");
   },
 
-  refreshAuthentication: function(aAccountId) {
+  refreshAuthentication: function(aEmail) {
     return this._contentRequest("refreshAuthentication", {
-      accountId: aAccountId
+      email: aEmail
     });
   },
 
   classID: Components.ID("{51875c14-91d7-4b8c-b65d-3549e101228c}"),
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIFxAccountsUIGlue])
 };
 
--- a/b2g/components/test/unit/test_fxaccounts.js
+++ b/b2g/components/test/unit/test_fxaccounts.js
@@ -123,17 +123,17 @@ add_test(function test_invalidEmailCase_
         break;
 
       // Having initially signed in as "Greta.Garbo", getAccounts should show
       // us that the signed-in user has the properly-capitalized email,
       // "greta.garbo".
       case "getAccounts":
         Services.obs.removeObserver(onMessage, "mozFxAccountsChromeEvent");
 
-        do_check_eq(message.data.accountId, canonicalEmail);
+        do_check_eq(message.data.email, canonicalEmail);
 
         do_test_finished();
         server.stop(run_next_test);
         break;
 
       // We should not receive any other mozFxAccountsChromeEvent messages
       default:
         do_throw("wat!");
@@ -146,17 +146,17 @@ add_test(function test_invalidEmailCase_
   SystemAppProxy._sendCustomEvent = mockSendCustomEvent;
 
   // Trigger signIn using an email with incorrect capitalization
   FxAccountsMgmtService.handleEvent({
     detail: {
       id: "signIn",
       data: {
         method: "signIn",
-        accountId: clientEmail,
+        email: clientEmail,
         password: "123456",
       },
     },
   });
 });
 
 // End of tests
 // Utility functions follow
--- a/services/fxaccounts/FxAccountsCommon.js
+++ b/services/fxaccounts/FxAccountsCommon.js
@@ -86,17 +86,17 @@ this.ERRNO_UNKNOWN_ERROR                
 this.ERROR_ACCOUNT_ALREADY_EXISTS         = "ACCOUNT_ALREADY_EXISTS";
 this.ERROR_ACCOUNT_DOES_NOT_EXIST         = "ACCOUNT_DOES_NOT_EXIST ";
 this.ERROR_ALREADY_SIGNED_IN_USER         = "ALREADY_SIGNED_IN_USER";
 this.ERROR_ENDPOINT_NO_LONGER_SUPPORTED   = "ENDPOINT_NO_LONGER_SUPPORTED";
 this.ERROR_INCORRECT_API_VERSION          = "INCORRECT_API_VERSION";
 this.ERROR_INCORRECT_EMAIL_CASE           = "INCORRECT_EMAIL_CASE";
 this.ERROR_INCORRECT_KEY_RETRIEVAL_METHOD = "INCORRECT_KEY_RETRIEVAL_METHOD";
 this.ERROR_INCORRECT_LOGIN_METHOD         = "INCORRECT_LOGIN_METHOD";
-this.ERROR_INVALID_ACCOUNTID              = "INVALID_ACCOUNTID";
+this.ERROR_INVALID_EMAIL                  = "INVALID_EMAIL";
 this.ERROR_INVALID_AUDIENCE               = "INVALID_AUDIENCE";
 this.ERROR_INVALID_AUTH_TOKEN             = "INVALID_AUTH_TOKEN";
 this.ERROR_INVALID_AUTH_TIMESTAMP         = "INVALID_AUTH_TIMESTAMP";
 this.ERROR_INVALID_AUTH_NONCE             = "INVALID_AUTH_NONCE";
 this.ERROR_INVALID_BODY_PARAMETERS        = "INVALID_BODY_PARAMETERS";
 this.ERROR_INVALID_PASSWORD               = "INVALID_PASSWORD";
 this.ERROR_INVALID_VERIFICATION_CODE      = "INVALID_VERIFICATION_CODE";
 this.ERROR_INVALID_REFRESH_AUTH_VALUE     = "INVALID_REFRESH_AUTH_VALUE";
--- a/services/fxaccounts/FxAccountsManager.jsm
+++ b/services/fxaccounts/FxAccountsManager.jsm
@@ -50,17 +50,17 @@ this.FxAccountsManager = {
 
   // We only expose the email and the verified status so far.
   get _user() {
     if (!this._activeSession || !this._activeSession.email) {
       return null;
     }
 
     return {
-      accountId: this._activeSession.email,
+      email: this._activeSession.email,
       verified: this._activeSession.verified
     }
   },
 
   _error: function(aError, aDetails) {
     log.error(aError);
     let reason = {
       error: aError
@@ -88,23 +88,23 @@ this.FxAccountsManager = {
   // allow tests to mock FxAccountsClient.  By default, we want to return the
   // client used by the fxAccounts object because deep down they should have
   // access to the same hawk request object which will enable them to share
   // local clock skeq data.
   _getFxAccountsClient: function() {
     return this._fxAccounts.getAccountsClient();
   },
 
-  _signInSignUp: function(aMethod, aAccountId, aPassword) {
+  _signInSignUp: function(aMethod, aEmail, aPassword) {
     if (Services.io.offline) {
       return this._error(ERROR_OFFLINE);
     }
 
-    if (!aAccountId) {
-      return this._error(ERROR_INVALID_ACCOUNTID);
+    if (!aEmail) {
+      return this._error(ERROR_INVALID_EMAIL);
     }
 
     if (!aPassword) {
       return this._error(ERROR_INVALID_PASSWORD);
     }
 
     // Check that there is no signed in account first.
     if ((!this._refreshing) && this._activeSession) {
@@ -116,31 +116,31 @@ this.FxAccountsManager = {
     let client = this._getFxAccountsClient();
     return this._fxAccounts.getSignedInUser().then(
       user => {
         if ((!this._refreshing) && user) {
           return this._error(ERROR_ALREADY_SIGNED_IN_USER, {
             user: this._user
           });
         }
-        return client[aMethod](aAccountId, aPassword);
+        return client[aMethod](aEmail, aPassword);
       }
     ).then(
       user => {
         let error = this._getError(user);
         if (!user || !user.uid || !user.sessionToken || error) {
           return this._error(error ? error : ERROR_INTERNAL_INVALID_USER, {
             user: user
           });
         }
 
         // If the user object includes an email field, it may differ in
         // capitalization from what we sent down.  This is the server's
         // canonical capitalization and should be used instead.
-        user.email = user.email || aAccountId;
+        user.email = user.email || aEmail;
         return this._fxAccounts.setSignedInUser(user).then(
           () => {
             this._activeSession = user;
             log.debug("User signed in: " + JSON.stringify(this._user) +
                       " - Account created " + (aMethod == "signUp"));
             return Promise.resolve({
               accountCreated: aMethod === "signUp",
               user: this._user
@@ -221,22 +221,22 @@ this.FxAccountsManager = {
       error => {
         return this._error(ERROR_UI_ERROR, error);
       }
     );
   },
 
   // -- API --
 
-  signIn: function(aAccountId, aPassword) {
-    return this._signInSignUp("signIn", aAccountId, aPassword);
+  signIn: function(aEmail, aPassword) {
+    return this._signInSignUp("signIn", aEmail, aPassword);
   },
 
-  signUp: function(aAccountId, aPassword) {
-    return this._signInSignUp("signUp", aAccountId, aPassword);
+  signUp: function(aEmail, aPassword) {
+    return this._signInSignUp("signUp", aEmail, aPassword);
   },
 
   signOut: function() {
     if (!this._activeSession) {
       // If there is no cached active session, we try to get it from the
       // account storage.
       return this.getAccount().then(
         result => {
@@ -281,30 +281,30 @@ this.FxAccountsManager = {
         }
 
         log.debug("Account " + JSON.stringify(this._user));
         return Promise.resolve(this._user);
       }
     );
   },
 
-  queryAccount: function(aAccountId) {
-    log.debug("queryAccount " + aAccountId);
+  queryAccount: function(aEmail) {
+    log.debug("queryAccount " + aEmail);
     if (Services.io.offline) {
       return this._error(ERROR_OFFLINE);
     }
 
     let deferred = Promise.defer();
 
-    if (!aAccountId) {
-      return this._error(ERROR_INVALID_ACCOUNTID);
+    if (!aEmail) {
+      return this._error(ERROR_INVALID_EMAIL);
     }
 
     let client = this._getFxAccountsClient();
-    return client.accountExists(aAccountId).then(
+    return client.accountExists(aEmail).then(
       result => {
         log.debug("Account " + result ? "" : "does not" + " exists");
         let error = this._getError(result);
         if (error) {
           return this._error(error, result);
         }
 
         return Promise.resolve({
@@ -393,17 +393,17 @@ this.FxAccountsManager = {
               return this._error(ERROR_NO_SILENT_REFRESH_AUTH);
             }
             if ((Date.now() / 1000) - this._activeSession.authAt > gracePeriod) {
               // Grace period expired, so we sign out and request the user to
               // authenticate herself again. If the authentication succeeds, we
               // will return the assertion. Otherwise, we will return an error.
               this._refreshing = true;
               return this._uiRequest(UI_REQUEST_REFRESH_AUTH,
-                                     aAudience, user.accountId).then(
+                                     aAudience, user.email).then(
                 (assertion) => {
                   this._refreshing = false;
                   return assertion;
                 },
                 (reason) => {
                   this._refreshing = false;
                   return this._signOut().then(
                     () => {
--- a/services/fxaccounts/interfaces/nsIFxAccountsUIGlue.idl
+++ b/services/fxaccounts/interfaces/nsIFxAccountsUIGlue.idl
@@ -6,10 +6,10 @@
 
 [scriptable, uuid(ab8d0700-9577-11e3-a5e2-0800200c9a66)]
 interface nsIFxAccountsUIGlue : nsISupports
 {
   // Returns a Promise.
   jsval signInFlow();
 
   // Returns a Promise.
-  jsval refreshAuthentication(in DOMString accountId);
+  jsval refreshAuthentication(in DOMString email);
 };
--- a/services/fxaccounts/tests/xpcshell/test_manager.js
+++ b/services/fxaccounts/tests/xpcshell/test_manager.js
@@ -407,17 +407,17 @@ add_test(function(test_getAssertion_refr
   );
 });
 
 add_test(function(test_getAccount_existing_verified_session) {
   do_print("= getAccount, existing verified session =");
   FxAccountsManager.getAccount().then(
     result => {
       do_check_false(FxAccountsManager._fxAccounts._getSignedInUserCalled);
-      do_check_eq(result.accountId, FxAccountsManager._user.accountId);
+      do_check_eq(result.email, FxAccountsManager._user.email);
       do_check_eq(result.verified, FxAccountsManager._user.verified);
       run_next_test();
     },
     error => {
       do_throw("Unexpected error: " + error);
     }
   );
 });
@@ -425,17 +425,17 @@ add_test(function(test_getAccount_existi
 add_test(function(test_getAccount_existing_unverified_session_unverified_user) {
   do_print("= getAccount, existing unverified session, unverified user =");
   FxAccountsManager._activeSession.verified = false;
   FxAccountsManager._fxAccounts._signedInUser.verified = false;
   FxAccountsManager.getAccount().then(
     result => {
       do_check_true(FakeFxAccountsClient._recoveryEmailStatusCalled);
       do_check_false(result.verified);
-      do_check_eq(result.accountId, FxAccountsManager._user.accountId);
+      do_check_eq(result.email, FxAccountsManager._user.email);
       FakeFxAccountsClient._reset();
       run_next_test();
     },
     error => {
       do_throw("Unexpected error: " + error);
     }
   );
 });
@@ -446,17 +446,17 @@ add_test(function(test_getAccount_existi
   FxAccountsManager._fxAccounts._signedInUser.verified = false;
   FakeFxAccountsClient._verified = true;
   FxAccountsManager.getAccount();
   do_execute_soon(function() {
     do_check_true(FakeFxAccountsClient._recoveryEmailStatusCalled);
     FxAccountsManager.getAccount().then(
       result => {
         do_check_true(result.verified);
-        do_check_eq(result.accountId, FxAccountsManager._user.accountId);
+        do_check_eq(result.email, FxAccountsManager._user.email);
         FakeFxAccountsClient._reset();
         run_next_test();
     });
   });
 });
 
 add_test(function(test_signOut) {
   do_print("= signOut =");
@@ -469,57 +469,57 @@ add_test(function(test_signOut) {
       run_next_test();
     },
     error => {
       do_throw("Unexpected error: " + error);
     }
   );
 });
 
-add_test(function(test_signUp_no_accountId) {
-  do_print("= signUp, no accountId=");
+add_test(function(test_signUp_no_email) {
+  do_print("= signUp, no email=");
   FxAccountsManager.signUp().then(
     () => {
       do_throw("Unexpected success");
     },
     error => {
-      do_check_eq(error.error, ERROR_INVALID_ACCOUNTID);
+      do_check_eq(error.error, ERROR_INVALID_EMAIL);
       run_next_test();
     }
   );
 });
 
-add_test(function(test_signIn_no_accountId) {
-  do_print("= signIn, no accountId=");
+add_test(function(test_signIn_no_email) {
+  do_print("= signIn, no email=");
   FxAccountsManager.signIn().then(
     () => {
       do_throw("Unexpected success");
     },
     error => {
-      do_check_eq(error.error, ERROR_INVALID_ACCOUNTID);
+      do_check_eq(error.error, ERROR_INVALID_EMAIL);
       run_next_test();
     }
   );
 });
 
 add_test(function(test_signUp_no_password) {
-  do_print("= signUp, no accountId=");
+  do_print("= signUp, no email=");
   FxAccountsManager.signUp("user@domain.org").then(
     () => {
       do_throw("Unexpected success");
     },
     error => {
       do_check_eq(error.error, ERROR_INVALID_PASSWORD);
       run_next_test();
     }
   );
 });
 
-add_test(function(test_signIn_no_accountId) {
-  do_print("= signIn, no accountId=");
+add_test(function(test_signIn_no_email) {
+  do_print("= signIn, no email=");
   FxAccountsManager.signIn("user@domain.org").then(
     () => {
       do_throw("Unexpected success");
     },
     error => {
       do_check_eq(error.error, ERROR_INVALID_PASSWORD);
       run_next_test();
     }
@@ -532,17 +532,17 @@ add_test(function(test_signUp) {
   FxAccountsManager.signUp("user@domain.org", "password").then(
     result => {
       do_check_true(FakeFxAccountsClient._signInCalled);
       do_check_true(FakeFxAccountsClient._signUpCalled);
       do_check_true(FxAccountsManager._fxAccounts._getSignedInUserCalled);
       do_check_eq(FxAccountsManager._fxAccounts._signedInUser.email, "user@domain.org");
       do_check_eq(FakeFxAccountsClient._password, "password");
       do_check_true(result.accountCreated);
-      do_check_eq(result.user.accountId, "user@domain.org");
+      do_check_eq(result.user.email, "user@domain.org");
       do_check_false(result.user.verified);
       FakeFxAccountsClient._reset();
       FxAccountsManager._fxAccounts._reset();
       run_next_test();
     },
     error => {
       do_throw("Unexpected error: " + error.error);
     }
@@ -553,32 +553,32 @@ add_test(function(test_signUp_already_si
   do_print("= signUp, already signed user =");
   FxAccountsManager.signUp("user@domain.org", "password").then(
     () => {
       do_throw("Unexpected success");
     },
     error => {
       do_check_false(FakeFxAccountsClient._signInCalled);
       do_check_eq(error.error, ERROR_ALREADY_SIGNED_IN_USER);
-      do_check_eq(error.details.user.accountId, "user@domain.org");
+      do_check_eq(error.details.user.email, "user@domain.org");
       do_check_false(error.details.user.verified);
       run_next_test();
     }
   );
 });
 
 add_test(function(test_signIn_already_signed_user) {
   do_print("= signIn, already signed user =");
   FxAccountsManager.signIn("user@domain.org", "password").then(
     () => {
       do_throw("Unexpected success");
     },
     error => {
       do_check_eq(error.error, ERROR_ALREADY_SIGNED_IN_USER);
-      do_check_eq(error.details.user.accountId, "user@domain.org");
+      do_check_eq(error.details.user.email, "user@domain.org");
       do_check_false(error.details.user.verified);
       run_next_test();
     }
   );
 });
 
 add_test(function(test_verificationStatus_unverified_session_unverified_user) {
   do_print("= verificationStatus unverified session and user =");
@@ -628,24 +628,24 @@ add_test(function(test_queryAccount_exis
       run_next_test();
     },
     error => {
       do_throw("Unexpected error: " + error);
     }
   );
 });
 
-add_test(function(test_queryAccount_no_accountId) {
-  do_print("= queryAccount, no accountId =");
+add_test(function(test_queryAccount_no_email) {
+  do_print("= queryAccount, no email =");
   FxAccountsManager.queryAccount().then(
     () => {
       do_throw("Unexpected success");
     },
     error => {
-      do_check_eq(error.error, ERROR_INVALID_ACCOUNTID);
+      do_check_eq(error.error, ERROR_INVALID_EMAIL);
       run_next_test();
     }
   );
 });
 
 add_test(function() {
   do_print("= fxaccounts:onlogout notification =");
   do_check_true(FxAccountsManager._activeSession != null);