Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 2 | Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 3 | |
michael@0 | 4 | function createURI(s) { |
michael@0 | 5 | let service = Components.classes["@mozilla.org/network/io-service;1"] |
michael@0 | 6 | .getService(Components.interfaces.nsIIOService); |
michael@0 | 7 | return service.newURI(s, null, null); |
michael@0 | 8 | } |
michael@0 | 9 | |
michael@0 | 10 | function run_test() { |
michael@0 | 11 | // Set up a profile. |
michael@0 | 12 | do_get_profile(); |
michael@0 | 13 | |
michael@0 | 14 | var secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager); |
michael@0 | 15 | const kURI1 = "http://example.com"; |
michael@0 | 16 | var app1 = secMan.getAppCodebasePrincipal(createURI(kURI1), 1, false); |
michael@0 | 17 | var app10 = secMan.getAppCodebasePrincipal(createURI(kURI1), 10, false); |
michael@0 | 18 | var app1browser = secMan.getAppCodebasePrincipal(createURI(kURI1), 1, true); |
michael@0 | 19 | |
michael@0 | 20 | var am = Cc["@mozilla.org/network/http-auth-manager;1"]. |
michael@0 | 21 | getService(Ci.nsIHttpAuthManager); |
michael@0 | 22 | am.setAuthIdentity("http", "a.example.com", -1, "basic", "realm", "", "example.com", "user", "pass", false, app1); |
michael@0 | 23 | am.setAuthIdentity("http", "a.example.com", -1, "basic", "realm", "", "example.com", "user3", "pass3", false, app1browser); |
michael@0 | 24 | am.setAuthIdentity("http", "a.example.com", -1, "basic", "realm", "", "example.com", "user2", "pass2", false, app10); |
michael@0 | 25 | |
michael@0 | 26 | let subject = { |
michael@0 | 27 | appId: 1, |
michael@0 | 28 | browserOnly: true, |
michael@0 | 29 | QueryInterface: XPCOMUtils.generateQI([Ci.mozIApplicationClearPrivateDataParams]) |
michael@0 | 30 | }; |
michael@0 | 31 | Services.obs.notifyObservers(subject, "webapps-clear-data", null); |
michael@0 | 32 | |
michael@0 | 33 | var domain = {value: ""}, user = {value: ""}, pass = {value: ""}; |
michael@0 | 34 | try { |
michael@0 | 35 | am.getAuthIdentity("http", "a.example.com", -1, "basic", "realm", "", domain, user, pass, false, app1browser); |
michael@0 | 36 | do_check_false(true); // no identity should be present |
michael@0 | 37 | } catch (x) { |
michael@0 | 38 | do_check_eq(domain.value, ""); |
michael@0 | 39 | do_check_eq(user.value, ""); |
michael@0 | 40 | do_check_eq(pass.value, ""); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | am.getAuthIdentity("http", "a.example.com", -1, "basic", "realm", "", domain, user, pass, false, app1); |
michael@0 | 44 | do_check_eq(domain.value, "example.com"); |
michael@0 | 45 | do_check_eq(user.value, "user"); |
michael@0 | 46 | do_check_eq(pass.value, "pass"); |
michael@0 | 47 | |
michael@0 | 48 | |
michael@0 | 49 | am.getAuthIdentity("http", "a.example.com", -1, "basic", "realm", "", domain, user, pass, false, app10); |
michael@0 | 50 | do_check_eq(domain.value, "example.com"); |
michael@0 | 51 | do_check_eq(user.value, "user2"); |
michael@0 | 52 | do_check_eq(pass.value, "pass2"); |
michael@0 | 53 | } |