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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | 'use strict'; |
michael@0 | 5 | |
michael@0 | 6 | const { store, search, remove } = require("sdk/passwords"); |
michael@0 | 7 | |
michael@0 | 8 | exports["test store requires `password` field"] = function(assert, done) { |
michael@0 | 9 | store({ |
michael@0 | 10 | username: "foo", |
michael@0 | 11 | realm: "bar", |
michael@0 | 12 | onComplete: function onComplete() { |
michael@0 | 13 | assert.fail("onComplete should not be called"); |
michael@0 | 14 | }, |
michael@0 | 15 | onError: function onError() { |
michael@0 | 16 | assert.pass("'`password` is required"); |
michael@0 | 17 | done(); |
michael@0 | 18 | } |
michael@0 | 19 | }); |
michael@0 | 20 | }; |
michael@0 | 21 | |
michael@0 | 22 | exports["test store requires `username` field"] = function(assert, done) { |
michael@0 | 23 | store({ |
michael@0 | 24 | password: "foo", |
michael@0 | 25 | realm: "bar", |
michael@0 | 26 | onComplete: function onComplete() { |
michael@0 | 27 | assert.fail("onComplete should not be called"); |
michael@0 | 28 | }, |
michael@0 | 29 | onError: function onError() { |
michael@0 | 30 | assert.pass("'`username` is required"); |
michael@0 | 31 | done(); |
michael@0 | 32 | } |
michael@0 | 33 | }); |
michael@0 | 34 | }; |
michael@0 | 35 | |
michael@0 | 36 | exports["test onComplete is optional"] = function(assert, done) { |
michael@0 | 37 | store({ |
michael@0 | 38 | realm: "bla", |
michael@0 | 39 | username: "bla", |
michael@0 | 40 | password: "bla", |
michael@0 | 41 | onError: function onError() { |
michael@0 | 42 | assert.fail("onError was called"); |
michael@0 | 43 | } |
michael@0 | 44 | }); |
michael@0 | 45 | assert.pass("exception is not thrown if `onComplete is missing") |
michael@0 | 46 | done(); |
michael@0 | 47 | }; |
michael@0 | 48 | |
michael@0 | 49 | exports["test exceptions in onComplete are reported"] = function(assert, done) { |
michael@0 | 50 | store({ |
michael@0 | 51 | realm: "throws", |
michael@0 | 52 | username: "error", |
michael@0 | 53 | password: "boom!", |
michael@0 | 54 | onComplete: function onComplete(error) { |
michael@0 | 55 | throw new Error("Boom!") |
michael@0 | 56 | }, |
michael@0 | 57 | onError: function onError(error) { |
michael@0 | 58 | assert.equal(error.message, "Boom!", "Error thrown is reported"); |
michael@0 | 59 | done(); |
michael@0 | 60 | } |
michael@0 | 61 | }); |
michael@0 | 62 | }; |
michael@0 | 63 | |
michael@0 | 64 | exports["test store requires `realm` field"] = function(assert, done) { |
michael@0 | 65 | store({ |
michael@0 | 66 | username: "foo", |
michael@0 | 67 | password: "bar", |
michael@0 | 68 | onComplete: function onComplete() { |
michael@0 | 69 | assert.fail("onComplete should not be called"); |
michael@0 | 70 | }, |
michael@0 | 71 | onError: function onError() { |
michael@0 | 72 | assert.pass("'`realm` is required"); |
michael@0 | 73 | done(); |
michael@0 | 74 | } |
michael@0 | 75 | }); |
michael@0 | 76 | }; |
michael@0 | 77 | |
michael@0 | 78 | exports["test can't store same login twice"] = function(assert, done) { |
michael@0 | 79 | store({ |
michael@0 | 80 | username: "user", |
michael@0 | 81 | password: "pass", |
michael@0 | 82 | realm: "realm", |
michael@0 | 83 | onComplete: function onComplete() { |
michael@0 | 84 | assert.pass("credential saved"); |
michael@0 | 85 | |
michael@0 | 86 | store({ |
michael@0 | 87 | username: "user", |
michael@0 | 88 | password: "pass", |
michael@0 | 89 | realm: "realm", |
michael@0 | 90 | onComplete: function onComplete() { |
michael@0 | 91 | assert.fail("onComplete should not be called"); |
michael@0 | 92 | }, |
michael@0 | 93 | onError: function onError() { |
michael@0 | 94 | assert.pass("re-saving credential failed"); |
michael@0 | 95 | |
michael@0 | 96 | remove({ |
michael@0 | 97 | username: "user", |
michael@0 | 98 | password: "pass", |
michael@0 | 99 | realm: "realm", |
michael@0 | 100 | onComplete: function onComplete() { |
michael@0 | 101 | assert.pass("credential was removed"); |
michael@0 | 102 | done(); |
michael@0 | 103 | }, |
michael@0 | 104 | onError: function onError() { |
michael@0 | 105 | assert.fail("remove should not fail"); |
michael@0 | 106 | } |
michael@0 | 107 | }); |
michael@0 | 108 | } |
michael@0 | 109 | }); |
michael@0 | 110 | }, |
michael@0 | 111 | onError: function onError() { |
michael@0 | 112 | assert.fail("onError should not be called"); |
michael@0 | 113 | } |
michael@0 | 114 | }); |
michael@0 | 115 | }; |
michael@0 | 116 | |
michael@0 | 117 | exports["test remove fails if no login found"] = function(assert, done) { |
michael@0 | 118 | remove({ |
michael@0 | 119 | username: "foo", |
michael@0 | 120 | password: "bar", |
michael@0 | 121 | realm: "baz", |
michael@0 | 122 | onComplete: function onComplete() { |
michael@0 | 123 | assert.fail("should not be able to remove unstored credentials"); |
michael@0 | 124 | }, |
michael@0 | 125 | onError: function onError() { |
michael@0 | 126 | assert.pass("can't remove unstored credentials"); |
michael@0 | 127 | done(); |
michael@0 | 128 | } |
michael@0 | 129 | }); |
michael@0 | 130 | }; |
michael@0 | 131 | |
michael@0 | 132 | exports["test addon associated credentials"] = function(assert, done) { |
michael@0 | 133 | store({ |
michael@0 | 134 | username: "foo", |
michael@0 | 135 | password: "bar", |
michael@0 | 136 | realm: "baz", |
michael@0 | 137 | onComplete: function onComplete() { |
michael@0 | 138 | search({ |
michael@0 | 139 | username: "foo", |
michael@0 | 140 | password: "bar", |
michael@0 | 141 | realm: "baz", |
michael@0 | 142 | onComplete: function onComplete([credential]) { |
michael@0 | 143 | assert.equal(credential.url.indexOf("addon:"), 0, |
michael@0 | 144 | "`addon:` uri is used for add-on credentials"); |
michael@0 | 145 | assert.equal(credential.username, "foo", |
michael@0 | 146 | "username matches"); |
michael@0 | 147 | assert.equal(credential.password, "bar", |
michael@0 | 148 | "password matches"); |
michael@0 | 149 | assert.equal(credential.realm, "baz", "realm matches"); |
michael@0 | 150 | assert.equal(credential.formSubmitURL, null, |
michael@0 | 151 | "`formSubmitURL` is `null` for add-on credentials"); |
michael@0 | 152 | assert.equal(credential.usernameField, "", "usernameField is empty"); |
michael@0 | 153 | assert.equal(credential.passwordField, "", "passwordField is empty"); |
michael@0 | 154 | |
michael@0 | 155 | remove({ |
michael@0 | 156 | username: credential.username, |
michael@0 | 157 | password: credential.password, |
michael@0 | 158 | realm: credential.realm, |
michael@0 | 159 | onComplete: function onComplete() { |
michael@0 | 160 | assert.pass("credential is removed"); |
michael@0 | 161 | done(); |
michael@0 | 162 | }, |
michael@0 | 163 | onError: function onError() { |
michael@0 | 164 | assert.fail("onError should not be called"); |
michael@0 | 165 | } |
michael@0 | 166 | }); |
michael@0 | 167 | }, |
michael@0 | 168 | onError: function onError() { |
michael@0 | 169 | assert.fail("onError should not be called"); |
michael@0 | 170 | } |
michael@0 | 171 | }); |
michael@0 | 172 | }, |
michael@0 | 173 | onError: function onError() { |
michael@0 | 174 | assert.fail("onError should not be called"); |
michael@0 | 175 | } |
michael@0 | 176 | }); |
michael@0 | 177 | }; |
michael@0 | 178 | |
michael@0 | 179 | exports["test web page associated credentials"] = function(assert, done) { |
michael@0 | 180 | store({ |
michael@0 | 181 | url: "http://bar.foo.com/authentication/?login", |
michael@0 | 182 | formSubmitURL: "http://login.foo.com/authenticate.cgi", |
michael@0 | 183 | username: "user", |
michael@0 | 184 | password: "pass", |
michael@0 | 185 | usernameField: "user-f", |
michael@0 | 186 | passwordField: "pass-f", |
michael@0 | 187 | onComplete: function onComplete() { |
michael@0 | 188 | search({ |
michael@0 | 189 | username: "user", |
michael@0 | 190 | password: "pass", |
michael@0 | 191 | url: "http://bar.foo.com", |
michael@0 | 192 | formSubmitURL: "http://login.foo.com", |
michael@0 | 193 | onComplete: function onComplete([credential]) { |
michael@0 | 194 | assert.equal(credential.url, "http://bar.foo.com", "url matches"); |
michael@0 | 195 | assert.equal(credential.username, "user", "username matches"); |
michael@0 | 196 | assert.equal(credential.password, "pass", "password matches"); |
michael@0 | 197 | assert.equal(credential.realm, null, "realm is null"); |
michael@0 | 198 | assert.equal(credential.formSubmitURL, "http://login.foo.com", |
michael@0 | 199 | "formSubmitURL matches"); |
michael@0 | 200 | assert.equal(credential.usernameField, "user-f", |
michael@0 | 201 | "usernameField is matches"); |
michael@0 | 202 | assert.equal(credential.passwordField, "pass-f", |
michael@0 | 203 | "passwordField matches"); |
michael@0 | 204 | |
michael@0 | 205 | remove({ |
michael@0 | 206 | url: credential.url, |
michael@0 | 207 | formSubmitURL: credential.formSubmitURL, |
michael@0 | 208 | username: credential.username, |
michael@0 | 209 | password: credential.password, |
michael@0 | 210 | usernameField: credential.usernameField, |
michael@0 | 211 | passwordField: credential.passwordField, |
michael@0 | 212 | |
michael@0 | 213 | onComplete: function onComplete() { |
michael@0 | 214 | assert.pass("credential is removed"); |
michael@0 | 215 | done(); |
michael@0 | 216 | }, |
michael@0 | 217 | onError: function onError(e) { |
michael@0 | 218 | assert.fail("onError should not be called"); |
michael@0 | 219 | } |
michael@0 | 220 | }); |
michael@0 | 221 | }, |
michael@0 | 222 | onError: function onError() { |
michael@0 | 223 | assert.fail("onError should not be called"); |
michael@0 | 224 | } |
michael@0 | 225 | }); |
michael@0 | 226 | }, |
michael@0 | 227 | onError: function onError() { |
michael@0 | 228 | assert.fail("onError should not be called"); |
michael@0 | 229 | } |
michael@0 | 230 | }); |
michael@0 | 231 | }; |
michael@0 | 232 | |
michael@0 | 233 | exports["test site authentication credentials"] = function(assert, done) { |
michael@0 | 234 | store({ |
michael@0 | 235 | url: "http://authentication.com", |
michael@0 | 236 | username: "U", |
michael@0 | 237 | password: "P", |
michael@0 | 238 | realm: "R", |
michael@0 | 239 | onComplete: function onComplete() { |
michael@0 | 240 | search({ |
michael@0 | 241 | url: "http://authentication.com", |
michael@0 | 242 | username: "U", |
michael@0 | 243 | password: "P", |
michael@0 | 244 | realm: "R", |
michael@0 | 245 | onComplete: function onComplete([credential]) { |
michael@0 | 246 | assert.equal(credential.url,"http://authentication.com", |
michael@0 | 247 | "url matches"); |
michael@0 | 248 | assert.equal(credential.username, "U", "username matches"); |
michael@0 | 249 | assert.equal(credential.password, "P", "password matches"); |
michael@0 | 250 | assert.equal(credential.realm, "R", "realm matches"); |
michael@0 | 251 | assert.equal(credential.formSubmitURL, null, "formSubmitURL is null"); |
michael@0 | 252 | assert.equal(credential.usernameField, "", "usernameField is empty"); |
michael@0 | 253 | assert.equal(credential.passwordField, "", "passwordField is empty"); |
michael@0 | 254 | |
michael@0 | 255 | remove({ |
michael@0 | 256 | url: credential.url, |
michael@0 | 257 | username: credential.username, |
michael@0 | 258 | password: credential.password, |
michael@0 | 259 | realm: credential.realm, |
michael@0 | 260 | onComplete: function onComplete() { |
michael@0 | 261 | assert.pass("credential is removed"); |
michael@0 | 262 | done(); |
michael@0 | 263 | }, |
michael@0 | 264 | onError: function onError() { |
michael@0 | 265 | assert.fail("onError should not be called"); |
michael@0 | 266 | } |
michael@0 | 267 | }); |
michael@0 | 268 | }, |
michael@0 | 269 | onError: function onError() { |
michael@0 | 270 | assert.fail("onError should not be called"); |
michael@0 | 271 | } |
michael@0 | 272 | }); |
michael@0 | 273 | }, |
michael@0 | 274 | onError: function onError() { |
michael@0 | 275 | assert.fail("onError should not be called"); |
michael@0 | 276 | } |
michael@0 | 277 | }); |
michael@0 | 278 | }; |
michael@0 | 279 | |
michael@0 | 280 | require("test").run(exports); |