michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: XPCOMUtils.defineLazyModuleGetter(this, "IDService", michael@0: "resource://gre/modules/identity/Identity.jsm", michael@0: "IdentityService"); michael@0: michael@0: const WELL_KNOWN_PATH = "/.well-known/browserid"; michael@0: michael@0: let SERVER_PORT = 8080; michael@0: michael@0: // valid IDP michael@0: function test_well_known_1() { michael@0: do_test_pending(); michael@0: michael@0: let server = new HttpServer(); michael@0: server.registerFile(WELL_KNOWN_PATH, do_get_file("data/idp_1" + WELL_KNOWN_PATH)); michael@0: server.start(SERVER_PORT); michael@0: let hostPort = "localhost:" + SERVER_PORT; michael@0: michael@0: function check_well_known(aErr, aCallbackObj) { michael@0: do_check_null(aErr); michael@0: do_check_eq(aCallbackObj.domain, hostPort); michael@0: let idpParams = aCallbackObj.idpParams; michael@0: do_check_eq(idpParams['public-key'].algorithm, "RS"); michael@0: do_check_eq(idpParams.authentication, "/browserid/sign_in.html"); michael@0: do_check_eq(idpParams.provisioning, "/browserid/provision.html"); michael@0: michael@0: do_test_finished(); michael@0: server.stop(run_next_test); michael@0: } michael@0: michael@0: IDService._fetchWellKnownFile(hostPort, check_well_known, "http"); michael@0: } michael@0: michael@0: // valid domain, non-exixtent browserid file michael@0: function test_well_known_404() { michael@0: do_test_pending(); michael@0: michael@0: let server = new HttpServer(); michael@0: // Don't register the well-known file michael@0: // Change ports to avoid HTTP caching michael@0: SERVER_PORT++; michael@0: server.start(SERVER_PORT); michael@0: michael@0: let hostPort = "localhost:" + SERVER_PORT; michael@0: michael@0: function check_well_known_404(aErr, aCallbackObj) { michael@0: do_check_eq("Error", aErr); michael@0: do_check_eq(undefined, aCallbackObj); michael@0: do_test_finished(); michael@0: server.stop(run_next_test); michael@0: } michael@0: michael@0: IDService._fetchWellKnownFile(hostPort, check_well_known_404, "http"); michael@0: } michael@0: michael@0: // valid domain, invalid browserid file (no "provisioning" member) michael@0: function test_well_known_invalid_1() { michael@0: do_test_pending(); michael@0: michael@0: let server = new HttpServer(); michael@0: server.registerFile(WELL_KNOWN_PATH, do_get_file("data/idp_invalid_1" + WELL_KNOWN_PATH)); michael@0: // Change ports to avoid HTTP caching michael@0: SERVER_PORT++; michael@0: server.start(SERVER_PORT); michael@0: michael@0: let hostPort = "localhost:" + SERVER_PORT; michael@0: michael@0: function check_well_known_invalid_1(aErr, aCallbackObj) { michael@0: // check for an error message michael@0: do_check_true(aErr && aErr.length > 0); michael@0: do_check_eq(undefined, aCallbackObj); michael@0: do_test_finished(); michael@0: server.stop(run_next_test); michael@0: } michael@0: michael@0: IDService._fetchWellKnownFile(hostPort, check_well_known_invalid_1, "http"); michael@0: } michael@0: michael@0: let TESTS = [test_well_known_1, test_well_known_404, test_well_known_invalid_1]; michael@0: michael@0: TESTS.forEach(add_test); michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: }