Bug 996027 - Ensure that TPS always fakes login into Weave. r=rnewman DONTBUILD
authorHenrik Skupin <mail@hskupin.info>
Mon, 14 Apr 2014 18:22:23 +0200
changeset 179388 6196c121c4f4f7241931e7ce1608c8c97c7433d6
parent 179345 e71ed4135461b57a9c7f35995e4e1f1dc5f0e8bf
child 179389 a64bdaed44e31b22a2a14c92d7211511fa5fc57b
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersrnewman
bugs996027
milestone31.0a1
Bug 996027 - Ensure that TPS always fakes login into Weave. r=rnewman DONTBUILD
services/sync/tps/extensions/tps/resource/auth/fxaccounts.jsm
services/sync/tps/extensions/tps/resource/auth/sync.jsm
services/sync/tps/extensions/tps/resource/tps.jsm
--- a/services/sync/tps/extensions/tps/resource/auth/fxaccounts.jsm
+++ b/services/sync/tps/extensions/tps/resource/auth/fxaccounts.jsm
@@ -74,14 +74,23 @@ var Authentication = {
       return fxAccounts.setSignedInUser(credentials);
     }).then(() => {
       cb(null, true);
     }, error => {
       cb(error, false);
     });
 
     try {
-      return cb.wait();
+      cb.wait();
+
+      if (Weave.Status.login !== Weave.LOGIN_SUCCEEDED) {
+        Logger.logInfo("Logging into Weave.");
+        Weave.Service.login();
+        Logger.AssertEqual(Weave.Status.login, Weave.LOGIN_SUCCEEDED,
+                           "Weave logged in");
+      }
+
+      return true;
     } catch (error) {
-      throw new Error("signIn() failed with: " + JSON.stringify(error));
+      throw new Error("signIn() failed with: " + error.message);
     }
   }
 };
--- a/services/sync/tps/extensions/tps/resource/auth/sync.jsm
+++ b/services/sync/tps/extensions/tps/resource/auth/sync.jsm
@@ -63,15 +63,22 @@ var Authentication = {
     Logger.AssertTrue(account["passphrase"], "Passphrase has been found");
 
     Logger.logInfo("Logging in user: " + account["username"]);
 
     Weave.Service.identity.account = account["username"];
     Weave.Service.identity.basicPassword = account["password"];
     Weave.Service.identity.syncKey = account["passphrase"];
 
-    // Fake the login
-    Weave.Service.login();
-    Weave.Svc.Obs.notify("weave:service:setup-complete");
+    if (Weave.Status.login !== Weave.LOGIN_SUCCEEDED) {
+      Logger.logInfo("Logging into Weave.");
+      Weave.Service.login();
+      Logger.AssertEqual(Weave.Status.login, Weave.LOGIN_SUCCEEDED,
+                         "Weave logged in");
+
+      // Bug 997279: Temporary workaround until we can ensure that Sync itself
+      // sends this notification for the first login attempt by TPS
+      Weave.Svc.Obs.notify("weave:service:setup-complete");
+    }
 
     return true;
   }
 };
--- a/services/sync/tps/extensions/tps/resource/tps.jsm
+++ b/services/sync/tps/extensions/tps/resource/tps.jsm
@@ -832,17 +832,16 @@ let TPS = {
     if (Authentication.isLoggedIn && !force) {
       return;
     }
 
     Logger.logInfo("Setting client credentials and login.");
     let account = this.fxaccounts_enabled ? this.config.fx_account
                                           : this.config.sync_account;
     Authentication.signIn(account);
-
     this.waitForSetupComplete();
     Logger.AssertEqual(Weave.Status.service, Weave.STATUS_OK, "Weave status OK");
     this.waitForTracking();
   },
 
   /**
    * Triggers a sync operation
    *