mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1038699 - Loop no longer resets the hawk session token when it is invalid. Handle the new server responses. r=dmose
This commit is contained in:
parent
309f493f83
commit
bd9115a8db
@ -6,6 +6,10 @@
|
||||
|
||||
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
// Invalid auth token as per
|
||||
// https://github.com/mozilla-services/loop-server/blob/45787d34108e2f0d87d74d4ddf4ff0dbab23501c/loop/errno.json#L6
|
||||
const INVALID_AUTH_TOKEN = 110;
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Promise.jsm");
|
||||
@ -245,7 +249,9 @@ let MozLoopServiceInternal = {
|
||||
// No need to clear the promise here, everything was good, so we don't need
|
||||
// to re-register.
|
||||
}, (error) => {
|
||||
if (error.errno == 401) {
|
||||
// There's other errors than invalid auth token, but we should only do the reset
|
||||
// as a last resort.
|
||||
if (error.code === 401 && error.errno === INVALID_AUTH_TOKEN) {
|
||||
if (this.urlExpiryTimeIsInFuture()) {
|
||||
// XXX Should this be reported to the user is a visible manner?
|
||||
Cu.reportError("Loop session token is invalid, all previously "
|
||||
|
@ -0,0 +1,58 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
const LOOP_HAWK_PREF = "loop.hawk-session-token";
|
||||
const fakeSessionToken1 = "1bad3e44b12f77a88fe09f016f6a37c42e40f974bc7a8b432bb0d2f0e37e1751";
|
||||
const fakeSessionToken2 = "1bad3e44b12f77a88fe09f016f6a37c42e40f974bc7a8b432bb0d2f0e37e1750";
|
||||
|
||||
add_test(function test_registration_invalid_token() {
|
||||
Services.prefs.setCharPref(LOOP_HAWK_PREF, fakeSessionToken1);
|
||||
var authorizationAttempts = 0;
|
||||
|
||||
loopServer.registerPathHandler("/registration", (request, response) => {
|
||||
// Due to the way the time stamp checking code works in hawkclient, we expect a couple
|
||||
// of authorization requests before we reset the token.
|
||||
if (request.hasHeader("Authorization")) {
|
||||
authorizationAttempts++;
|
||||
response.setStatusLine(null, 401, "Unauthorized");
|
||||
response.write(JSON.stringify({
|
||||
code: 401,
|
||||
errno: 110,
|
||||
error: {
|
||||
error: "Unauthorized",
|
||||
message: "Unknown credentials",
|
||||
statusCode: 401
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
// We didn't have an authorization header, so check the pref has been cleared.
|
||||
Assert.equal(Services.prefs.prefHasUserValue(LOOP_HAWK_PREF), false);
|
||||
response.setStatusLine(null, 200, "OK");
|
||||
response.setHeader("Hawk-Session-Token", fakeSessionToken2, false);
|
||||
}
|
||||
response.processAsync();
|
||||
response.finish();
|
||||
});
|
||||
|
||||
MozLoopService.register(mockPushHandler).then(() => {
|
||||
// Due to the way the time stamp checking code works in hawkclient, we expect a couple
|
||||
// of authorization requests before we reset the token.
|
||||
Assert.equal(authorizationAttempts, 2);
|
||||
Assert.equal(Services.prefs.getCharPref(LOOP_HAWK_PREF), fakeSessionToken2);
|
||||
run_next_test();
|
||||
}, err => {
|
||||
do_throw("shouldn't be a failure result: " + err);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
function run_test()
|
||||
{
|
||||
setupFakeLoopServer();
|
||||
|
||||
do_register_cleanup(function() {
|
||||
Services.prefs.clearUserPref("loop.hawk-session-token");
|
||||
});
|
||||
|
||||
run_next_test();
|
||||
}
|
@ -11,6 +11,7 @@ firefox-appdir = browser
|
||||
[test_loopservice_initialize.js]
|
||||
[test_loopservice_locales.js]
|
||||
[test_loopservice_registration.js]
|
||||
[test_loopservice_token_invalid.js]
|
||||
[test_loopservice_token_save.js]
|
||||
[test_loopservice_token_send.js]
|
||||
[test_loopservice_token_validation.js]
|
||||
|
Loading…
Reference in New Issue
Block a user