toolkit/identity/tests/unit/test_observer_topics.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * By their nature, these tests duplicate some of the functionality of
michael@0 6 * other tests for Identity, RelyingParty, and IdentityProvider.
michael@0 7 *
michael@0 8 * In particular, "identity-auth-complete" and
michael@0 9 * "identity-login-state-changed" are tested in test_authentication.js
michael@0 10 */
michael@0 11
michael@0 12 "use strict";
michael@0 13
michael@0 14 XPCOMUtils.defineLazyModuleGetter(this, "IDService",
michael@0 15 "resource://gre/modules/identity/Identity.jsm",
michael@0 16 "IdentityService");
michael@0 17
michael@0 18 function test_smoke() {
michael@0 19 do_check_neq(IDService, null);
michael@0 20 run_next_test();
michael@0 21 }
michael@0 22
michael@0 23 function test_identity_request() {
michael@0 24 // In response to navigator.id.request(), initiate a login with user
michael@0 25 // interaction by notifying observers of 'identity-request'
michael@0 26
michael@0 27 do_test_pending();
michael@0 28
michael@0 29 IDService.reset();
michael@0 30
michael@0 31 let id = "landru@mockmyid.com";
michael@0 32 setup_test_identity(id, TEST_CERT, function() {
michael@0 33 // deliberately adding a trailing final slash on the domain
michael@0 34 // to test path composition
michael@0 35 let mockedDoc = mock_doc(null, "http://jed.gov/", function() {});
michael@0 36
michael@0 37 // by calling watch() we create an rp flow.
michael@0 38 IDService.RP.watch(mockedDoc);
michael@0 39
michael@0 40 // register the request UX observer
michael@0 41 makeObserver("identity-request", function (aSubject, aTopic, aData) {
michael@0 42 do_check_eq(aTopic, "identity-request");
michael@0 43 do_check_eq(aData, null);
michael@0 44
michael@0 45 // check that all the URLs are properly resolved
michael@0 46 let subj = aSubject.wrappedJSObject;
michael@0 47 do_check_eq(subj.privacyPolicy, "http://jed.gov/pp.html");
michael@0 48 do_check_eq(subj.termsOfService, "http://jed.gov/tos.html");
michael@0 49
michael@0 50 do_test_finished();
michael@0 51 run_next_test();
michael@0 52 });
michael@0 53
michael@0 54 let requestOptions = {
michael@0 55 privacyPolicy: "/pp.html",
michael@0 56 termsOfService: "/tos.html"
michael@0 57 };
michael@0 58 IDService.RP.request(mockedDoc.id, requestOptions);
michael@0 59 });
michael@0 60
michael@0 61 }
michael@0 62
michael@0 63 function test_identity_auth() {
michael@0 64 // see test_authentication.js for "identity-auth-complete"
michael@0 65 // and "identity-login-state-changed"
michael@0 66
michael@0 67 do_test_pending();
michael@0 68 let _provId = "bogus";
michael@0 69
michael@0 70 // Simulate what would be returned by IDService._fetchWellKnownFile
michael@0 71 // for a given domain.
michael@0 72 let idpParams = {
michael@0 73 domain: "myfavoriteflan.com",
michael@0 74 idpParams: {
michael@0 75 authentication: "/foo/authenticate.html",
michael@0 76 provisioning: "/foo/provision.html"
michael@0 77 }
michael@0 78 };
michael@0 79
michael@0 80 // Create an RP flow
michael@0 81 let mockedDoc = mock_doc(null, TEST_URL, function(action, params) {});
michael@0 82 IDService.RP.watch(mockedDoc);
michael@0 83
michael@0 84 // The identity-auth notification is sent up to the UX from the
michael@0 85 // _doAuthentication function. Be ready to receive it and call
michael@0 86 // beginAuthentication
michael@0 87 makeObserver("identity-auth", function (aSubject, aTopic, aData) {
michael@0 88 do_check_neq(aSubject, null);
michael@0 89 do_check_eq(aTopic, "identity-auth");
michael@0 90 do_check_eq(aData, "https://myfavoriteflan.com/foo/authenticate.html");
michael@0 91
michael@0 92 do_check_eq(aSubject.wrappedJSObject.provId, _provId);
michael@0 93 do_test_finished();
michael@0 94 run_next_test();
michael@0 95 });
michael@0 96
michael@0 97 // Even though our provisioning flow id is bogus, IdentityProvider
michael@0 98 // won't look at it until farther along in the authentication
michael@0 99 // process. So this test can pass with a fake provId.
michael@0 100 IDService.IDP._doAuthentication(_provId, idpParams);
michael@0 101 }
michael@0 102
michael@0 103 let TESTS = [
michael@0 104 test_smoke,
michael@0 105 test_identity_request,
michael@0 106 test_identity_auth,
michael@0 107 ];
michael@0 108
michael@0 109
michael@0 110 TESTS.forEach(add_test);
michael@0 111
michael@0 112 function run_test() {
michael@0 113 run_next_test();
michael@0 114 }

mercurial