diff --git a/services/sync/modules/rest.js b/services/sync/modules/rest.js index 94c096dba5b9..8579086a919e 100644 --- a/services/sync/modules/rest.js +++ b/services/sync/modules/rest.js @@ -39,7 +39,12 @@ SyncStorageRequest.prototype = { } 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."); } diff --git a/services/sync/tests/unit/test_service_getStorageInfo.js b/services/sync/tests/unit/test_service_getStorageInfo.js index 074ebea2c815..00f0fbb84d2f 100644 --- a/services/sync/tests/unit/test_service_getStorageInfo.js +++ b/services/sync/tests/unit/test_service_getStorageInfo.js @@ -19,25 +19,20 @@ function run_test() { 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 + "." + @@ -66,10 +61,10 @@ add_test(function test_network_error() { }); }); -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); @@ -78,10 +73,10 @@ add_test(function test_http_error() { }); }); -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"); diff --git a/services/sync/tests/unit/test_syncstoragerequest.js b/services/sync/tests/unit/test_syncstoragerequest.js index cdcfac257d64..427965e7b12e 100644 --- a/services/sync/tests/unit/test_syncstoragerequest.js +++ b/services/sync/tests/unit/test_syncstoragerequest.js @@ -57,24 +57,22 @@ add_test(function test_user_agent_mobile() { }); }); -// 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}); +add_task(async function test_auth() { + let handler = httpd_handler(200, "OK"); + let server = httpd_setup({"/resource": handler}); + await configureIdentity({ username: "foo" }, server); -// configureIdentity(); + 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. diff --git a/services/sync/tests/unit/xpcshell.ini b/services/sync/tests/unit/xpcshell.ini index b6f8f6bbf937..169a842178f5 100644 --- a/services/sync/tests/unit/xpcshell.ini +++ b/services/sync/tests/unit/xpcshell.ini @@ -74,8 +74,7 @@ skip-if = os == "android" 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]