mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1127579 - Handle a user capturing a HTTPS login with an already saved login for the HTTP version. r=dolske
MozReview-Commit-ID: 4vWuFUmicYV --HG-- extra : rebase_source : ca7769168eeba7120b1480a67adf427e8c2df86a
This commit is contained in:
parent
1adf4b4140
commit
b8f1ff3fed
@ -1432,3 +1432,5 @@ pref("browser.migration.automigrate", false);
|
||||
pref("dom.mozBrowserFramesEnabled", true);
|
||||
|
||||
pref("extensions.pocket.enabled", true);
|
||||
|
||||
pref("signon.schemeUpgrades", true);
|
||||
|
@ -204,6 +204,42 @@ this.LoginHelper = {
|
||||
return false;
|
||||
},
|
||||
|
||||
doLoginsMatch(aLogin1, aLogin2, {
|
||||
ignorePassword = false,
|
||||
ignoreSchemes = false,
|
||||
}) {
|
||||
if (aLogin1.httpRealm != aLogin2.httpRealm ||
|
||||
aLogin1.username != aLogin2.username)
|
||||
return false;
|
||||
|
||||
if (!ignorePassword && aLogin1.password != aLogin2.password)
|
||||
return false;
|
||||
|
||||
if (ignoreSchemes) {
|
||||
let hostname1URI = Services.io.newURI(aLogin1.hostname, null, null);
|
||||
let hostname2URI = Services.io.newURI(aLogin2.hostname, null, null);
|
||||
if (hostname1URI.hostPort != hostname2URI.hostPort)
|
||||
return false;
|
||||
|
||||
if (aLogin1.formSubmitURL != "" && aLogin2.formSubmitURL != "" &&
|
||||
Services.io.newURI(aLogin1.formSubmitURL, null, null).hostPort !=
|
||||
Services.io.newURI(aLogin2.formSubmitURL, null, null).hostPort)
|
||||
return false;
|
||||
} else {
|
||||
if (aLogin1.hostname != aLogin2.hostname)
|
||||
return false;
|
||||
|
||||
// If either formSubmitURL is blank (but not null), then match.
|
||||
if (aLogin1.formSubmitURL != "" && aLogin2.formSubmitURL != "" &&
|
||||
aLogin1.formSubmitURL != aLogin2.formSubmitURL)
|
||||
return false;
|
||||
}
|
||||
|
||||
// The .usernameField and .passwordField values are ignored.
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new login object that results by modifying the given object with
|
||||
* the provided data.
|
||||
|
@ -334,6 +334,15 @@ var LoginManagerParent = {
|
||||
schemeUpgrades: LoginHelper.schemeUpgrades,
|
||||
});
|
||||
|
||||
// Dedupe so the length checks below still make sense with scheme upgrades.
|
||||
// Below here we have one login per hostPort + action + username with the
|
||||
// matching scheme being preferred.
|
||||
let resolveBy = [
|
||||
"scheme",
|
||||
"timePasswordChanged",
|
||||
];
|
||||
logins = LoginHelper.dedupeLogins(logins, ["username"], resolveBy, hostname);
|
||||
|
||||
// If we didn't find a username field, but seem to be changing a
|
||||
// password, allow the user to select from a list of applicable
|
||||
// logins to update the password for.
|
||||
@ -355,6 +364,10 @@ var LoginManagerParent = {
|
||||
|
||||
prompter.promptToChangePassword(oldLogin, formLogin);
|
||||
} else {
|
||||
// Note: It's possible that that we already have the correct u+p saved
|
||||
// but since we don't have the username, we don't know if the user is
|
||||
// changing a second account to the new password so we ask anyways.
|
||||
|
||||
prompter.promptToChangePasswordWithUsernames(
|
||||
logins, logins.length, formLogin);
|
||||
}
|
||||
@ -365,8 +378,8 @@ var LoginManagerParent = {
|
||||
|
||||
var existingLogin = null;
|
||||
// Look for an existing login that matches the form login.
|
||||
for (var i = 0; i < logins.length; i++) {
|
||||
var same, login = logins[i];
|
||||
for (let login of logins) {
|
||||
let same;
|
||||
|
||||
// If one login has a username but the other doesn't, ignore
|
||||
// the username when comparing and only match if they have the
|
||||
@ -375,14 +388,23 @@ var LoginManagerParent = {
|
||||
if (!login.username && formLogin.username) {
|
||||
var restoreMe = formLogin.username;
|
||||
formLogin.username = "";
|
||||
same = formLogin.matches(login, false);
|
||||
same = LoginHelper.doLoginsMatch(formLogin, login, {
|
||||
ignorePassword: false,
|
||||
ignoreSchemes: LoginHelper.schemeUpgrades,
|
||||
});
|
||||
formLogin.username = restoreMe;
|
||||
} else if (!formLogin.username && login.username) {
|
||||
formLogin.username = login.username;
|
||||
same = formLogin.matches(login, false);
|
||||
same = LoginHelper.doLoginsMatch(formLogin, login, {
|
||||
ignorePassword: false,
|
||||
ignoreSchemes: LoginHelper.schemeUpgrades,
|
||||
});
|
||||
formLogin.username = ""; // we know it's always blank.
|
||||
} else {
|
||||
same = formLogin.matches(login, true);
|
||||
same = LoginHelper.doLoginsMatch(formLogin, login, {
|
||||
ignorePassword: true,
|
||||
ignoreSchemes: LoginHelper.schemeUpgrades,
|
||||
});
|
||||
}
|
||||
|
||||
if (same) {
|
||||
|
@ -6,6 +6,10 @@ const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "LoginHelper",
|
||||
"resource://gre/modules/LoginHelper.jsm");
|
||||
|
||||
|
||||
function nsLoginInfo() {}
|
||||
|
||||
nsLoginInfo.prototype = {
|
||||
@ -38,22 +42,9 @@ nsLoginInfo.prototype = {
|
||||
},
|
||||
|
||||
matches(aLogin, ignorePassword) {
|
||||
if (this.hostname != aLogin.hostname ||
|
||||
this.httpRealm != aLogin.httpRealm ||
|
||||
this.username != aLogin.username)
|
||||
return false;
|
||||
|
||||
if (!ignorePassword && this.password != aLogin.password)
|
||||
return false;
|
||||
|
||||
// If either formSubmitURL is blank (but not null), then match.
|
||||
if (this.formSubmitURL != "" && aLogin.formSubmitURL != "" &&
|
||||
this.formSubmitURL != aLogin.formSubmitURL)
|
||||
return false;
|
||||
|
||||
// The .usernameField and .passwordField values are ignored.
|
||||
|
||||
return true;
|
||||
return LoginHelper.doLoginsMatch(this, aLogin, {
|
||||
ignorePassword,
|
||||
});
|
||||
},
|
||||
|
||||
equals : function (aLogin) {
|
||||
|
@ -820,9 +820,13 @@ LoginManagerPrompter.prototype = {
|
||||
};
|
||||
|
||||
let updateButtonLabel = () => {
|
||||
let foundLogins = Services.logins.findLogins({}, login.hostname,
|
||||
login.formSubmitURL,
|
||||
login.httpRealm);
|
||||
let foundLogins = LoginHelper.searchLoginsWithObject({
|
||||
formSubmitURL: login.formSubmitURL,
|
||||
hostname: login.hostname,
|
||||
httpRealm: login.httpRealm,
|
||||
schemeUpgrades: LoginHelper.schemeUpgrades,
|
||||
});
|
||||
|
||||
let logins = this._filterUpdatableLogins(login, foundLogins);
|
||||
let msgNames = (logins.length == 0) ? saveMsgNames : changeMsgNames;
|
||||
|
||||
@ -886,9 +890,13 @@ LoginManagerPrompter.prototype = {
|
||||
};
|
||||
|
||||
let persistData = () => {
|
||||
let foundLogins = Services.logins.findLogins({}, login.hostname,
|
||||
login.formSubmitURL,
|
||||
login.httpRealm);
|
||||
let foundLogins = LoginHelper.searchLoginsWithObject({
|
||||
formSubmitURL: login.formSubmitURL,
|
||||
hostname: login.hostname,
|
||||
httpRealm: login.httpRealm,
|
||||
schemeUpgrades: LoginHelper.schemeUpgrades,
|
||||
});
|
||||
|
||||
let logins = this._filterUpdatableLogins(login, foundLogins);
|
||||
|
||||
if (logins.length == 0) {
|
||||
@ -1002,15 +1010,15 @@ LoginManagerPrompter.prototype = {
|
||||
);
|
||||
},
|
||||
|
||||
/*
|
||||
* _showSaveLoginNotification
|
||||
*
|
||||
/**
|
||||
* Displays a notification bar or a popup notification, to allow the user
|
||||
* to save the specified login. This allows the user to see the results of
|
||||
* their login, and only save a login which they know worked.
|
||||
*
|
||||
* @param aNotifyObj
|
||||
* A notification box or a popup notification.
|
||||
* @param aLogin
|
||||
* The login captured from the form.
|
||||
*/
|
||||
_showSaveLoginNotification : function (aNotifyObj, aLogin) {
|
||||
// Ugh. We can't use the strings from the popup window, because they
|
||||
@ -1223,6 +1231,8 @@ LoginManagerPrompter.prototype = {
|
||||
|
||||
// Notification is a PopupNotification
|
||||
if (aNotifyObj == this._getPopupNote()) {
|
||||
aOldLogin.hostname = aNewLogin.hostname;
|
||||
aOldLogin.formSubmitURL = aNewLogin.formSubmitURL;
|
||||
aOldLogin.password = aNewLogin.password;
|
||||
aOldLogin.username = aNewLogin.username;
|
||||
this._showLoginCaptureDoorhanger(aOldLogin, "password-change");
|
||||
@ -1347,6 +1357,8 @@ LoginManagerPrompter.prototype = {
|
||||
var propBag = Cc["@mozilla.org/hash-property-bag;1"].
|
||||
createInstance(Ci.nsIWritablePropertyBag);
|
||||
if (aNewLogin) {
|
||||
propBag.setProperty("formSubmitURL", aNewLogin.formSubmitURL);
|
||||
propBag.setProperty("hostname", aNewLogin.hostname);
|
||||
propBag.setProperty("password", aNewLogin.password);
|
||||
propBag.setProperty("username", aNewLogin.username);
|
||||
// Explicitly set the password change time here (even though it would
|
||||
|
@ -359,7 +359,8 @@ this.LoginManagerStorage_json.prototype = {
|
||||
}
|
||||
}
|
||||
|
||||
this.log("_searchLogins: returning", foundLogins.length, "logins for", matchData);
|
||||
this.log("_searchLogins: returning", foundLogins.length, "logins for", matchData,
|
||||
"with options", aOptions);
|
||||
return [foundLogins, foundIds];
|
||||
},
|
||||
|
||||
|
@ -7,13 +7,15 @@ const BRAND_SHORT_NAME = BRAND_BUNDLE.GetStringFromName("brandShortName");
|
||||
|
||||
let nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1",
|
||||
Ci.nsILoginInfo, "init");
|
||||
let login1 = new nsLoginInfo("http://mochi.test:8888", "http://mochi.test:8888", null,
|
||||
let login1 = new nsLoginInfo("http://example.com", "http://example.com", null,
|
||||
"notifyu1", "notifyp1", "user", "pass");
|
||||
let login2 = new nsLoginInfo("http://mochi.test:8888", "http://mochi.test:8888", null,
|
||||
let login1HTTPS = new nsLoginInfo("https://example.com", "https://example.com", null,
|
||||
"notifyu1", "notifyp1", "user", "pass");
|
||||
let login2 = new nsLoginInfo("http://example.com", "http://example.com", null,
|
||||
"", "notifyp1", "", "pass");
|
||||
let login1B = new nsLoginInfo("http://mochi.test:8888", "http://mochi.test:8888", null,
|
||||
let login1B = new nsLoginInfo("http://example.com", "http://example.com", null,
|
||||
"notifyu1B", "notifyp1B", "user", "pass");
|
||||
let login2B = new nsLoginInfo("http://mochi.test:8888", "http://mochi.test:8888", null,
|
||||
let login2B = new nsLoginInfo("http://example.com", "http://example.com", null,
|
||||
"", "notifyp1B", "", "pass");
|
||||
|
||||
requestLongerTimeout(2);
|
||||
@ -46,7 +48,7 @@ add_task(function* test_clickNever() {
|
||||
is(fieldValues.password, "notifyp1", "Checking submitted password");
|
||||
let notif = getCaptureDoorhanger("password-save");
|
||||
ok(notif, "got notification popup");
|
||||
is(true, Services.logins.getLoginSavingEnabled("http://mochi.test:8888"),
|
||||
is(true, Services.logins.getLoginSavingEnabled("http://example.com"),
|
||||
"Checking for login saving enabled");
|
||||
clickDoorhangerButton(notif, NEVER_BUTTON);
|
||||
});
|
||||
@ -59,9 +61,9 @@ add_task(function* test_clickNever() {
|
||||
is(fieldValues.password, "notifyp1", "Checking submitted password");
|
||||
let notif = getCaptureDoorhanger("password-save");
|
||||
ok(!notif, "checking for no notification popup");
|
||||
is(false, Services.logins.getLoginSavingEnabled("http://mochi.test:8888"),
|
||||
is(false, Services.logins.getLoginSavingEnabled("http://example.com"),
|
||||
"Checking for login saving disabled");
|
||||
Services.logins.setLoginSavingEnabled("http://mochi.test:8888", true);
|
||||
Services.logins.setLoginSavingEnabled("http://example.com", true);
|
||||
});
|
||||
|
||||
is(Services.logins.getAllLogins().length, 0, "Should not have any logins yet");
|
||||
@ -80,7 +82,7 @@ add_task(function* test_clickRemember() {
|
||||
|
||||
let logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 1, "Should only have 1 login");
|
||||
let login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
|
||||
let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||
is(login.username, "notifyu1", "Check the username used on the new entry");
|
||||
is(login.password, "notifyp1", "Check the password used on the new entry");
|
||||
is(login.timesUsed, 1, "Check times used on new entry");
|
||||
@ -95,7 +97,7 @@ add_task(function* test_clickRemember() {
|
||||
|
||||
logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 1, "Should only have 1 login");
|
||||
login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
|
||||
login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||
is(login.username, "notifyu1", "Check the username used");
|
||||
is(login.password, "notifyp1", "Check the password used");
|
||||
is(login.timesUsed, 2, "Check times used incremented");
|
||||
@ -209,7 +211,7 @@ add_task(function* test_pwOnlyLoginMatchesForm() {
|
||||
|
||||
let logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 1, "Should only have 1 login");
|
||||
let login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
|
||||
let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||
is(login.username, "", "Check the username");
|
||||
is(login.password, "notifyp1", "Check the password");
|
||||
is(login.timesUsed, 1, "Check times used");
|
||||
@ -230,7 +232,7 @@ add_task(function* test_pwOnlyFormMatchesLogin() {
|
||||
|
||||
let logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 1, "Should only have 1 login");
|
||||
let login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
|
||||
let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||
is(login.username, "notifyu1", "Check the username");
|
||||
is(login.password, "notifyp1", "Check the password");
|
||||
is(login.timesUsed, 2, "Check times used");
|
||||
@ -252,7 +254,7 @@ add_task(function* test_pwOnlyFormDoesntMatchExisting() {
|
||||
|
||||
let logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 1, "Should only have 1 login");
|
||||
let login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
|
||||
let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||
is(login.username, "notifyu1B", "Check the username unchanged");
|
||||
is(login.password, "notifyp1B", "Check the password unchanged");
|
||||
is(login.timesUsed, 1, "Check times used");
|
||||
@ -274,7 +276,7 @@ add_task(function* test_changeUPLoginOnUPForm_dont() {
|
||||
|
||||
let logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 1, "Should only have 1 login");
|
||||
let login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
|
||||
let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||
is(login.username, "notifyu1", "Check the username unchanged");
|
||||
is(login.password, "notifyp1", "Check the password unchanged");
|
||||
is(login.timesUsed, 1, "Check times used");
|
||||
@ -297,7 +299,7 @@ add_task(function* test_changeUPLoginOnUPForm_change() {
|
||||
|
||||
let logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 1, "Should only have 1 login");
|
||||
let login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
|
||||
let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||
is(login.username, "notifyu1", "Check the username unchanged");
|
||||
is(login.password, "pass2", "Check the password changed");
|
||||
is(login.timesUsed, 2, "Check times used");
|
||||
@ -325,7 +327,7 @@ add_task(function* test_changePLoginOnUPForm() {
|
||||
|
||||
let logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 1, "Should only have 1 login");
|
||||
let login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
|
||||
let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||
is(login.username, "", "Check the username unchanged");
|
||||
is(login.password, "pass2", "Check the password changed");
|
||||
is(login.timesUsed, 2, "Check times used");
|
||||
@ -347,7 +349,7 @@ add_task(function* test_changePLoginOnPForm() {
|
||||
|
||||
let logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 1, "Should only have 1 login");
|
||||
let login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
|
||||
let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||
is(login.username, "", "Check the username unchanged");
|
||||
is(login.password, "notifyp1", "Check the password changed");
|
||||
is(login.timesUsed, 3, "Check times used");
|
||||
@ -422,7 +424,7 @@ add_task(function* test_change2pw0unExistingDifferentUP() {
|
||||
|
||||
let logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 1, "Should only have 1 login");
|
||||
let login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
|
||||
let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||
is(login.username, "notifyu1B", "Check the username unchanged");
|
||||
is(login.password, "notifyp1B", "Check the password unchanged");
|
||||
is(login.timesUsed, 1, "Check times used");
|
||||
@ -446,7 +448,7 @@ add_task(function* test_change2pw0unExistingDifferentP() {
|
||||
|
||||
let logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 1, "Should only have 1 login");
|
||||
let login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
|
||||
let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||
is(login.username, "", "Check the username unchanged");
|
||||
is(login.password, "notifyp1B", "Check the password unchanged");
|
||||
is(login.timesUsed, 1, "Check times used");
|
||||
@ -469,7 +471,7 @@ add_task(function* test_change2pw0unExistingWithSameP() {
|
||||
|
||||
let logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 1, "Should only have 1 login");
|
||||
let login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
|
||||
let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||
is(login.username, "", "Check the username unchanged");
|
||||
is(login.password, "notifyp1", "Check the password unchanged");
|
||||
is(login.timesUsed, 2, "Check times used incremented");
|
||||
@ -494,7 +496,7 @@ add_task(function* test_changeUPLoginOnPUpdateForm() {
|
||||
|
||||
let logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 1, "Should only have 1 login");
|
||||
let login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
|
||||
let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||
is(login.username, "notifyu1", "Check the username unchanged");
|
||||
is(login.password, "pass2", "Check the password changed");
|
||||
is(login.timesUsed, 2, "Check times used");
|
||||
@ -525,7 +527,7 @@ add_task(function* test_recipeCaptureFields_NewLogin() {
|
||||
|
||||
let logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 1, "Should only have 1 login");
|
||||
let login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
|
||||
let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||
is(login.username, "notifyu1", "Check the username unchanged");
|
||||
is(login.password, "notifyp1", "Check the password unchanged");
|
||||
is(login.timesUsed, 1, "Check times used");
|
||||
@ -545,7 +547,7 @@ add_task(function* test_recipeCaptureFields_ExistingLogin() {
|
||||
checkOnlyLoginWasUsedTwice({ justChanged: false });
|
||||
let logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 1, "Should only have 1 login");
|
||||
let login = SpecialPowers.wrap(logins[0]).QueryInterface(Ci.nsILoginMetaInfo);
|
||||
let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||
is(login.username, "notifyu1", "Check the username unchanged");
|
||||
is(login.password, "notifyp1", "Check the password unchanged");
|
||||
is(login.timesUsed, 2, "Check times used incremented");
|
||||
@ -576,5 +578,114 @@ add_task(function* test_noShowPasswordOnDismissal() {
|
||||
});
|
||||
});
|
||||
|
||||
add_task(function* test_httpsUpgradeCaptureFields_noChange() {
|
||||
info("Check that we don't prompt to remember when capturing an upgraded login with no change");
|
||||
Services.logins.addLogin(login1);
|
||||
// Sanity check the HTTP login exists.
|
||||
let logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 1, "Should have the HTTP login");
|
||||
|
||||
yield testSubmittingLoginForm("subtst_notifications_1.html", function*(fieldValues) {
|
||||
is(fieldValues.username, "notifyu1", "Checking submitted username");
|
||||
is(fieldValues.password, "notifyp1", "Checking submitted password");
|
||||
let notif = getCaptureDoorhanger("password-save");
|
||||
ok(!notif, "checking for no notification popup");
|
||||
}, "https://example.com"); // This is HTTPS whereas the saved login is HTTP
|
||||
|
||||
logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 1, "Should only have 1 login still");
|
||||
let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||
is(login.hostname, "http://example.com", "Check the hostname is unchanged");
|
||||
is(login.username, "notifyu1", "Check the username is unchanged");
|
||||
is(login.password, "notifyp1", "Check the password is unchanged");
|
||||
is(login.timesUsed, 2, "Check times used increased");
|
||||
|
||||
Services.logins.removeLogin(login1);
|
||||
});
|
||||
|
||||
add_task(function* test_httpsUpgradeCaptureFields_changePW() {
|
||||
info("Check that we prompt to change when capturing an upgraded login with a new PW");
|
||||
Services.logins.addLogin(login1);
|
||||
// Sanity check the HTTP login exists.
|
||||
let logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 1, "Should have the HTTP login");
|
||||
|
||||
yield testSubmittingLoginForm("subtst_notifications_8.html", function*(fieldValues) {
|
||||
is(fieldValues.username, "notifyu1", "Checking submitted username");
|
||||
is(fieldValues.password, "pass2", "Checking submitted password");
|
||||
let notif = getCaptureDoorhanger("password-change");
|
||||
ok(notif, "checking for a change popup");
|
||||
clickDoorhangerButton(notif, CHANGE_BUTTON);
|
||||
ok(!getCaptureDoorhanger("password-change"), "popup should be gone");
|
||||
}, "https://example.com"); // This is HTTPS whereas the saved login is HTTP
|
||||
|
||||
checkOnlyLoginWasUsedTwice({ justChanged: true });
|
||||
logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 1, "Should only have 1 login still");
|
||||
let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||
is(login.hostname, "https://example.com", "Check the hostname is upgraded");
|
||||
is(login.formSubmitURL, "https://example.com", "Check the formSubmitURL is upgraded");
|
||||
is(login.username, "notifyu1", "Check the username is unchanged");
|
||||
is(login.password, "pass2", "Check the password changed");
|
||||
is(login.timesUsed, 2, "Check times used increased");
|
||||
|
||||
Services.logins.removeAllLogins();
|
||||
});
|
||||
|
||||
add_task(function* test_httpsUpgradeCaptureFields_captureMatchingHTTP() {
|
||||
info("Capture a new HTTP login which matches a stored HTTPS one.");
|
||||
Services.logins.addLogin(login1HTTPS);
|
||||
|
||||
yield testSubmittingLoginForm("subtst_notifications_1.html", function*(fieldValues) {
|
||||
is(fieldValues.username, "notifyu1", "Checking submitted username");
|
||||
is(fieldValues.password, "notifyp1", "Checking submitted password");
|
||||
let notif = getCaptureDoorhanger("password-save");
|
||||
ok(notif, "got notification popup");
|
||||
|
||||
is(Services.logins.getAllLogins().length, 1, "Should only have the HTTPS login");
|
||||
clickDoorhangerButton(notif, REMEMBER_BUTTON);
|
||||
});
|
||||
|
||||
let logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 2, "Should have both HTTP and HTTPS logins");
|
||||
for (let login of logins) {
|
||||
login = login.QueryInterface(Ci.nsILoginMetaInfo);
|
||||
is(login.username, "notifyu1", "Check the username used on the new entry");
|
||||
is(login.password, "notifyp1", "Check the password used on the new entry");
|
||||
is(login.timesUsed, 1, "Check times used on entry");
|
||||
}
|
||||
|
||||
info("Make sure Remember took effect and we don't prompt for an existing HTTP login");
|
||||
yield testSubmittingLoginForm("subtst_notifications_1.html", function*(fieldValues) {
|
||||
is(fieldValues.username, "notifyu1", "Checking submitted username");
|
||||
is(fieldValues.password, "notifyp1", "Checking submitted password");
|
||||
let notif = getCaptureDoorhanger("password-save");
|
||||
ok(!notif, "checking for no notification popup");
|
||||
});
|
||||
|
||||
logins = Services.logins.getAllLogins();
|
||||
is(logins.length, 2, "Should have both HTTP and HTTPS still");
|
||||
|
||||
let httpsLogins = LoginHelper.searchLoginsWithObject({
|
||||
hostname: "https://example.com",
|
||||
});
|
||||
is(httpsLogins.length, 1, "Check https logins count");
|
||||
let httpsLogin = httpsLogins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||
ok(httpsLogin.equals(login1HTTPS), "Check HTTPS login didn't change");
|
||||
is(httpsLogin.timesUsed, 1, "Check times used");
|
||||
|
||||
let httpLogins = LoginHelper.searchLoginsWithObject({
|
||||
hostname: "http://example.com",
|
||||
});
|
||||
is(httpLogins.length, 1, "Check http logins count");
|
||||
let httpLogin = httpLogins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||
ok(httpLogin.equals(login1), "Check HTTP login is as expected");
|
||||
is(httpLogin.timesUsed, 2, "Check times used increased");
|
||||
|
||||
Services.logins.removeLogin(login1);
|
||||
Services.logins.removeLogin(login1HTTPS);
|
||||
});
|
||||
|
||||
|
||||
// TODO:
|
||||
// * existing login test, form has different password --> change password, no save prompt
|
||||
|
@ -39,9 +39,9 @@ function getSelectDialogDoc() {
|
||||
|
||||
let nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1",
|
||||
Ci.nsILoginInfo, "init");
|
||||
let login1 = new nsLoginInfo("http://mochi.test:8888", "http://mochi.test:8888", null,
|
||||
let login1 = new nsLoginInfo("http://example.com", "http://example.com", null,
|
||||
"notifyu1", "notifyp1", "user", "pass");
|
||||
let login1B = new nsLoginInfo("http://mochi.test:8888", "http://mochi.test:8888", null,
|
||||
let login1B = new nsLoginInfo("http://example.com", "http://example.com", null,
|
||||
"notifyu1B", "notifyp1B", "user", "pass");
|
||||
|
||||
add_task(function* test_changeUPLoginOnPUpdateForm_accept() {
|
||||
|
@ -20,10 +20,10 @@ registerCleanupFunction(function* cleanup_removeAllLoginsAndResetRecipes() {
|
||||
*
|
||||
* @param {String} aPageFile - test page file name which auto-submits to formsubmit.sjs
|
||||
* @param {Function} aTaskFn - task which can be run before the tab closes.
|
||||
* @param {String} [aOrigin="http://mochi.test:8888"] - origin of the server to
|
||||
* use to load `aPageFile`.
|
||||
* @param {String} [aOrigin="http://example.com"] - origin of the server to use
|
||||
* to load `aPageFile`.
|
||||
*/
|
||||
function testSubmittingLoginForm(aPageFile, aTaskFn, aOrigin = "http://mochi.test:8888") {
|
||||
function testSubmittingLoginForm(aPageFile, aTaskFn, aOrigin = "http://example.com") {
|
||||
return BrowserTestUtils.withNewTab({
|
||||
gBrowser,
|
||||
url: aOrigin + DIRECTORY_PATH + aPageFile,
|
||||
|
Loading…
Reference in New Issue
Block a user