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