Bug 966560 - fix bugs with time skew fix in bug 957863; r=jedp

This commit is contained in:
Chris Karlof 2014-01-31 16:43:36 -08:00
Родитель ec298b04a6
Коммит a7ca3ed75d
5 изменённых файлов: 37 добавлений и 15 удалений

Просмотреть файл

@ -194,7 +194,11 @@ HawkClient.prototype = {
}; };
let request = new HAWKAuthenticatedRESTRequest(uri, credentials, extra); 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; return deferred.promise;
} }

Просмотреть файл

@ -763,19 +763,25 @@ HAWKAuthenticatedRESTRequest.prototype = {
__proto__: RESTRequest.prototype, __proto__: RESTRequest.prototype,
dispatch: function dispatch(method, data, onComplete, onProgress) { dispatch: function dispatch(method, data, onComplete, onProgress) {
let contentType = "text/plain";
if (method == "POST" || method == "PUT") {
contentType = "application/json";
}
if (this.credentials) { if (this.credentials) {
let options = { let options = {
now: this.now, now: this.now,
localtimeOffsetMsec: this.localtimeOffsetMsec, localtimeOffsetMsec: this.localtimeOffsetMsec,
credentials: this.credentials, credentials: this.credentials,
payload: data && JSON.stringify(data) || "", payload: data && JSON.stringify(data) || "",
contentType: "application/json; charset=utf-8", contentType: contentType,
}; };
let header = CryptoUtils.computeHAWK(this.uri, method, options); let header = CryptoUtils.computeHAWK(this.uri, method, options);
this.setHeader("Authorization", header.field); this.setHeader("Authorization", header.field);
this._log.trace("hawk auth header: " + header.field); this._log.trace("hawk auth header: " + header.field);
} }
this.setHeader("Content-Type", contentType);
return RESTRequest.prototype.dispatch.call( return RESTRequest.prototype.dispatch.call(
this, method, data, onComplete, onProgress this, method, data, onComplete, onProgress
); );

Просмотреть файл

@ -385,15 +385,6 @@ InternalMethods.prototype = {
Services.obs.notifyObservers(null, topic, null); 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) { pollEmailStatus: function pollEmailStatus(sessionToken, why) {
let myGenerationCount = this.generationCount; let myGenerationCount = this.generationCount;
log.debug("entering pollEmailStatus: " + why + " " + myGenerationCount); log.debug("entering pollEmailStatus: " + why + " " + myGenerationCount);
@ -489,6 +480,20 @@ this.FxAccounts = function(mockInternal) {
this.FxAccounts.prototype = Object.freeze({ this.FxAccounts.prototype = Object.freeze({
version: DATA_FORMAT_VERSION, 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. // set() makes sure that polling is happening, if necessary.
// get() does not wait for verification, and returns an object even if // get() does not wait for verification, and returns an object even if
// unverified. The caller of get() must check .verified . // unverified. The caller of get() must check .verified .
@ -620,7 +625,6 @@ this.FxAccounts.prototype = Object.freeze({
return internal.whenVerified(userData); return internal.whenVerified(userData);
}, },
/** /**
* Sign the current user out. * Sign the current user out.
* *
@ -656,7 +660,7 @@ this.FxAccounts.prototype = Object.freeze({
newQueryPortion += "email=" + encodeURIComponent(accountData.email); newQueryPortion += "email=" + encodeURIComponent(accountData.email);
return url + newQueryPortion; return url + newQueryPortion;
}); });
}, }
}); });

Просмотреть файл

@ -211,11 +211,11 @@ this.BrowserIDManager.prototype = {
* Provide override point for testing token expiration. * Provide override point for testing token expiration.
*/ */
_now: function() { _now: function() {
return this._fxaService.internal.now() return this._fxaService.now()
}, },
get _localtimeOffsetMsec() { get _localtimeOffsetMsec() {
return this._fxaService.internal.localtimeOffsetMsec; return this._fxaService.localtimeOffsetMsec;
}, },
get account() { get account() {

Просмотреть файл

@ -136,13 +136,21 @@ add_test(function test_resourceAuthenticatorSkew() {
do_check_eq(fxa.internal.now(), now); do_check_eq(fxa.internal.now(), now);
do_check_eq(fxa.internal.localtimeOffsetMsec, localtimeOffsetMsec); do_check_eq(fxa.internal.localtimeOffsetMsec, localtimeOffsetMsec);
do_check_eq(fxa.now(), now);
do_check_eq(fxa.localtimeOffsetMsec, localtimeOffsetMsec);
// Mocks within mocks... // Mocks within mocks...
configureFxAccountIdentity(browseridManager, identityConfig); configureFxAccountIdentity(browseridManager, identityConfig);
browseridManager._fxaService = fxa; browseridManager._fxaService = fxa;
do_check_eq(browseridManager._fxaService.internal.now(), now); do_check_eq(browseridManager._fxaService.internal.now(), now);
do_check_eq(browseridManager._fxaService.internal.localtimeOffsetMsec, do_check_eq(browseridManager._fxaService.internal.localtimeOffsetMsec,
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 request = new SyncStorageRequest("https://example.net/i/like/pie/");
let authenticator = browseridManager.getResourceAuthenticator(); let authenticator = browseridManager.getResourceAuthenticator();
let output = authenticator(request, 'GET'); let output = authenticator(request, 'GET');