Bug 1296767 part 13 - Repair Weave Service getStorageInfo. r=markh
☠☠ backed out by 9eae58c7414b ☠ ☠
authorEdouard Oger <eoger@fastmail.com>
Mon, 23 Jan 2017 15:19:04 -0500
changeset 360249 41ed7778833327295ade26481e8561c68c931a0e
parent 360248 1c0c9289b5327816345531b198e40a2592015319
child 360250 0702ce2e636a06ec0c3a8f175b97bfc2c5bc23d4
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs1296767
milestone54.0a1
Bug 1296767 part 13 - Repair Weave Service getStorageInfo. r=markh MozReview-Commit-ID: E4S5xYTNDIH
services/sync/modules/rest.js
services/sync/tests/unit/test_service_getStorageInfo.js
services/sync/tests/unit/test_syncstoragerequest.js
services/sync/tests/unit/xpcshell.ini
--- a/services/sync/modules/rest.js
+++ b/services/sync/modules/rest.js
@@ -34,17 +34,22 @@ SyncStorageRequest.prototype = {
 
   dispatch: function dispatch(method, data, onComplete, onProgress) {
     // Compose a UA string fragment from the various available identifiers.
     if (Svc.Prefs.get("sendVersionInfo", true)) {
       this.setHeader("user-agent", Utils.userAgent);
     }
 
     if (this.authenticator) {
-      this.authenticator(this);
+      let result = this.authenticator(this, method);
+      if (result && result.headers) {
+        for (let [k, v] of Object.entries(result.headers)) {
+          setHeader(k, v);
+        }
+      }
     } else {
       this._log.debug("No authenticator found.");
     }
 
     return RESTRequest.prototype.dispatch.apply(this, arguments);
   },
 
   onStartRequest: function onStartRequest(channel) {
--- a/services/sync/tests/unit/test_service_getStorageInfo.js
+++ b/services/sync/tests/unit/test_service_getStorageInfo.js
@@ -14,35 +14,30 @@ var collections = {steam:  65.11328,
                    petrol: 82.488281,
                    diesel: 2.25488281};
 
 function run_test() {
   Log.repository.getLogger("Sync.Service").level = Log.Level.Trace;
   Log.repository.getLogger("Sync.StorageRequest").level = Log.Level.Trace;
   initTestLogging();
 
-  ensureLegacyIdentityManager();
-  setBasicCredentials("johndoe", "ilovejane");
-
   run_next_test();
 }
 
-add_test(function test_success() {
+add_task(async function test_success() {
   let handler = httpd_handler(200, "OK", JSON.stringify(collections));
   let server = httpd_setup({"/1.1/johndoe/info/collections": handler});
-  Service.clusterURL = server.baseURI + "/";
+  await configureIdentity({ username: "johndoe" }, server);
 
   let request = Service.getStorageInfo("collections", function(error, info) {
     do_check_eq(error, null);
     do_check_true(Utils.deepEquals(info, collections));
 
     // Ensure that the request is sent off with the right bits.
-    do_check_true(basic_auth_matches(handler.request,
-                                     Service.identity.username,
-                                     Service.identity.basicPassword));
+    do_check_true(has_hawk_header(handler.request));
     let expectedUA = Services.appinfo.name + "/" + Services.appinfo.version +
                      " (" + httpProtocolHandler.oscpu + ")" +
                      " FxSync/" + WEAVE_VERSION + "." +
                      Services.appinfo.appBuildID + ".desktop";
     do_check_eq(handler.request.getHeader("User-Agent"), expectedUA);
 
     server.stop(run_next_test);
   });
@@ -61,31 +56,31 @@ add_test(function test_invalid_type() {
 add_test(function test_network_error() {
   Service.getStorageInfo(INFO_COLLECTIONS, function(error, info) {
     do_check_eq(error.result, Cr.NS_ERROR_CONNECTION_REFUSED);
     do_check_eq(info, null);
     run_next_test();
   });
 });
 
-add_test(function test_http_error() {
+add_task(async function test_http_error() {
   let handler = httpd_handler(500, "Oh noez", "Something went wrong!");
   let server = httpd_setup({"/1.1/johndoe/info/collections": handler});
-  Service.clusterURL = server.baseURI + "/";
+  await configureIdentity({ username: "johndoe" }, server);
 
   Service.getStorageInfo(INFO_COLLECTIONS, function(error, info) {
     do_check_eq(error.status, 500);
     do_check_eq(info, null);
     server.stop(run_next_test);
   });
 });
 
-add_test(function test_invalid_json() {
+add_task(async function test_invalid_json() {
   let handler = httpd_handler(200, "OK", "Invalid JSON");
   let server = httpd_setup({"/1.1/johndoe/info/collections": handler});
-  Service.clusterURL = server.baseURI + "/";
+  await configureIdentity({ username: "johndoe" }, server);
 
   Service.getStorageInfo(INFO_COLLECTIONS, function(error, info) {
     do_check_eq(error.name, "SyntaxError");
     do_check_eq(info, null);
     server.stop(run_next_test);
   });
 });
--- a/services/sync/tests/unit/test_syncstoragerequest.js
+++ b/services/sync/tests/unit/test_syncstoragerequest.js
@@ -52,34 +52,32 @@ add_test(function test_user_agent_mobile
     do_check_eq(error, null);
     do_check_eq(this.response.status, 200);
     do_check_eq(handler.request.getHeader("User-Agent"), expectedUA);
     Svc.Prefs.resetBranch("");
     server.stop(run_next_test);
   });
 });
 
-// XXX - DISABLED BECAUSE getStorageRequest broken with browserid_manager
-// add_test(function test_auth() {
-//   let handler = httpd_handler(200, "OK");
-//   let server = httpd_setup({"/resource": handler});
-
-//   configureIdentity();
+add_task(async function test_auth() {
+  let handler = httpd_handler(200, "OK");
+  let server = httpd_setup({"/resource": handler});
+  await configureIdentity({ username: "foo" }, server);
 
-//   let request = Service.getStorageRequest(server.baseURI + "/resource");
-//   request.get(function(error) {
-//     do_check_eq(error, null);
-//     do_check_eq(this.response.status, 200);
-//     do_check_true(has_hawk_header(handler.request));
+  let request = Service.getStorageRequest(server.baseURI + "/resource");
+  request.get(function(error) {
+    do_check_eq(error, null);
+    do_check_eq(this.response.status, 200);
+    do_check_true(has_hawk_header(handler.request));
 
-//     Svc.Prefs.reset("");
+    Svc.Prefs.reset("");
 
-//     server.stop(run_next_test);
-//   });
-// });
+    server.stop(run_next_test);
+  });
+});
 
 /**
  *  The X-Weave-Timestamp header updates SyncStorageRequest.serverTime.
  */
 add_test(function test_weave_timestamp() {
   const TIMESTAMP = 1274380461;
   function handler(request, response) {
     response.setHeader("X-Weave-Timestamp", "" + TIMESTAMP, false);
--- a/services/sync/tests/unit/xpcshell.ini
+++ b/services/sync/tests/unit/xpcshell.ini
@@ -69,18 +69,17 @@ skip-if = os == "android"
 [test_tracker_addChanged.js]
 
 # Service semantics.
 [test_service_attributes.js]
 # Bug 752243: Profile cleanup frequently fails
 skip-if = os == "mac" || os == "linux"
 [test_service_cluster.js]
 [test_service_detect_upgrade.js]
-# XXX - Disabled because getStorageInfo is broken
-# [test_service_getStorageInfo.js]
+[test_service_getStorageInfo.js]
 [test_service_login.js]
 [test_service_migratePrefs.js]
 [test_service_startOver.js]
 [test_service_startup.js]
 [test_service_sync_401.js]
 [test_service_sync_locked.js]
 [test_service_sync_remoteSetup.js]
 # Bug 676978: test hangs on Android (see also testing/xpcshell/xpcshell.ini)