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);
request[method](payloadObj, onComplete);
if (method == "post" || method == "put") {
request[method](payloadObj, onComplete);
} else {
request[method](onComplete);
}
return deferred.promise;
}

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

@ -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
);

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

@ -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;
});
},
}
});

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

@ -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() {

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

@ -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');