Sat, 03 Jan 2015 20:18:00 +0100
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.
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 XPCOMUtils.defineLazyModuleGetter(this, "IDService",
7 "resource://gre/modules/identity/Identity.jsm",
8 "IdentityService");
10 XPCOMUtils.defineLazyModuleGetter(this, "jwcrypto",
11 "resource://gre/modules/identity/jwcrypto.jsm");
13 function test_begin_authentication_flow() {
14 do_test_pending();
15 let _provId = null;
17 // set up a watch, to be consistent
18 let mockedDoc = mock_doc(null, TEST_URL, function(action, params) {});
19 IDService.RP.watch(mockedDoc);
21 // The identity-auth notification is sent up to the UX from the
22 // _doAuthentication function. Be ready to receive it and call
23 // beginAuthentication
24 makeObserver("identity-auth", function (aSubject, aTopic, aData) {
25 do_check_neq(aSubject, null);
27 do_check_eq(aSubject.wrappedJSObject.provId, _provId);
29 do_test_finished();
30 run_next_test();
31 });
33 setup_provisioning(
34 TEST_USER,
35 function(caller) {
36 _provId = caller.id;
37 IDService.IDP.beginProvisioning(caller);
38 }, function() {},
39 {
40 beginProvisioningCallback: function(email, duration_s) {
42 // let's say this user needs to authenticate
43 IDService.IDP._doAuthentication(_provId, {idpParams:TEST_IDPPARAMS});
44 }
45 }
46 );
47 }
49 function test_complete_authentication_flow() {
50 do_test_pending();
51 let _provId = null;
52 let _authId = null;
53 let id = TEST_USER;
55 let callbacksFired = false;
56 let loginStateChanged = false;
57 let identityAuthComplete = false;
59 // The result of authentication should be a successful login
60 IDService.reset();
62 setup_test_identity(id, TEST_CERT, function() {
63 // set it up so we're supposed to be logged in to TEST_URL
65 get_idstore().setLoginState(TEST_URL, true, id);
67 // When we authenticate, our ready callback will be fired.
68 // At the same time, a separate topic will be sent up to the
69 // the observer in the UI. The test is complete when both
70 // events have occurred.
71 let mockedDoc = mock_doc(id, TEST_URL, call_sequentially(
72 function(action, params) {
73 do_check_eq(action, 'ready');
74 do_check_eq(params, undefined);
76 // if notification already received by observer, test is done
77 callbacksFired = true;
78 if (loginStateChanged && identityAuthComplete) {
79 do_test_finished();
80 run_next_test();
81 }
82 }
83 ));
85 makeObserver("identity-auth-complete", function(aSubject, aTopic, aData) {
86 identityAuthComplete = true;
87 do_test_finished();
88 run_next_test();
89 });
91 makeObserver("identity-login-state-changed", function (aSubject, aTopic, aData) {
92 do_check_neq(aSubject, null);
94 do_check_eq(aSubject.wrappedJSObject.rpId, mockedDoc.id);
95 do_check_eq(aData, id);
97 // if callbacks in caller doc already fired, test is done.
98 loginStateChanged = true;
99 if (callbacksFired && identityAuthComplete) {
100 do_test_finished();
101 run_next_test();
102 }
103 });
105 IDService.RP.watch(mockedDoc);
107 // Create a provisioning flow for our auth flow to attach to
108 setup_provisioning(
109 TEST_USER,
110 function(provFlow) {
111 _provId = provFlow.id;
113 IDService.IDP.beginProvisioning(provFlow);
114 }, function() {},
115 {
116 beginProvisioningCallback: function(email, duration_s) {
117 // let's say this user needs to authenticate
118 IDService.IDP._doAuthentication(_provId, {idpParams:TEST_IDPPARAMS});
120 // test_begin_authentication_flow verifies that the right
121 // message is sent to the UI. So that works. Moving on,
122 // the UI calls setAuthenticationFlow ...
123 _authId = uuid();
124 IDService.IDP.setAuthenticationFlow(_authId, _provId);
126 // ... then the UI calls beginAuthentication ...
127 authCaller.id = _authId;
128 IDService.IDP._provisionFlows[_provId].caller = authCaller;
129 IDService.IDP.beginAuthentication(authCaller);
130 }
131 }
132 );
133 });
135 // A mock calling context
136 let authCaller = {
137 doBeginAuthenticationCallback: function doBeginAuthenticationCallback(identity) {
138 do_check_eq(identity, TEST_USER);
139 // completeAuthentication will emit "identity-auth-complete"
140 IDService.IDP.completeAuthentication(_authId);
141 },
143 doError: function(err) {
144 log("OW! My doError callback hurts!", err);
145 },
146 };
148 }
150 let TESTS = [];
152 TESTS.push(test_begin_authentication_flow);
153 TESTS.push(test_complete_authentication_flow);
155 TESTS.forEach(add_test);
157 function run_test() {
158 run_next_test();
159 }