Bug 927457 - processTokenResponse fails to handle 401 response correctly. r=gps

This commit is contained in:
Mark Hammond 2013-10-16 11:32:36 -07:00
parent 42002b918e
commit e883ceb840
2 changed files with 26 additions and 1 deletions

View File

@ -331,6 +331,31 @@ add_test(function test_400_response() {
});
});
add_test(function test_401_response() {
_("Ensure HTTP 401 is converted to invalid-credentials.");
let server = httpd_setup({
"/1.0/foo/1.0": function(request, response) {
response.setStatusLine(request.httpVersion, 401, "Unauthorized");
response.setHeader("Content-Type", "application/json; charset=utf-8");
let body = "{}"; // Actual content may not be used.
response.bodyOutputStream.write(body, body.length);
}
});
let client = new TokenServerClient();
let url = server.baseURI + "/1.0/foo/1.0";
client.getTokenFromBrowserIDAssertion(url, "assertion", function(error, r) {
do_check_neq(null, error);
do_check_eq("TokenServerClientServerError", error.name);
do_check_neq(null, error.response);
do_check_eq(error.cause, "invalid-credentials");
server.stop(run_next_test);
});
});
add_test(function test_unhandled_media_type() {
_("Ensure that unhandled media types throw an error.");

View File

@ -326,7 +326,7 @@ TokenServerClient.prototype = {
error.message = "Malformed request.";
error.cause = "malformed-request";
} else if (response.status == 401) {
error.message("Authentication failed.");
error.message = "Authentication failed.";
error.cause = "invalid-credentials";
}