2014-06-05 02:29:54 -07:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
2014-05-29 13:13:48 -07:00
|
|
|
|
|
|
|
// XXX should report error if Hawk-Session-Token is lexically invalid
|
|
|
|
// (not a string of 64 hex digits) to help resist other possible injection
|
|
|
|
// attacks. For now, however, we're just checking if it's the right length.
|
|
|
|
add_test(function test_registration_handles_bogus_hawk_token() {
|
|
|
|
|
|
|
|
var wrongSizeToken = "jdkasjkasjdlaksj";
|
|
|
|
Services.prefs.clearUserPref("loop.hawk-session-token");
|
|
|
|
|
2014-06-05 02:29:54 -07:00
|
|
|
loopServer.registerPathHandler("/registration", (request, response) => {
|
2014-05-29 13:13:48 -07:00
|
|
|
response.setStatusLine(null, 200, "OK");
|
|
|
|
response.setHeader("Hawk-Session-Token", wrongSizeToken, false);
|
|
|
|
response.processAsync();
|
|
|
|
response.finish();
|
|
|
|
});
|
|
|
|
|
2014-10-29 16:20:31 -07:00
|
|
|
MozLoopService.promiseRegisteredWithServers().then(() => {
|
2014-06-04 06:42:41 -07:00
|
|
|
do_throw("should not succeed with a bogus token");
|
|
|
|
}, err => {
|
2014-05-29 13:13:48 -07:00
|
|
|
|
2014-11-24 13:39:57 -08:00
|
|
|
Assert.equal(err.message, "session-token-wrong-size", "Should cause an error to be" +
|
2014-05-29 13:13:48 -07:00
|
|
|
" called back if the session-token is not 64 characters long");
|
|
|
|
|
|
|
|
// for some reason, Assert.throw is misbehaving, so....
|
|
|
|
var ex;
|
|
|
|
try {
|
|
|
|
Services.prefs.getCharPref("loop.hawk-session-token");
|
|
|
|
} catch (e) {
|
|
|
|
ex = e;
|
|
|
|
}
|
|
|
|
Assert.notEqual(ex, undefined, "Should not set a loop.hawk-session-token pref");
|
|
|
|
|
|
|
|
run_next_test();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-10-27 03:11:36 -07:00
|
|
|
function run_test() {
|
2014-06-05 02:29:54 -07:00
|
|
|
setupFakeLoopServer();
|
2014-05-29 13:13:48 -07:00
|
|
|
|
2014-11-05 13:58:52 -08:00
|
|
|
mockPushHandler.registrationPushURL = kEndPointUrl;
|
|
|
|
|
2014-05-29 13:13:48 -07:00
|
|
|
do_register_cleanup(function() {
|
|
|
|
Services.prefs.clearUserPref("loop.hawk-session-token");
|
|
|
|
});
|
|
|
|
|
|
|
|
run_next_test();
|
|
|
|
}
|