michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * By their nature, these tests duplicate some of the functionality of michael@0: * other tests for Identity, RelyingParty, and IdentityProvider. michael@0: * michael@0: * In particular, "identity-auth-complete" and michael@0: * "identity-login-state-changed" are tested in test_authentication.js michael@0: */ michael@0: michael@0: "use strict"; michael@0: michael@0: XPCOMUtils.defineLazyModuleGetter(this, "IDService", michael@0: "resource://gre/modules/identity/Identity.jsm", michael@0: "IdentityService"); michael@0: michael@0: function test_smoke() { michael@0: do_check_neq(IDService, null); michael@0: run_next_test(); michael@0: } michael@0: michael@0: function test_identity_request() { michael@0: // In response to navigator.id.request(), initiate a login with user michael@0: // interaction by notifying observers of 'identity-request' michael@0: michael@0: do_test_pending(); michael@0: michael@0: IDService.reset(); michael@0: michael@0: let id = "landru@mockmyid.com"; michael@0: setup_test_identity(id, TEST_CERT, function() { michael@0: // deliberately adding a trailing final slash on the domain michael@0: // to test path composition michael@0: let mockedDoc = mock_doc(null, "http://jed.gov/", function() {}); michael@0: michael@0: // by calling watch() we create an rp flow. michael@0: IDService.RP.watch(mockedDoc); michael@0: michael@0: // register the request UX observer michael@0: makeObserver("identity-request", function (aSubject, aTopic, aData) { michael@0: do_check_eq(aTopic, "identity-request"); michael@0: do_check_eq(aData, null); michael@0: michael@0: // check that all the URLs are properly resolved michael@0: let subj = aSubject.wrappedJSObject; michael@0: do_check_eq(subj.privacyPolicy, "http://jed.gov/pp.html"); michael@0: do_check_eq(subj.termsOfService, "http://jed.gov/tos.html"); michael@0: michael@0: do_test_finished(); michael@0: run_next_test(); michael@0: }); michael@0: michael@0: let requestOptions = { michael@0: privacyPolicy: "/pp.html", michael@0: termsOfService: "/tos.html" michael@0: }; michael@0: IDService.RP.request(mockedDoc.id, requestOptions); michael@0: }); michael@0: michael@0: } michael@0: michael@0: function test_identity_auth() { michael@0: // see test_authentication.js for "identity-auth-complete" michael@0: // and "identity-login-state-changed" michael@0: michael@0: do_test_pending(); michael@0: let _provId = "bogus"; michael@0: michael@0: // Simulate what would be returned by IDService._fetchWellKnownFile michael@0: // for a given domain. michael@0: let idpParams = { michael@0: domain: "myfavoriteflan.com", michael@0: idpParams: { michael@0: authentication: "/foo/authenticate.html", michael@0: provisioning: "/foo/provision.html" michael@0: } michael@0: }; michael@0: michael@0: // Create an RP flow michael@0: let mockedDoc = mock_doc(null, TEST_URL, function(action, params) {}); michael@0: IDService.RP.watch(mockedDoc); michael@0: michael@0: // The identity-auth notification is sent up to the UX from the michael@0: // _doAuthentication function. Be ready to receive it and call michael@0: // beginAuthentication michael@0: makeObserver("identity-auth", function (aSubject, aTopic, aData) { michael@0: do_check_neq(aSubject, null); michael@0: do_check_eq(aTopic, "identity-auth"); michael@0: do_check_eq(aData, "https://myfavoriteflan.com/foo/authenticate.html"); michael@0: michael@0: do_check_eq(aSubject.wrappedJSObject.provId, _provId); michael@0: do_test_finished(); michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // Even though our provisioning flow id is bogus, IdentityProvider michael@0: // won't look at it until farther along in the authentication michael@0: // process. So this test can pass with a fake provId. michael@0: IDService.IDP._doAuthentication(_provId, idpParams); michael@0: } michael@0: michael@0: let TESTS = [ michael@0: test_smoke, michael@0: test_identity_request, michael@0: test_identity_auth, michael@0: ]; michael@0: michael@0: michael@0: TESTS.forEach(add_test); michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: }