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 | Cu.import("resource://gre/modules/identity/IdentityProvider.jsm"); |
michael@0 | 7 | |
michael@0 | 8 | function check_provision_flow_done(provId) { |
michael@0 | 9 | do_check_null(IdentityProvider._provisionFlows[provId]); |
michael@0 | 10 | } |
michael@0 | 11 | |
michael@0 | 12 | function test_begin_provisioning() { |
michael@0 | 13 | do_test_pending(); |
michael@0 | 14 | |
michael@0 | 15 | setup_provisioning( |
michael@0 | 16 | TEST_USER, |
michael@0 | 17 | function(caller) { |
michael@0 | 18 | // call .beginProvisioning() |
michael@0 | 19 | IdentityProvider.beginProvisioning(caller); |
michael@0 | 20 | }, function() {}, |
michael@0 | 21 | { |
michael@0 | 22 | beginProvisioningCallback: function(email, duration_s) { |
michael@0 | 23 | do_check_eq(email, TEST_USER); |
michael@0 | 24 | do_check_true(duration_s > 0); |
michael@0 | 25 | do_check_true(duration_s <= (24 * 3600)); |
michael@0 | 26 | |
michael@0 | 27 | do_test_finished(); |
michael@0 | 28 | run_next_test(); |
michael@0 | 29 | } |
michael@0 | 30 | }); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function test_raise_provisioning_failure() { |
michael@0 | 34 | do_test_pending(); |
michael@0 | 35 | let _callerId = null; |
michael@0 | 36 | |
michael@0 | 37 | setup_provisioning( |
michael@0 | 38 | TEST_USER, |
michael@0 | 39 | function(caller) { |
michael@0 | 40 | // call .beginProvisioning() |
michael@0 | 41 | _callerId = caller.id; |
michael@0 | 42 | IdentityProvider.beginProvisioning(caller); |
michael@0 | 43 | }, function(err) { |
michael@0 | 44 | // this should be invoked with a populated error |
michael@0 | 45 | do_check_neq(err, null); |
michael@0 | 46 | do_check_true(err.indexOf("can't authenticate this email") > -1); |
michael@0 | 47 | |
michael@0 | 48 | do_test_finished(); |
michael@0 | 49 | run_next_test(); |
michael@0 | 50 | }, |
michael@0 | 51 | { |
michael@0 | 52 | beginProvisioningCallback: function(email, duration_s) { |
michael@0 | 53 | // raise the failure as if we can't provision this email |
michael@0 | 54 | IdentityProvider.raiseProvisioningFailure(_callerId, "can't authenticate this email"); |
michael@0 | 55 | } |
michael@0 | 56 | }); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function test_genkeypair_before_begin_provisioning() { |
michael@0 | 60 | do_test_pending(); |
michael@0 | 61 | |
michael@0 | 62 | setup_provisioning( |
michael@0 | 63 | TEST_USER, |
michael@0 | 64 | function(caller) { |
michael@0 | 65 | // call genKeyPair without beginProvisioning |
michael@0 | 66 | IdentityProvider.genKeyPair(caller.id); |
michael@0 | 67 | }, |
michael@0 | 68 | // expect this to be called with an error |
michael@0 | 69 | function(err) { |
michael@0 | 70 | do_check_neq(err, null); |
michael@0 | 71 | |
michael@0 | 72 | do_test_finished(); |
michael@0 | 73 | run_next_test(); |
michael@0 | 74 | }, |
michael@0 | 75 | { |
michael@0 | 76 | // this should not be called at all! |
michael@0 | 77 | genKeyPairCallback: function(pk) { |
michael@0 | 78 | // a test that will surely fail because we shouldn't be here. |
michael@0 | 79 | do_check_true(false); |
michael@0 | 80 | |
michael@0 | 81 | do_test_finished(); |
michael@0 | 82 | run_next_test(); |
michael@0 | 83 | } |
michael@0 | 84 | } |
michael@0 | 85 | ); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | function test_genkeypair() { |
michael@0 | 89 | do_test_pending(); |
michael@0 | 90 | let _callerId = null; |
michael@0 | 91 | |
michael@0 | 92 | setup_provisioning( |
michael@0 | 93 | TEST_USER, |
michael@0 | 94 | function(caller) { |
michael@0 | 95 | _callerId = caller.id; |
michael@0 | 96 | IdentityProvider.beginProvisioning(caller); |
michael@0 | 97 | }, |
michael@0 | 98 | function(err) { |
michael@0 | 99 | // should not be called! |
michael@0 | 100 | do_check_true(false); |
michael@0 | 101 | |
michael@0 | 102 | do_test_finished(); |
michael@0 | 103 | run_next_test(); |
michael@0 | 104 | }, |
michael@0 | 105 | { |
michael@0 | 106 | beginProvisioningCallback: function(email, time_s) { |
michael@0 | 107 | IdentityProvider.genKeyPair(_callerId); |
michael@0 | 108 | }, |
michael@0 | 109 | genKeyPairCallback: function(kp) { |
michael@0 | 110 | do_check_neq(kp, null); |
michael@0 | 111 | |
michael@0 | 112 | // yay! |
michael@0 | 113 | do_test_finished(); |
michael@0 | 114 | run_next_test(); |
michael@0 | 115 | } |
michael@0 | 116 | } |
michael@0 | 117 | ); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | // we've already ensured that genkeypair can't be called |
michael@0 | 121 | // before beginProvisioning, so this test should be enough |
michael@0 | 122 | // to ensure full sequential call of the 3 APIs. |
michael@0 | 123 | function test_register_certificate_before_genkeypair() { |
michael@0 | 124 | do_test_pending(); |
michael@0 | 125 | let _callerID = null; |
michael@0 | 126 | |
michael@0 | 127 | setup_provisioning( |
michael@0 | 128 | TEST_USER, |
michael@0 | 129 | function(caller) { |
michael@0 | 130 | // do the right thing for beginProvisioning |
michael@0 | 131 | _callerID = caller.id; |
michael@0 | 132 | IdentityProvider.beginProvisioning(caller); |
michael@0 | 133 | }, |
michael@0 | 134 | // expect this to be called with an error |
michael@0 | 135 | function(err) { |
michael@0 | 136 | do_check_neq(err, null); |
michael@0 | 137 | |
michael@0 | 138 | do_test_finished(); |
michael@0 | 139 | run_next_test(); |
michael@0 | 140 | }, |
michael@0 | 141 | { |
michael@0 | 142 | beginProvisioningCallback: function(email, duration_s) { |
michael@0 | 143 | // now we try to register cert but no keygen has been done |
michael@0 | 144 | IdentityProvider.registerCertificate(_callerID, "fake-cert"); |
michael@0 | 145 | } |
michael@0 | 146 | } |
michael@0 | 147 | ); |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | function test_register_certificate() { |
michael@0 | 151 | do_test_pending(); |
michael@0 | 152 | let _callerId = null; |
michael@0 | 153 | |
michael@0 | 154 | setup_provisioning( |
michael@0 | 155 | TEST_USER, |
michael@0 | 156 | function(caller) { |
michael@0 | 157 | _callerId = caller.id; |
michael@0 | 158 | IdentityProvider.beginProvisioning(caller); |
michael@0 | 159 | }, |
michael@0 | 160 | function(err) { |
michael@0 | 161 | // we should be cool! |
michael@0 | 162 | do_check_null(err); |
michael@0 | 163 | |
michael@0 | 164 | // check that the cert is there |
michael@0 | 165 | let identity = get_idstore().fetchIdentity(TEST_USER); |
michael@0 | 166 | do_check_neq(identity,null); |
michael@0 | 167 | do_check_eq(identity.cert, "fake-cert-42"); |
michael@0 | 168 | |
michael@0 | 169 | do_execute_soon(function check_done() { |
michael@0 | 170 | // cleanup will happen after the callback is called |
michael@0 | 171 | check_provision_flow_done(_callerId); |
michael@0 | 172 | |
michael@0 | 173 | do_test_finished(); |
michael@0 | 174 | run_next_test(); |
michael@0 | 175 | }); |
michael@0 | 176 | }, |
michael@0 | 177 | { |
michael@0 | 178 | beginProvisioningCallback: function(email, duration_s) { |
michael@0 | 179 | IdentityProvider.genKeyPair(_callerId); |
michael@0 | 180 | }, |
michael@0 | 181 | genKeyPairCallback: function(pk) { |
michael@0 | 182 | IdentityProvider.registerCertificate(_callerId, "fake-cert-42"); |
michael@0 | 183 | } |
michael@0 | 184 | } |
michael@0 | 185 | ); |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | |
michael@0 | 189 | function test_get_assertion_after_provision() { |
michael@0 | 190 | do_test_pending(); |
michael@0 | 191 | let _callerId = null; |
michael@0 | 192 | |
michael@0 | 193 | setup_provisioning( |
michael@0 | 194 | TEST_USER, |
michael@0 | 195 | function(caller) { |
michael@0 | 196 | _callerId = caller.id; |
michael@0 | 197 | IdentityProvider.beginProvisioning(caller); |
michael@0 | 198 | }, |
michael@0 | 199 | function(err) { |
michael@0 | 200 | // we should be cool! |
michael@0 | 201 | do_check_null(err); |
michael@0 | 202 | |
michael@0 | 203 | // check that the cert is there |
michael@0 | 204 | let identity = get_idstore().fetchIdentity(TEST_USER); |
michael@0 | 205 | do_check_neq(identity,null); |
michael@0 | 206 | do_check_eq(identity.cert, "fake-cert-42"); |
michael@0 | 207 | |
michael@0 | 208 | do_execute_soon(function check_done() { |
michael@0 | 209 | // cleanup will happen after the callback is called |
michael@0 | 210 | check_provision_flow_done(_callerId); |
michael@0 | 211 | |
michael@0 | 212 | do_test_finished(); |
michael@0 | 213 | run_next_test(); |
michael@0 | 214 | }); |
michael@0 | 215 | }, |
michael@0 | 216 | { |
michael@0 | 217 | beginProvisioningCallback: function(email, duration_s) { |
michael@0 | 218 | IdentityProvider.genKeyPair(_callerId); |
michael@0 | 219 | }, |
michael@0 | 220 | genKeyPairCallback: function(pk) { |
michael@0 | 221 | IdentityProvider.registerCertificate(_callerId, "fake-cert-42"); |
michael@0 | 222 | } |
michael@0 | 223 | } |
michael@0 | 224 | ); |
michael@0 | 225 | |
michael@0 | 226 | } |
michael@0 | 227 | |
michael@0 | 228 | let TESTS = []; |
michael@0 | 229 | |
michael@0 | 230 | TESTS.push(test_begin_provisioning); |
michael@0 | 231 | TESTS.push(test_raise_provisioning_failure); |
michael@0 | 232 | TESTS.push(test_genkeypair_before_begin_provisioning); |
michael@0 | 233 | TESTS.push(test_genkeypair); |
michael@0 | 234 | TESTS.push(test_register_certificate_before_genkeypair); |
michael@0 | 235 | TESTS.push(test_register_certificate); |
michael@0 | 236 | TESTS.push(test_get_assertion_after_provision); |
michael@0 | 237 | |
michael@0 | 238 | TESTS.forEach(add_test); |
michael@0 | 239 | |
michael@0 | 240 | function run_test() { |
michael@0 | 241 | run_next_test(); |
michael@0 | 242 | } |