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, "RelyingParty",
7 "resource://gre/modules/identity/RelyingParty.jsm");
9 function resetState() {
10 get_idstore().reset();
11 RelyingParty.reset();
12 }
14 function test_watch_loggedin_ready() {
15 do_test_pending();
17 resetState();
19 let id = TEST_USER;
20 setup_test_identity(id, TEST_CERT, function() {
21 let store = get_idstore();
23 // set it up so we're supposed to be logged in to TEST_URL
24 store.setLoginState(TEST_URL, true, id);
25 RelyingParty.watch(mock_doc(id, TEST_URL, function(action, params) {
26 do_check_eq(action, 'ready');
27 do_check_eq(params, undefined);
29 do_test_finished();
30 run_next_test();
31 }));
32 });
33 }
35 function test_watch_loggedin_login() {
36 do_test_pending();
38 resetState();
40 let id = TEST_USER;
41 setup_test_identity(id, TEST_CERT, function() {
42 let store = get_idstore();
44 // set it up so we're supposed to be logged in to TEST_URL
45 store.setLoginState(TEST_URL, true, id);
47 // check for first a login() call, then a ready() call
48 RelyingParty.watch(mock_doc(null, TEST_URL, call_sequentially(
49 function(action, params) {
50 do_check_eq(action, 'login');
51 do_check_neq(params, null);
52 },
53 function(action, params) {
54 do_check_eq(action, 'ready');
55 do_check_null(params);
57 do_test_finished();
58 run_next_test();
59 }
60 )));
61 });
62 }
64 function test_watch_loggedin_logout() {
65 do_test_pending();
67 resetState();
69 let id = TEST_USER;
70 let other_id = "otherid@foo.com";
71 setup_test_identity(other_id, TEST_CERT, function() {
72 setup_test_identity(id, TEST_CERT, function() {
73 let store = get_idstore();
75 // set it up so we're supposed to be logged in to TEST_URL
76 // with id, not other_id
77 store.setLoginState(TEST_URL, true, id);
79 // this should cause a login with an assertion for id,
80 // not for other_id
81 RelyingParty.watch(mock_doc(other_id, TEST_URL, call_sequentially(
82 function(action, params) {
83 do_check_eq(action, 'login');
84 do_check_neq(params, null);
85 },
86 function(action, params) {
87 do_check_eq(action, 'ready');
88 do_check_null(params);
90 do_test_finished();
91 run_next_test();
92 }
93 )));
94 });
95 });
96 }
98 function test_watch_notloggedin_ready() {
99 do_test_pending();
101 resetState();
103 RelyingParty.watch(mock_doc(null, TEST_URL, function(action, params) {
104 do_check_eq(action, 'ready');
105 do_check_eq(params, undefined);
107 do_test_finished();
108 run_next_test();
109 }));
110 }
112 function test_watch_notloggedin_logout() {
113 do_test_pending();
115 resetState();
117 RelyingParty.watch(mock_doc(TEST_USER, TEST_URL, call_sequentially(
118 function(action, params) {
119 do_check_eq(action, 'logout');
120 do_check_eq(params, undefined);
122 let store = get_idstore();
123 do_check_null(store.getLoginState(TEST_URL));
124 },
125 function(action, params) {
126 do_check_eq(action, 'ready');
127 do_check_eq(params, undefined);
128 do_test_finished();
129 run_next_test();
130 }
131 )));
132 }
134 function test_request() {
135 do_test_pending();
137 // set up a watch, to be consistent
138 let mockedDoc = mock_doc(null, TEST_URL, function(action, params) {
139 // this isn't going to be called for now
140 // XXX but it is called - is that bad?
141 });
143 RelyingParty.watch(mockedDoc);
145 // be ready for the UX identity-request notification
146 makeObserver("identity-request", function (aSubject, aTopic, aData) {
147 do_check_neq(aSubject, null);
149 do_check_eq(aSubject.wrappedJSObject.rpId, mockedDoc.id);
151 do_test_finished();
152 run_next_test();
153 });
155 RelyingParty.request(mockedDoc.id, {});
156 }
158 /*
159 * ensure the forceAuthentication param can be passed through
160 */
161 function test_request_forceAuthentication() {
162 do_test_pending();
164 let mockedDoc = mock_doc(null, TEST_URL, function(action, params) {});
166 RelyingParty.watch(mockedDoc);
168 makeObserver("identity-request", function(aSubject, aTopic, aData) {
169 do_check_eq(aSubject.wrappedJSObject.rpId, mockedDoc.id);
170 do_check_eq(aSubject.wrappedJSObject.forceAuthentication, true);
171 do_test_finished();
172 run_next_test();
173 });
175 RelyingParty.request(mockedDoc.id, {forceAuthentication: true});
176 }
178 /*
179 * ensure the issuer can be forced
180 */
181 function test_request_forceIssuer() {
182 do_test_pending();
184 let mockedDoc = mock_doc(null, TEST_URL, function(action, params) {});
186 RelyingParty.watch(mockedDoc);
188 makeObserver("identity-request", function(aSubject, aTopic, aData) {
189 do_check_eq(aSubject.wrappedJSObject.rpId, mockedDoc.id);
190 do_check_eq(aSubject.wrappedJSObject.issuer, "https://ozten.co.uk");
191 do_test_finished();
192 run_next_test();
193 });
195 RelyingParty.request(mockedDoc.id, {issuer: "https://ozten.co.uk"});
196 }
197 function test_logout() {
198 do_test_pending();
200 resetState();
202 let id = TEST_USER;
203 setup_test_identity(id, TEST_CERT, function() {
204 let store = get_idstore();
206 // set it up so we're supposed to be logged in to TEST_URL
207 store.setLoginState(TEST_URL, true, id);
209 let doLogout;
210 let mockedDoc = mock_doc(id, TEST_URL, call_sequentially(
211 function(action, params) {
212 do_check_eq(action, 'ready');
213 do_check_eq(params, undefined);
215 do_timeout(100, doLogout);
216 },
217 function(action, params) {
218 do_check_eq(action, 'logout');
219 do_check_eq(params, undefined);
220 },
221 function(action, params) {
222 do_check_eq(action, 'ready');
223 do_check_eq(params, undefined);
225 do_test_finished();
226 run_next_test();
227 }));
229 doLogout = function() {
230 RelyingParty.logout(mockedDoc.id);
231 do_check_false(store.getLoginState(TEST_URL).isLoggedIn);
232 do_check_eq(store.getLoginState(TEST_URL).email, TEST_USER);
233 };
235 RelyingParty.watch(mockedDoc);
236 });
237 }
239 let TESTS = [
240 test_watch_loggedin_ready,
241 test_watch_loggedin_login,
242 test_watch_loggedin_logout,
243 test_watch_notloggedin_ready,
244 test_watch_notloggedin_logout,
245 test_request,
246 test_request_forceAuthentication,
247 test_request_forceIssuer,
248 test_logout,
249 ];
251 TESTS.forEach(add_test);
253 function run_test() {
254 run_next_test();
255 }