diff --git a/services/common/hawk.js b/services/common/hawk.js index 3843554e3e8..a13298d1652 100644 --- a/services/common/hawk.js +++ b/services/common/hawk.js @@ -194,7 +194,11 @@ HawkClient.prototype = { }; let request = new HAWKAuthenticatedRESTRequest(uri, credentials, extra); - request[method](payloadObj, onComplete); + if (method == "post" || method == "put") { + request[method](payloadObj, onComplete); + } else { + request[method](onComplete); + } return deferred.promise; } diff --git a/services/common/rest.js b/services/common/rest.js index f53bdfff503..310fa77b3d4 100644 --- a/services/common/rest.js +++ b/services/common/rest.js @@ -763,19 +763,25 @@ HAWKAuthenticatedRESTRequest.prototype = { __proto__: RESTRequest.prototype, dispatch: function dispatch(method, data, onComplete, onProgress) { + let contentType = "text/plain"; + if (method == "POST" || method == "PUT") { + contentType = "application/json"; + } if (this.credentials) { let options = { now: this.now, localtimeOffsetMsec: this.localtimeOffsetMsec, credentials: this.credentials, payload: data && JSON.stringify(data) || "", - contentType: "application/json; charset=utf-8", + contentType: contentType, }; let header = CryptoUtils.computeHAWK(this.uri, method, options); this.setHeader("Authorization", header.field); this._log.trace("hawk auth header: " + header.field); } + this.setHeader("Content-Type", contentType); + return RESTRequest.prototype.dispatch.call( this, method, data, onComplete, onProgress ); diff --git a/services/fxaccounts/FxAccounts.jsm b/services/fxaccounts/FxAccounts.jsm index 23d20394e5d..56bd86b2bab 100644 --- a/services/fxaccounts/FxAccounts.jsm +++ b/services/fxaccounts/FxAccounts.jsm @@ -385,15 +385,6 @@ InternalMethods.prototype = { Services.obs.notifyObservers(null, topic, null); }, - /** - * Give xpcshell tests an override point for duration testing. This is - * necessary because the tests need to manipulate the date in order to - * simulate certificate expiration. - */ - now: function() { - return Date.now(); - }, - pollEmailStatus: function pollEmailStatus(sessionToken, why) { let myGenerationCount = this.generationCount; log.debug("entering pollEmailStatus: " + why + " " + myGenerationCount); @@ -489,6 +480,20 @@ this.FxAccounts = function(mockInternal) { this.FxAccounts.prototype = Object.freeze({ version: DATA_FORMAT_VERSION, + now: function() { + if (this.internal) { + return this.internal.now(); + } + return internal.now(); + }, + + get localtimeOffsetMsec() { + if (this.internal) { + return this.internal.localtimeOffsetMsec; + } + return internal.localtimeOffsetMsec; + }, + // set() makes sure that polling is happening, if necessary. // get() does not wait for verification, and returns an object even if // unverified. The caller of get() must check .verified . @@ -620,7 +625,6 @@ this.FxAccounts.prototype = Object.freeze({ return internal.whenVerified(userData); }, - /** * Sign the current user out. * @@ -656,7 +660,7 @@ this.FxAccounts.prototype = Object.freeze({ newQueryPortion += "email=" + encodeURIComponent(accountData.email); return url + newQueryPortion; }); - }, + } }); diff --git a/services/sync/modules/browserid_identity.js b/services/sync/modules/browserid_identity.js index 9b370268e32..8e1d38158ab 100644 --- a/services/sync/modules/browserid_identity.js +++ b/services/sync/modules/browserid_identity.js @@ -211,11 +211,11 @@ this.BrowserIDManager.prototype = { * Provide override point for testing token expiration. */ _now: function() { - return this._fxaService.internal.now() + return this._fxaService.now() }, get _localtimeOffsetMsec() { - return this._fxaService.internal.localtimeOffsetMsec; + return this._fxaService.localtimeOffsetMsec; }, get account() { diff --git a/services/sync/tests/unit/test_browserid_identity.js b/services/sync/tests/unit/test_browserid_identity.js index acecf385204..66eeda175e1 100644 --- a/services/sync/tests/unit/test_browserid_identity.js +++ b/services/sync/tests/unit/test_browserid_identity.js @@ -136,13 +136,21 @@ add_test(function test_resourceAuthenticatorSkew() { do_check_eq(fxa.internal.now(), now); do_check_eq(fxa.internal.localtimeOffsetMsec, localtimeOffsetMsec); + do_check_eq(fxa.now(), now); + do_check_eq(fxa.localtimeOffsetMsec, localtimeOffsetMsec); + // Mocks within mocks... configureFxAccountIdentity(browseridManager, identityConfig); browseridManager._fxaService = fxa; + do_check_eq(browseridManager._fxaService.internal.now(), now); do_check_eq(browseridManager._fxaService.internal.localtimeOffsetMsec, localtimeOffsetMsec); + do_check_eq(browseridManager._fxaService.now(), now); + do_check_eq(browseridManager._fxaService.localtimeOffsetMsec, + localtimeOffsetMsec); + let request = new SyncStorageRequest("https://example.net/i/like/pie/"); let authenticator = browseridManager.getResourceAuthenticator(); let output = authenticator(request, 'GET');