Bug 1846036, replace usage of findLogins with searchLoginsAsync, r=credential-management-reviewers,sync-reviewers,joschmidt,markh
One caller in modifyLogin is switched to synchronous searchLogins, we can switch this later to add an asyncronous version of modifyLogin Differential Revision: https://phabricator.services.mozilla.com/D184840
This commit is contained in:
@@ -9,8 +9,8 @@ const OLD_HOST = "http://mozilla.org";
|
|||||||
const NEW_HOST = "http://mozilla.com";
|
const NEW_HOST = "http://mozilla.com";
|
||||||
const FXA_HOST = "chrome://FirefoxAccounts";
|
const FXA_HOST = "chrome://FirefoxAccounts";
|
||||||
|
|
||||||
function checkLoginExists(host, shouldExist) {
|
async function checkLoginExists(origin, shouldExist) {
|
||||||
const logins = Services.logins.findLogins(host, "", null);
|
const logins = await Services.logins.searchLoginsAsync({ origin });
|
||||||
equal(
|
equal(
|
||||||
logins.length,
|
logins.length,
|
||||||
shouldExist ? 1 : 0,
|
shouldExist ? 1 : 0,
|
||||||
@@ -19,7 +19,7 @@ function checkLoginExists(host, shouldExist) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function addLogin(host, timestamp) {
|
async function addLogin(host, timestamp) {
|
||||||
checkLoginExists(host, false);
|
await checkLoginExists(host, false);
|
||||||
let login = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(
|
let login = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(
|
||||||
Ci.nsILoginInfo
|
Ci.nsILoginInfo
|
||||||
);
|
);
|
||||||
@@ -27,7 +27,7 @@ async function addLogin(host, timestamp) {
|
|||||||
login.QueryInterface(Ci.nsILoginMetaInfo);
|
login.QueryInterface(Ci.nsILoginMetaInfo);
|
||||||
login.timePasswordChanged = timestamp;
|
login.timePasswordChanged = timestamp;
|
||||||
await Services.logins.addLoginAsync(login);
|
await Services.logins.addLoginAsync(login);
|
||||||
checkLoginExists(host, true);
|
await checkLoginExists(host, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setupPasswords() {
|
async function setupPasswords() {
|
||||||
@@ -62,27 +62,27 @@ add_task(async function testPasswords() {
|
|||||||
extension.sendMessage(method, {});
|
extension.sendMessage(method, {});
|
||||||
await extension.awaitMessage("passwordsRemoved");
|
await extension.awaitMessage("passwordsRemoved");
|
||||||
|
|
||||||
checkLoginExists(OLD_HOST, false);
|
await checkLoginExists(OLD_HOST, false);
|
||||||
checkLoginExists(NEW_HOST, false);
|
await checkLoginExists(NEW_HOST, false);
|
||||||
checkLoginExists(FXA_HOST, true);
|
await checkLoginExists(FXA_HOST, true);
|
||||||
|
|
||||||
// Clear passwords with recent since value.
|
// Clear passwords with recent since value.
|
||||||
await setupPasswords();
|
await setupPasswords();
|
||||||
extension.sendMessage(method, { since: REFERENCE_DATE - 1000 });
|
extension.sendMessage(method, { since: REFERENCE_DATE - 1000 });
|
||||||
await extension.awaitMessage("passwordsRemoved");
|
await extension.awaitMessage("passwordsRemoved");
|
||||||
|
|
||||||
checkLoginExists(OLD_HOST, true);
|
await checkLoginExists(OLD_HOST, true);
|
||||||
checkLoginExists(NEW_HOST, false);
|
await checkLoginExists(NEW_HOST, false);
|
||||||
checkLoginExists(FXA_HOST, true);
|
await checkLoginExists(FXA_HOST, true);
|
||||||
|
|
||||||
// Clear passwords with old since value.
|
// Clear passwords with old since value.
|
||||||
await setupPasswords();
|
await setupPasswords();
|
||||||
extension.sendMessage(method, { since: REFERENCE_DATE - 20000 });
|
extension.sendMessage(method, { since: REFERENCE_DATE - 20000 });
|
||||||
await extension.awaitMessage("passwordsRemoved");
|
await extension.awaitMessage("passwordsRemoved");
|
||||||
|
|
||||||
checkLoginExists(OLD_HOST, false);
|
await checkLoginExists(OLD_HOST, false);
|
||||||
checkLoginExists(NEW_HOST, false);
|
await checkLoginExists(NEW_HOST, false);
|
||||||
checkLoginExists(FXA_HOST, true);
|
await checkLoginExists(FXA_HOST, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
await extension.startup();
|
await extension.startup();
|
||||||
|
|||||||
@@ -244,13 +244,13 @@ class TestFirefoxRefresh(MarionetteTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def checkPassword(self):
|
def checkPassword(self):
|
||||||
loginInfo = self.marionette.execute_script(
|
loginInfo = self.runAsyncCode(
|
||||||
"""
|
"""
|
||||||
let ary = Services.logins.findLogins(
|
let [resolve] = arguments;
|
||||||
"test.marionette.mozilla.com",
|
Services.logins.searchLoginsAsync({
|
||||||
"http://test.marionette.mozilla.com/some/form/",
|
origin: "test.marionette.mozilla.com",
|
||||||
null, {});
|
formActionOrigin: "http://test.marionette.mozilla.com/some/form/",
|
||||||
return ary.length ? ary : {username: "null", password: "null"};
|
}).then(ary => resolve(ary.length ? ary : {username: "null", password: "null"}));
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
self.assertEqual(len(loginInfo), 1)
|
self.assertEqual(len(loginInfo), 1)
|
||||||
|
|||||||
@@ -498,11 +498,10 @@ LoginManagerStorage.prototype = {
|
|||||||
if (!this._isLoggedIn) {
|
if (!this._isLoggedIn) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let logins = Services.logins.findLogins(
|
let logins = await Services.logins.searchLoginsAsync({
|
||||||
FXA_PWDMGR_HOST,
|
origin: FXA_PWDMGR_HOST,
|
||||||
null,
|
httpRealm: FXA_PWDMGR_REALM,
|
||||||
FXA_PWDMGR_REALM
|
});
|
||||||
);
|
|
||||||
for (let login of logins) {
|
for (let login of logins) {
|
||||||
Services.logins.removeLogin(login);
|
Services.logins.removeLogin(login);
|
||||||
}
|
}
|
||||||
@@ -554,11 +553,10 @@ LoginManagerStorage.prototype = {
|
|||||||
""
|
""
|
||||||
); // aPasswordField
|
); // aPasswordField
|
||||||
|
|
||||||
let existingLogins = Services.logins.findLogins(
|
let existingLogins = await Services.logins.searchLoginsAsync({
|
||||||
FXA_PWDMGR_HOST,
|
origin: FXA_PWDMGR_HOST,
|
||||||
null,
|
httpRealm: FXA_PWDMGR_REALM,
|
||||||
FXA_PWDMGR_REALM
|
});
|
||||||
);
|
|
||||||
if (existingLogins.length) {
|
if (existingLogins.length) {
|
||||||
Services.logins.modifyLogin(existingLogins[0], login);
|
Services.logins.modifyLogin(existingLogins[0], login);
|
||||||
} else {
|
} else {
|
||||||
@@ -590,11 +588,10 @@ LoginManagerStorage.prototype = {
|
|||||||
throw new this.STORAGE_LOCKED();
|
throw new this.STORAGE_LOCKED();
|
||||||
}
|
}
|
||||||
|
|
||||||
let logins = Services.logins.findLogins(
|
let logins = await Services.logins.searchLoginsAsync({
|
||||||
FXA_PWDMGR_HOST,
|
origin: FXA_PWDMGR_HOST,
|
||||||
null,
|
httpRealm: FXA_PWDMGR_REALM,
|
||||||
FXA_PWDMGR_REALM
|
});
|
||||||
);
|
|
||||||
if (!logins.length) {
|
if (!logins.length) {
|
||||||
// This could happen if the MP was locked when we wrote the data.
|
// This could happen if the MP was locked when we wrote the data.
|
||||||
log.info("Can't find any credentials in the login manager");
|
log.info("Can't find any credentials in the login manager");
|
||||||
|
|||||||
@@ -29,12 +29,11 @@ function setLoginMgrLoggedInState(loggedIn) {
|
|||||||
|
|
||||||
initTestLogging("Trace");
|
initTestLogging("Trace");
|
||||||
|
|
||||||
function getLoginMgrData() {
|
async function getLoginMgrData() {
|
||||||
let logins = Services.logins.findLogins(
|
let logins = await Services.logins.searchLoginsAsync({
|
||||||
FXA_PWDMGR_HOST,
|
origin: FXA_PWDMGR_HOST,
|
||||||
null,
|
httpRealm: FXA_PWDMGR_REALM,
|
||||||
FXA_PWDMGR_REALM
|
});
|
||||||
);
|
|
||||||
if (!logins.length) {
|
if (!logins.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -114,7 +113,7 @@ add_task(async function test_simple() {
|
|||||||
"scopedKeys not stored in clear text"
|
"scopedKeys not stored in clear text"
|
||||||
);
|
);
|
||||||
|
|
||||||
let login = getLoginMgrData();
|
let login = await getLoginMgrData();
|
||||||
Assert.strictEqual(login.username, creds.uid, "uid used for username");
|
Assert.strictEqual(login.username, creds.uid, "uid used for username");
|
||||||
let loginData = JSON.parse(login.password);
|
let loginData = JSON.parse(login.password);
|
||||||
Assert.strictEqual(
|
Assert.strictEqual(
|
||||||
@@ -139,7 +138,7 @@ add_task(async function test_simple() {
|
|||||||
|
|
||||||
await fxa.signOut(/* localOnly = */ true);
|
await fxa.signOut(/* localOnly = */ true);
|
||||||
Assert.strictEqual(
|
Assert.strictEqual(
|
||||||
getLoginMgrData(),
|
await getLoginMgrData(),
|
||||||
null,
|
null,
|
||||||
"login mgr data deleted on logout"
|
"login mgr data deleted on logout"
|
||||||
);
|
);
|
||||||
@@ -158,7 +157,11 @@ add_task(async function test_MPLocked() {
|
|||||||
verified: true,
|
verified: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.strictEqual(getLoginMgrData(), null, "no login mgr at the start");
|
Assert.strictEqual(
|
||||||
|
await getLoginMgrData(),
|
||||||
|
null,
|
||||||
|
"no login mgr at the start"
|
||||||
|
);
|
||||||
// tell the storage that the MP is locked.
|
// tell the storage that the MP is locked.
|
||||||
setLoginMgrLoggedInState(false);
|
setLoginMgrLoggedInState(false);
|
||||||
await fxa._internal.setSignedInUser(creds);
|
await fxa._internal.setSignedInUser(creds);
|
||||||
@@ -189,7 +192,11 @@ add_task(async function test_MPLocked() {
|
|||||||
"scopedKeys not stored in clear text"
|
"scopedKeys not stored in clear text"
|
||||||
);
|
);
|
||||||
|
|
||||||
Assert.strictEqual(getLoginMgrData(), null, "login mgr data doesn't exist");
|
Assert.strictEqual(
|
||||||
|
await getLoginMgrData(),
|
||||||
|
null,
|
||||||
|
"login mgr data doesn't exist"
|
||||||
|
);
|
||||||
await fxa.signOut(/* localOnly = */ true);
|
await fxa.signOut(/* localOnly = */ true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -235,7 +242,7 @@ add_task(async function test_consistentWithMPEdgeCases() {
|
|||||||
await fxa._internal.setSignedInUser(creds2);
|
await fxa._internal.setSignedInUser(creds2);
|
||||||
|
|
||||||
// We should still have creds1 data in the login manager.
|
// We should still have creds1 data in the login manager.
|
||||||
let login = getLoginMgrData();
|
let login = await getLoginMgrData();
|
||||||
Assert.strictEqual(login.username, creds1.uid);
|
Assert.strictEqual(login.username, creds1.uid);
|
||||||
// and that we do have the first scopedKeys in the login manager.
|
// and that we do have the first scopedKeys in the login manager.
|
||||||
Assert.deepEqual(
|
Assert.deepEqual(
|
||||||
@@ -264,7 +271,11 @@ add_task(async function test_consistentWithMPEdgeCases() {
|
|||||||
// the login manager.
|
// the login manager.
|
||||||
add_task(async function test_uidMigration() {
|
add_task(async function test_uidMigration() {
|
||||||
setLoginMgrLoggedInState(true);
|
setLoginMgrLoggedInState(true);
|
||||||
Assert.strictEqual(getLoginMgrData(), null, "expect no logins at the start");
|
Assert.strictEqual(
|
||||||
|
await getLoginMgrData(),
|
||||||
|
null,
|
||||||
|
"expect no logins at the start"
|
||||||
|
);
|
||||||
|
|
||||||
// create the login entry using email as a key.
|
// create the login entry using email as a key.
|
||||||
let contents = {
|
let contents = {
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ import {
|
|||||||
} from "resource://services-sync/engines.sys.mjs";
|
} from "resource://services-sync/engines.sys.mjs";
|
||||||
import { Svc, Utils } from "resource://services-sync/util.sys.mjs";
|
import { Svc, Utils } from "resource://services-sync/util.sys.mjs";
|
||||||
|
|
||||||
import { Async } from "resource://services-common/async.sys.mjs";
|
|
||||||
|
|
||||||
// These are valid fields the server could have for a logins record
|
// These are valid fields the server could have for a logins record
|
||||||
// we mainly use this to detect if there are any unknownFields and
|
// we mainly use this to detect if there are any unknownFields and
|
||||||
// store (but don't process) those fields to roundtrip them back
|
// store (but don't process) those fields to roundtrip them back
|
||||||
@@ -164,13 +162,11 @@ PasswordEngine.prototype = {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let logins = this._store.storage.findLogins(
|
let logins = await this._store.storage.searchLoginsAsync({
|
||||||
login.origin,
|
origin: login.origin,
|
||||||
login.formActionOrigin,
|
formActionOrigin: login.formActionOrigin,
|
||||||
login.httpRealm
|
httpRealm: login.httpRealm,
|
||||||
);
|
});
|
||||||
|
|
||||||
await Async.promiseYield(); // Yield back to main thread after synchronous operation.
|
|
||||||
|
|
||||||
// Look for existing logins that match the origin, but ignore the password.
|
// Look for existing logins that match the origin, but ignore the password.
|
||||||
for (let local of logins) {
|
for (let local of logins) {
|
||||||
|
|||||||
@@ -168,7 +168,9 @@ add_task(async function test_password_engine() {
|
|||||||
);
|
);
|
||||||
await Services.logins.addLoginAsync(login);
|
await Services.logins.addLoginAsync(login);
|
||||||
|
|
||||||
let logins = Services.logins.findLogins("https://example.com", "", "");
|
let logins = await Services.logins.searchLoginsAsync({
|
||||||
|
origin: "https://example.com",
|
||||||
|
});
|
||||||
equal(logins.length, 1, "Should find new login in login manager");
|
equal(logins.length, 1, "Should find new login in login manager");
|
||||||
newLogin = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
newLogin = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||||
|
|
||||||
@@ -208,7 +210,9 @@ add_task(async function test_password_engine() {
|
|||||||
props.setProperty("timePasswordChanged", localPasswordChangeTime);
|
props.setProperty("timePasswordChanged", localPasswordChangeTime);
|
||||||
Services.logins.modifyLogin(login, props);
|
Services.logins.modifyLogin(login, props);
|
||||||
|
|
||||||
let logins = Services.logins.findLogins("https://mozilla.com", "", "");
|
let logins = await Services.logins.searchLoginsAsync({
|
||||||
|
origin: "https://mozilla.com",
|
||||||
|
});
|
||||||
equal(logins.length, 1, "Should find old login in login manager");
|
equal(logins.length, 1, "Should find old login in login manager");
|
||||||
oldLogin = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
oldLogin = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||||
equal(oldLogin.timePasswordChanged, localPasswordChangeTime);
|
equal(oldLogin.timePasswordChanged, localPasswordChangeTime);
|
||||||
@@ -240,7 +244,9 @@ add_task(async function test_password_engine() {
|
|||||||
"Should update remote password for newer login"
|
"Should update remote password for newer login"
|
||||||
);
|
);
|
||||||
|
|
||||||
let logins = Services.logins.findLogins("https://mozilla.com", "", "");
|
let logins = await Services.logins.searchLoginsAsync({
|
||||||
|
origin: "https://mozilla.com",
|
||||||
|
});
|
||||||
equal(
|
equal(
|
||||||
logins[0].password,
|
logins[0].password,
|
||||||
"n3wpa55",
|
"n3wpa55",
|
||||||
@@ -372,7 +378,6 @@ add_task(async function test_sync_outgoing() {
|
|||||||
_("Remove the login");
|
_("Remove the login");
|
||||||
equal(collection.count(), 1);
|
equal(collection.count(), 1);
|
||||||
equal(Services.logins.countLogins("", "", ""), 2);
|
equal(Services.logins.countLogins("", "", ""), 2);
|
||||||
equal(Services.logins.findLogins("", "", "").length, 2);
|
|
||||||
equal((await Services.logins.getAllLogins()).length, 2);
|
equal((await Services.logins.getAllLogins()).length, 2);
|
||||||
ok(await engine._store.itemExists(guid));
|
ok(await engine._store.itemExists(guid));
|
||||||
|
|
||||||
@@ -401,7 +406,6 @@ add_task(async function test_sync_outgoing() {
|
|||||||
|
|
||||||
// All of these should not include the deleted login. Only the FxA password should exist.
|
// All of these should not include the deleted login. Only the FxA password should exist.
|
||||||
equal(Services.logins.countLogins("", "", ""), 1);
|
equal(Services.logins.countLogins("", "", ""), 1);
|
||||||
equal(Services.logins.findLogins("", "", "").length, 1);
|
|
||||||
equal((await Services.logins.getAllLogins()).length, 1);
|
equal((await Services.logins.getAllLogins()).length, 1);
|
||||||
ok(!(await engine._store.itemExists(guid)));
|
ok(!(await engine._store.itemExists(guid)));
|
||||||
|
|
||||||
@@ -457,7 +461,9 @@ add_task(async function test_sync_incoming() {
|
|||||||
_("Perform sync when remote login has been added");
|
_("Perform sync when remote login has been added");
|
||||||
await sync_engine_and_validate_telem(engine, false);
|
await sync_engine_and_validate_telem(engine, false);
|
||||||
|
|
||||||
let logins = Services.logins.findLogins("https://www.example.com", "", "");
|
let logins = await Services.logins.searchLoginsAsync({
|
||||||
|
origin: "https://www.example.com",
|
||||||
|
});
|
||||||
equal(logins.length, 1);
|
equal(logins.length, 1);
|
||||||
|
|
||||||
equal(logins[0].QueryInterface(Ci.nsILoginMetaInfo).guid, guid1);
|
equal(logins[0].QueryInterface(Ci.nsILoginMetaInfo).guid, guid1);
|
||||||
@@ -482,7 +488,9 @@ add_task(async function test_sync_incoming() {
|
|||||||
await engine.setLastSync(newTime / 1000 - 30);
|
await engine.setLastSync(newTime / 1000 - 30);
|
||||||
await sync_engine_and_validate_telem(engine, false);
|
await sync_engine_and_validate_telem(engine, false);
|
||||||
|
|
||||||
logins = Services.logins.findLogins("https://www.example.com", "", "");
|
logins = await Services.logins.searchLoginsAsync({
|
||||||
|
origin: "https://www.example.com",
|
||||||
|
});
|
||||||
equal(logins.length, 1);
|
equal(logins.length, 1);
|
||||||
|
|
||||||
details.password = "alpaca";
|
details.password = "alpaca";
|
||||||
@@ -508,7 +516,9 @@ add_task(async function test_sync_incoming() {
|
|||||||
await engine.setLastSync(newTime / 1000 - 30);
|
await engine.setLastSync(newTime / 1000 - 30);
|
||||||
await sync_engine_and_validate_telem(engine, false);
|
await sync_engine_and_validate_telem(engine, false);
|
||||||
|
|
||||||
logins = Services.logins.findLogins("https://www.example.com", "", "");
|
logins = await Services.logins.searchLoginsAsync({
|
||||||
|
origin: "https://www.example.com",
|
||||||
|
});
|
||||||
equal(logins.length, 1);
|
equal(logins.length, 1);
|
||||||
|
|
||||||
details.username = "guanaco";
|
details.username = "guanaco";
|
||||||
@@ -534,7 +544,9 @@ add_task(async function test_sync_incoming() {
|
|||||||
await engine.setLastSync(newTime / 1000 - 30);
|
await engine.setLastSync(newTime / 1000 - 30);
|
||||||
await sync_engine_and_validate_telem(engine, false);
|
await sync_engine_and_validate_telem(engine, false);
|
||||||
|
|
||||||
logins = Services.logins.findLogins("https://www.example.com", "", "");
|
logins = await Services.logins.searchLoginsAsync({
|
||||||
|
origin: "https://www.example.com",
|
||||||
|
});
|
||||||
equal(logins.length, 0);
|
equal(logins.length, 0);
|
||||||
} finally {
|
} finally {
|
||||||
await cleanup(engine, server);
|
await cleanup(engine, server);
|
||||||
@@ -574,7 +586,9 @@ add_task(async function test_sync_incoming_deleted() {
|
|||||||
_("Perform sync when remote login has been deleted");
|
_("Perform sync when remote login has been deleted");
|
||||||
await sync_engine_and_validate_telem(engine, false);
|
await sync_engine_and_validate_telem(engine, false);
|
||||||
|
|
||||||
let logins = Services.logins.findLogins("https://www.example.org", "", "");
|
let logins = await Services.logins.searchLoginsAsync({
|
||||||
|
origin: "https://www.example.com",
|
||||||
|
});
|
||||||
equal(logins.length, 0);
|
equal(logins.length, 0);
|
||||||
ok(!(await engine._store.getAllIDs())[guid1]);
|
ok(!(await engine._store.getAllIDs())[guid1]);
|
||||||
ok(!(await engine._store.itemExists(guid1)));
|
ok(!(await engine._store.itemExists(guid1)));
|
||||||
@@ -631,7 +645,9 @@ add_task(async function test_sync_incoming_deleted_localchanged_remotenewer() {
|
|||||||
);
|
);
|
||||||
await sync_engine_and_validate_telem(engine, false);
|
await sync_engine_and_validate_telem(engine, false);
|
||||||
|
|
||||||
let logins = Services.logins.findLogins("http://mozilla.com", "", "");
|
let logins = await Services.logins.searchLoginsAsync({
|
||||||
|
origin: "https://mozilla.com",
|
||||||
|
});
|
||||||
equal(logins.length, 0);
|
equal(logins.length, 0);
|
||||||
ok(await engine._store.getAllIDs());
|
ok(await engine._store.getAllIDs());
|
||||||
} finally {
|
} finally {
|
||||||
@@ -687,7 +703,9 @@ add_task(async function test_sync_incoming_deleted_localchanged_localnewer() {
|
|||||||
);
|
);
|
||||||
await sync_engine_and_validate_telem(engine, false);
|
await sync_engine_and_validate_telem(engine, false);
|
||||||
|
|
||||||
let logins = Services.logins.findLogins("http://www.mozilla.com", "", "");
|
let logins = await Services.logins.searchLoginsAsync({
|
||||||
|
origin: "http://www.mozilla.com",
|
||||||
|
});
|
||||||
equal(logins.length, 1);
|
equal(logins.length, 1);
|
||||||
equal(logins[0].password, "cheetah");
|
equal(logins[0].password, "cheetah");
|
||||||
equal(logins[0].syncCounter, 0);
|
equal(logins[0].syncCounter, 0);
|
||||||
@@ -734,7 +752,9 @@ add_task(async function test_password_dupe() {
|
|||||||
_("Perform sync");
|
_("Perform sync");
|
||||||
await sync_engine_and_validate_telem(engine, true);
|
await sync_engine_and_validate_telem(engine, true);
|
||||||
|
|
||||||
let logins = Services.logins.findLogins("https://www.example.com", "", "");
|
let logins = await Services.logins.searchLoginsAsync({
|
||||||
|
origin: "https://www.example.com",
|
||||||
|
});
|
||||||
|
|
||||||
equal(logins.length, 1);
|
equal(logins.length, 1);
|
||||||
equal(logins[0].QueryInterface(Ci.nsILoginMetaInfo).guid, guid2);
|
equal(logins[0].QueryInterface(Ci.nsILoginMetaInfo).guid, guid2);
|
||||||
@@ -788,11 +808,9 @@ add_task(async function test_updated_null_password_sync() {
|
|||||||
_("Perform sync");
|
_("Perform sync");
|
||||||
await sync_engine_and_validate_telem(engine, false);
|
await sync_engine_and_validate_telem(engine, false);
|
||||||
|
|
||||||
let logins = Services.logins.findLogins(
|
let logins = await Services.logins.searchLoginsAsync({
|
||||||
"https://www.nullupdateexample.com",
|
origin: "https://www.nullupdateexample.com",
|
||||||
"",
|
});
|
||||||
""
|
|
||||||
);
|
|
||||||
|
|
||||||
equal(logins.length, 1);
|
equal(logins.length, 1);
|
||||||
equal(logins[0].QueryInterface(Ci.nsILoginMetaInfo).guid, guid1);
|
equal(logins[0].QueryInterface(Ci.nsILoginMetaInfo).guid, guid1);
|
||||||
@@ -845,11 +863,9 @@ add_task(async function test_updated_undefined_password_sync() {
|
|||||||
_("Perform sync");
|
_("Perform sync");
|
||||||
await sync_engine_and_validate_telem(engine, false);
|
await sync_engine_and_validate_telem(engine, false);
|
||||||
|
|
||||||
let logins = Services.logins.findLogins(
|
let logins = await Services.logins.searchLoginsAsync({
|
||||||
"https://www.undefinedupdateexample.com",
|
origin: "https://www.undefinedupdateexample.com",
|
||||||
"",
|
});
|
||||||
""
|
|
||||||
);
|
|
||||||
|
|
||||||
equal(logins.length, 1);
|
equal(logins.length, 1);
|
||||||
equal(logins[0].QueryInterface(Ci.nsILoginMetaInfo).guid, guid1);
|
equal(logins[0].QueryInterface(Ci.nsILoginMetaInfo).guid, guid1);
|
||||||
@@ -887,7 +903,9 @@ add_task(async function test_new_null_password_sync() {
|
|||||||
_("Perform sync");
|
_("Perform sync");
|
||||||
await sync_engine_and_validate_telem(engine, false);
|
await sync_engine_and_validate_telem(engine, false);
|
||||||
|
|
||||||
let logins = Services.logins.findLogins("https://www.example.com", "", "");
|
let logins = await Services.logins.searchLoginsAsync({
|
||||||
|
origin: "https://www.example.com",
|
||||||
|
});
|
||||||
|
|
||||||
equal(logins.length, 1);
|
equal(logins.length, 1);
|
||||||
notEqual(logins[0].QueryInterface(Ci.nsILoginMetaInfo).username, null);
|
notEqual(logins[0].QueryInterface(Ci.nsILoginMetaInfo).username, null);
|
||||||
@@ -927,7 +945,9 @@ add_task(async function test_new_undefined_password_sync() {
|
|||||||
_("Perform sync");
|
_("Perform sync");
|
||||||
await sync_engine_and_validate_telem(engine, false);
|
await sync_engine_and_validate_telem(engine, false);
|
||||||
|
|
||||||
let logins = Services.logins.findLogins("https://www.example.com", "", "");
|
let logins = await Services.logins.searchLoginsAsync({
|
||||||
|
origin: "https://www.example.com",
|
||||||
|
});
|
||||||
|
|
||||||
equal(logins.length, 1);
|
equal(logins.length, 1);
|
||||||
notEqual(logins[0].QueryInterface(Ci.nsILoginMetaInfo).username, null);
|
notEqual(logins[0].QueryInterface(Ci.nsILoginMetaInfo).username, null);
|
||||||
@@ -1002,7 +1022,9 @@ add_task(async function test_roundtrip_unknown_fields() {
|
|||||||
props.setProperty("timePasswordChanged", localPasswordChangeTime);
|
props.setProperty("timePasswordChanged", localPasswordChangeTime);
|
||||||
Services.logins.modifyLogin(login, props);
|
Services.logins.modifyLogin(login, props);
|
||||||
|
|
||||||
let logins = Services.logins.findLogins("https://mozilla.com", "", "");
|
let logins = await Services.logins.searchLoginsAsync({
|
||||||
|
origin: "https://mozilla.com",
|
||||||
|
});
|
||||||
equal(logins.length, 1, "Should find old login in login manager");
|
equal(logins.length, 1, "Should find old login in login manager");
|
||||||
oldLogin = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
oldLogin = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||||
equal(oldLogin.timePasswordChanged, localPasswordChangeTime);
|
equal(oldLogin.timePasswordChanged, localPasswordChangeTime);
|
||||||
@@ -1032,7 +1054,9 @@ add_task(async function test_roundtrip_unknown_fields() {
|
|||||||
try {
|
try {
|
||||||
await sync_engine_and_validate_telem(engine, false);
|
await sync_engine_and_validate_telem(engine, false);
|
||||||
|
|
||||||
let logins = Services.logins.findLogins("https://mozilla.com", "", "");
|
let logins = await Services.logins.searchLoginsAsync({
|
||||||
|
origin: "https://mozilla.com",
|
||||||
|
});
|
||||||
equal(
|
equal(
|
||||||
logins[0].password,
|
logins[0].password,
|
||||||
"n3wpa55",
|
"n3wpa55",
|
||||||
|
|||||||
@@ -24,11 +24,10 @@ async function checkRecord(
|
|||||||
let engine = Service.engineManager.get("passwords");
|
let engine = Service.engineManager.get("passwords");
|
||||||
let store = engine._store;
|
let store = engine._store;
|
||||||
|
|
||||||
let logins = Services.logins.findLogins(
|
let logins = await Services.logins.searchLoginsAsync({
|
||||||
record.hostname,
|
origin: record.hostname,
|
||||||
record.formSubmitURL,
|
formActionOrigin: record.formSubmitURL,
|
||||||
null
|
});
|
||||||
);
|
|
||||||
|
|
||||||
_("Record" + name + ":" + JSON.stringify(logins));
|
_("Record" + name + ":" + JSON.stringify(logins));
|
||||||
_("Count" + name + ":" + logins.length);
|
_("Count" + name + ":" + logins.length);
|
||||||
@@ -350,16 +349,15 @@ add_task(async function run_test() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Only the good record makes it to Services.logins.
|
// Only the good record makes it to Services.logins.
|
||||||
let badLogins = Services.logins.findLogins(
|
let badLogins = await Services.logins.searchLoginsAsync({
|
||||||
recordA.hostname,
|
origin: recordA.hostname,
|
||||||
recordA.formSubmitURL,
|
formActionOrigin: recordA.formSubmitURL,
|
||||||
recordA.httpRealm
|
httpRealm: recordA.httpRealm,
|
||||||
);
|
});
|
||||||
let goodLogins = Services.logins.findLogins(
|
let goodLogins = await Services.logins.searchLoginsAsync({
|
||||||
recordB.hostname,
|
origin: recordB.hostname,
|
||||||
recordB.formSubmitURL,
|
formActionOrigin: recordB.formSubmitURL,
|
||||||
null
|
});
|
||||||
);
|
|
||||||
|
|
||||||
_("Bad: " + JSON.stringify(badLogins));
|
_("Bad: " + JSON.stringify(badLogins));
|
||||||
_("Good: " + JSON.stringify(goodLogins));
|
_("Good: " + JSON.stringify(goodLogins));
|
||||||
|
|||||||
@@ -112,12 +112,12 @@ Password.prototype = {
|
|||||||
*
|
*
|
||||||
* @return the guid of the password if found, otherwise -1
|
* @return the guid of the password if found, otherwise -1
|
||||||
*/
|
*/
|
||||||
Find() {
|
async Find() {
|
||||||
let logins = Services.logins.findLogins(
|
let logins = await Services.logins.searchLoginsAsync({
|
||||||
this.props.hostname,
|
origin: this.props.hostname,
|
||||||
this.props.submitURL,
|
formActionOrigin: this.props.submitURL,
|
||||||
this.props.realm
|
httpRealm: this.props.realm,
|
||||||
);
|
});
|
||||||
for (var i = 0; i < logins.length; i++) {
|
for (var i = 0; i < logins.length; i++) {
|
||||||
if (
|
if (
|
||||||
logins[i].username == this.props.username &&
|
logins[i].username == this.props.username &&
|
||||||
|
|||||||
@@ -464,19 +464,19 @@ export var TPS = {
|
|||||||
break;
|
break;
|
||||||
case ACTION_VERIFY:
|
case ACTION_VERIFY:
|
||||||
lazy.Logger.AssertTrue(
|
lazy.Logger.AssertTrue(
|
||||||
passwordOb.Find() != -1,
|
(await passwordOb.Find()) != -1,
|
||||||
"password not found"
|
"password not found"
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case ACTION_VERIFY_NOT:
|
case ACTION_VERIFY_NOT:
|
||||||
lazy.Logger.AssertTrue(
|
lazy.Logger.AssertTrue(
|
||||||
passwordOb.Find() == -1,
|
(await passwordOb.Find()) == -1,
|
||||||
"password found, but it shouldn't exist"
|
"password found, but it shouldn't exist"
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case ACTION_DELETE:
|
case ACTION_DELETE:
|
||||||
lazy.Logger.AssertTrue(
|
lazy.Logger.AssertTrue(
|
||||||
passwordOb.Find() != -1,
|
(await passwordOb.Find()) != -1,
|
||||||
"password not found"
|
"password not found"
|
||||||
);
|
);
|
||||||
passwordOb.Remove();
|
passwordOb.Remove();
|
||||||
@@ -484,7 +484,7 @@ export var TPS = {
|
|||||||
case ACTION_MODIFY:
|
case ACTION_MODIFY:
|
||||||
if (passwordOb.updateProps != null) {
|
if (passwordOb.updateProps != null) {
|
||||||
lazy.Logger.AssertTrue(
|
lazy.Logger.AssertTrue(
|
||||||
passwordOb.Find() != -1,
|
(await passwordOb.Find()) != -1,
|
||||||
"password not found"
|
"password not found"
|
||||||
);
|
);
|
||||||
passwordOb.Update();
|
passwordOb.Update();
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ function check_disabled_host(aHost, aIsDisabled) {
|
|||||||
* The host to add the login for.
|
* The host to add the login for.
|
||||||
*/
|
*/
|
||||||
async function add_login(aHost) {
|
async function add_login(aHost) {
|
||||||
check_login_exists(aHost, false);
|
await check_login_exists(aHost, false);
|
||||||
let login = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(
|
let login = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(
|
||||||
Ci.nsILoginInfo
|
Ci.nsILoginInfo
|
||||||
);
|
);
|
||||||
@@ -122,7 +122,7 @@ async function add_login(aHost) {
|
|||||||
LOGIN_PASSWORD_FIELD
|
LOGIN_PASSWORD_FIELD
|
||||||
);
|
);
|
||||||
await Services.logins.addLoginAsync(login);
|
await Services.logins.addLoginAsync(login);
|
||||||
check_login_exists(aHost, true);
|
await check_login_exists(aHost, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -133,8 +133,8 @@ async function add_login(aHost) {
|
|||||||
* @param aExists
|
* @param aExists
|
||||||
* True if the login should exist, false otherwise.
|
* True if the login should exist, false otherwise.
|
||||||
*/
|
*/
|
||||||
function check_login_exists(aHost, aExists) {
|
async function check_login_exists(aHost, aExists) {
|
||||||
let logins = Services.logins.findLogins(aHost, "", null);
|
let logins = await Services.logins.searchLoginsAsync({ origin: aHost });
|
||||||
Assert.equal(logins.length, aExists ? 1 : 0);
|
Assert.equal(logins.length, aExists ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,24 +314,24 @@ async function test_login_manager_logins_cleared_with_direct_match() {
|
|||||||
const TEST_HOST = "http://mozilla.org";
|
const TEST_HOST = "http://mozilla.org";
|
||||||
await add_login(TEST_HOST);
|
await add_login(TEST_HOST);
|
||||||
await ForgetAboutSite.removeDataFromDomain("mozilla.org");
|
await ForgetAboutSite.removeDataFromDomain("mozilla.org");
|
||||||
check_login_exists(TEST_HOST, true);
|
await check_login_exists(TEST_HOST, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function test_login_manager_logins_cleared_with_subdomain() {
|
async function test_login_manager_logins_cleared_with_subdomain() {
|
||||||
const TEST_HOST = "http://www.mozilla.org";
|
const TEST_HOST = "http://www.mozilla.org";
|
||||||
await add_login(TEST_HOST);
|
await add_login(TEST_HOST);
|
||||||
await ForgetAboutSite.removeDataFromDomain("mozilla.org");
|
await ForgetAboutSite.removeDataFromDomain("mozilla.org");
|
||||||
check_login_exists(TEST_HOST, true);
|
await check_login_exists(TEST_HOST, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function test_login_manager_logins_not_cleared_with_uri_contains_domain() {
|
async function test_login_manager_logins_not_cleared_with_uri_contains_domain() {
|
||||||
const TEST_HOST = "http://ilovemozilla.org";
|
const TEST_HOST = "http://ilovemozilla.org";
|
||||||
await add_login(TEST_HOST);
|
await add_login(TEST_HOST);
|
||||||
await ForgetAboutSite.removeDataFromDomain("mozilla.org");
|
await ForgetAboutSite.removeDataFromDomain("mozilla.org");
|
||||||
check_login_exists(TEST_HOST, true);
|
await check_login_exists(TEST_HOST, true);
|
||||||
|
|
||||||
Services.logins.removeAllUserFacingLogins();
|
Services.logins.removeAllUserFacingLogins();
|
||||||
check_login_exists(TEST_HOST, false);
|
await check_login_exists(TEST_HOST, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function test_login_manager_disabled_hosts_cleared_base_domain() {
|
async function test_login_manager_disabled_hosts_cleared_base_domain() {
|
||||||
|
|||||||
@@ -171,14 +171,14 @@ class ImportRowProcessor {
|
|||||||
* A login object.
|
* A login object.
|
||||||
* @returns {boolean} True if the entry is similar or identical to another previously processed entry, false otherwise.
|
* @returns {boolean} True if the entry is similar or identical to another previously processed entry, false otherwise.
|
||||||
*/
|
*/
|
||||||
checkConflictingWithExistingLogins(login) {
|
async checkConflictingWithExistingLogins(login) {
|
||||||
// While here we're passing formActionOrigin and httpRealm, they could be empty/null and get
|
// While here we're passing formActionOrigin and httpRealm, they could be empty/null and get
|
||||||
// ignored in that case, leading to multiple logins for the same username.
|
// ignored in that case, leading to multiple logins for the same username.
|
||||||
let existingLogins = Services.logins.findLogins(
|
let existingLogins = await Services.logins.searchLoginsAsync({
|
||||||
login.origin,
|
origin: login.origin,
|
||||||
login.formActionOrigin,
|
httpRealm: login.httpRealm,
|
||||||
login.httpRealm
|
});
|
||||||
);
|
|
||||||
// Check for an existing login that matches *including* the password.
|
// Check for an existing login that matches *including* the password.
|
||||||
// If such a login exists, we do not need to add a new login.
|
// If such a login exists, we do not need to add a new login.
|
||||||
if (
|
if (
|
||||||
@@ -1498,7 +1498,7 @@ export const LoginHelper = {
|
|||||||
if (processor.checkConflictingOriginWithPreviousRows(login)) {
|
if (processor.checkConflictingOriginWithPreviousRows(login)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (processor.checkConflictingWithExistingLogins(login)) {
|
if (await processor.checkConflictingWithExistingLogins(login)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
processor.addLoginToSummary(login, "added");
|
processor.addLoginToSummary(login, "added");
|
||||||
|
|||||||
@@ -417,7 +417,13 @@ LoginManagerAuthPrompter.prototype = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Look for existing logins.
|
// Look for existing logins.
|
||||||
foundLogins = Services.logins.findLogins(origin, null, realm);
|
// We don't use searchLoginsAsync here and in asyncPromptPassword
|
||||||
|
// because of bug 1848682
|
||||||
|
let matchData = lazy.LoginHelper.newPropertyBag({
|
||||||
|
origin,
|
||||||
|
httpRealm: realm,
|
||||||
|
});
|
||||||
|
foundLogins = Services.logins.searchLogins(matchData);
|
||||||
|
|
||||||
// XXX Like the original code, we can't deal with multiple
|
// XXX Like the original code, we can't deal with multiple
|
||||||
// account selection. (bug 227632)
|
// account selection. (bug 227632)
|
||||||
@@ -531,7 +537,11 @@ LoginManagerAuthPrompter.prototype = {
|
|||||||
Services.logins.getLoginSavingEnabled(origin);
|
Services.logins.getLoginSavingEnabled(origin);
|
||||||
if (!aPassword.value) {
|
if (!aPassword.value) {
|
||||||
// Look for existing logins.
|
// Look for existing logins.
|
||||||
var foundLogins = Services.logins.findLogins(origin, null, realm);
|
let matchData = lazy.LoginHelper.newPropertyBag({
|
||||||
|
origin,
|
||||||
|
httpRealm: realm,
|
||||||
|
});
|
||||||
|
let foundLogins = Services.logins.searchLogins(matchData);
|
||||||
|
|
||||||
// XXX Like the original code, we can't deal with multiple
|
// XXX Like the original code, we can't deal with multiple
|
||||||
// account selection (bug 227632). We can deal with finding the
|
// account selection (bug 227632). We can deal with finding the
|
||||||
|
|||||||
@@ -195,7 +195,8 @@ interface nsILoginManager : nsISupports {
|
|||||||
* Search for logins matching the specified criteria. Called when looking
|
* Search for logins matching the specified criteria. Called when looking
|
||||||
* for logins that might be applicable to a form or authentication request.
|
* for logins that might be applicable to a form or authentication request.
|
||||||
*
|
*
|
||||||
* @deprecated Use `searchLoginsAsync` instead.
|
* @deprecated Use `searchLoginsAsync` instead. This function is retained
|
||||||
|
* for Thunderbird compatibility.
|
||||||
*
|
*
|
||||||
* @param aOrigin
|
* @param aOrigin
|
||||||
* The origin to restrict searches to. For example: "http://www.site.com".
|
* The origin to restrict searches to. For example: "http://www.site.com".
|
||||||
|
|||||||
@@ -286,12 +286,12 @@ export class LoginManagerStorage_json {
|
|||||||
const resultLogins = [];
|
const resultLogins = [];
|
||||||
for (const [login, encryptedLogin] of encryptedLogins) {
|
for (const [login, encryptedLogin] of encryptedLogins) {
|
||||||
// check for duplicates
|
// check for duplicates
|
||||||
const { origin, formActionOrigin, httpRealm } = login;
|
let loginData = {
|
||||||
const existingLogins = this.findLogins(
|
origin: login.origin,
|
||||||
origin,
|
httpRealm: login.httpRealm,
|
||||||
formActionOrigin,
|
};
|
||||||
httpRealm
|
const existingLogins = await Services.logins.searchLoginsAsync(loginData);
|
||||||
);
|
|
||||||
const matchingLogin = existingLogins.find(l => login.matches(l, true));
|
const matchingLogin = existingLogins.find(l => login.matches(l, true));
|
||||||
if (matchingLogin) {
|
if (matchingLogin) {
|
||||||
if (continueOnDuplicates) {
|
if (continueOnDuplicates) {
|
||||||
@@ -372,10 +372,13 @@ export class LoginManagerStorage_json {
|
|||||||
|
|
||||||
// Look for an existing entry in case key properties changed.
|
// Look for an existing entry in case key properties changed.
|
||||||
if (!newLogin.matches(oldLogin, true)) {
|
if (!newLogin.matches(oldLogin, true)) {
|
||||||
let logins = this.findLogins(
|
let loginData = {
|
||||||
newLogin.origin,
|
origin: newLogin.origin,
|
||||||
newLogin.formActionOrigin,
|
httpRealm: newLogin.httpRealm,
|
||||||
newLogin.httpRealm
|
};
|
||||||
|
|
||||||
|
let logins = this.searchLogins(
|
||||||
|
lazy.LoginHelper.newPropertyBag(loginData)
|
||||||
);
|
);
|
||||||
|
|
||||||
let matchingLogin = logins.find(login => newLogin.matches(login, true));
|
let matchingLogin = logins.find(login => newLogin.matches(login, true));
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ let chromeScript = runInParent(() => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
addMessageListener("getTimeLastUsed", () => {
|
addMessageListener("getTimeLastUsed", async () => {
|
||||||
let logins = Services.logins.findLogins(mozproxyURL, null, "Proxy Realm");
|
let logins = await Services.logins.searchLoginsAsync({ origin: mozproxyURL, httpRealm: "Proxy Realm"});
|
||||||
return logins[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed;
|
return logins[0].QueryInterface(Ci.nsILoginMetaInfo).timeLastUsed;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ add_task(async function test_addLogin_wildcard() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies that findLogins, searchLogins, and countLogins include all logins
|
* Verifies that searchLogins and countLogins include all logins
|
||||||
* that have an empty formActionOrigin in the store, even when a formActionOrigin is
|
* that have an empty formActionOrigin in the store, even when a formActionOrigin is
|
||||||
* specified.
|
* specified.
|
||||||
*/
|
*/
|
||||||
@@ -76,11 +76,6 @@ add_task(function test_search_all_wildcard() {
|
|||||||
});
|
});
|
||||||
Assert.equal(Services.logins.searchLogins(matchData).length, 2);
|
Assert.equal(Services.logins.searchLogins(matchData).length, 2);
|
||||||
|
|
||||||
Assert.equal(
|
|
||||||
Services.logins.findLogins("", "http://www.example.com", null).length,
|
|
||||||
2
|
|
||||||
);
|
|
||||||
|
|
||||||
Assert.equal(
|
Assert.equal(
|
||||||
Services.logins.countLogins("", "http://www.example.com", null),
|
Services.logins.countLogins("", "http://www.example.com", null),
|
||||||
2
|
2
|
||||||
@@ -90,15 +85,6 @@ add_task(function test_search_all_wildcard() {
|
|||||||
matchData.setProperty("origin", "http://any.example.com");
|
matchData.setProperty("origin", "http://any.example.com");
|
||||||
Assert.equal(Services.logins.searchLogins(matchData).length, 1);
|
Assert.equal(Services.logins.searchLogins(matchData).length, 1);
|
||||||
|
|
||||||
Assert.equal(
|
|
||||||
Services.logins.findLogins(
|
|
||||||
"http://any.example.com",
|
|
||||||
"http://www.example.com",
|
|
||||||
null
|
|
||||||
).length,
|
|
||||||
1
|
|
||||||
);
|
|
||||||
|
|
||||||
Assert.equal(
|
Assert.equal(
|
||||||
Services.logins.countLogins(
|
Services.logins.countLogins(
|
||||||
"http://any.example.com",
|
"http://any.example.com",
|
||||||
|
|||||||
@@ -35,9 +35,8 @@ add_task(async function test_logins_decrypt_failure() {
|
|||||||
|
|
||||||
// These functions don't see the non-decryptable entries anymore.
|
// These functions don't see the non-decryptable entries anymore.
|
||||||
let savedLogins = await Services.logins.getAllLogins();
|
let savedLogins = await Services.logins.getAllLogins();
|
||||||
Assert.equal(savedLogins.length, 0);
|
|
||||||
Assert.equal(savedLogins.length, 0, "getAllLogins length");
|
Assert.equal(savedLogins.length, 0, "getAllLogins length");
|
||||||
Assert.equal(Services.logins.findLogins("", "", "").length, 0);
|
await Assert.rejects(Services.logins.searchLoginsAsync({}), /is required/);
|
||||||
Assert.equal(Services.logins.searchLogins(newPropertyBag()).length, 0);
|
Assert.equal(Services.logins.searchLogins(newPropertyBag()).length, 0);
|
||||||
Assert.throws(
|
Assert.throws(
|
||||||
() => Services.logins.modifyLogin(logins[0], newPropertyBag()),
|
() => Services.logins.modifyLogin(logins[0], newPropertyBag()),
|
||||||
@@ -63,7 +62,11 @@ add_task(async function test_logins_decrypt_failure() {
|
|||||||
|
|
||||||
// Finding logins doesn't return the non-decryptable duplicates.
|
// Finding logins doesn't return the non-decryptable duplicates.
|
||||||
Assert.equal(
|
Assert.equal(
|
||||||
Services.logins.findLogins("http://www.example.com", "", "").length,
|
(
|
||||||
|
await Services.logins.searchLoginsAsync({
|
||||||
|
origin: "http://www.example.com",
|
||||||
|
})
|
||||||
|
).length,
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
let matchData = newPropertyBag({ origin: "http://www.example.com" });
|
let matchData = newPropertyBag({ origin: "http://www.example.com" });
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ const gLooksLikeUUIDRegex = /^\{\w{8}-\w{4}-\w{4}-\w{4}-\w{12}\}$/;
|
|||||||
* the given nsILoginInfo. In case there is more than one login for the
|
* the given nsILoginInfo. In case there is more than one login for the
|
||||||
* origin, the test fails.
|
* origin, the test fails.
|
||||||
*/
|
*/
|
||||||
function retrieveLoginMatching(aLoginInfo) {
|
async function retrieveOriginMatching(origin) {
|
||||||
let logins = Services.logins.findLogins(aLoginInfo.origin, "", "");
|
let logins = await Services.logins.searchLoginsAsync({ origin });
|
||||||
Assert.equal(logins.length, 1);
|
Assert.equal(logins.length, 1);
|
||||||
return logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
return logins[0].QueryInterface(Ci.nsILoginMetaInfo);
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ add_task(async function test_addLogin_metainfo() {
|
|||||||
Assert.equal(gLoginInfo1.timesUsed, 0);
|
Assert.equal(gLoginInfo1.timesUsed, 0);
|
||||||
|
|
||||||
// A login with valid metadata should have been stored.
|
// A login with valid metadata should have been stored.
|
||||||
gLoginMetaInfo1 = retrieveLoginMatching(gLoginInfo1);
|
gLoginMetaInfo1 = await retrieveOriginMatching(gLoginInfo1.origin);
|
||||||
Assert.ok(gLooksLikeUUIDRegex.test(gLoginMetaInfo1.guid));
|
Assert.ok(gLooksLikeUUIDRegex.test(gLoginMetaInfo1.guid));
|
||||||
let creationTime = gLoginMetaInfo1.timeCreated;
|
let creationTime = gLoginMetaInfo1.timeCreated;
|
||||||
LoginTestUtils.assertTimeIsAboutNow(creationTime);
|
LoginTestUtils.assertTimeIsAboutNow(creationTime);
|
||||||
@@ -110,12 +110,12 @@ add_task(async function test_addLogin_metainfo() {
|
|||||||
assertMetaInfoEqual(gLoginInfo2, originalLogin);
|
assertMetaInfoEqual(gLoginInfo2, originalLogin);
|
||||||
|
|
||||||
// A login with the provided metadata should have been stored.
|
// A login with the provided metadata should have been stored.
|
||||||
gLoginMetaInfo2 = retrieveLoginMatching(gLoginInfo2);
|
gLoginMetaInfo2 = await retrieveOriginMatching(gLoginInfo2.origin);
|
||||||
assertMetaInfoEqual(gLoginMetaInfo2, gLoginInfo2);
|
assertMetaInfoEqual(gLoginMetaInfo2, gLoginInfo2);
|
||||||
|
|
||||||
// Add an authentication login to the database before continuing.
|
// Add an authentication login to the database before continuing.
|
||||||
await Services.logins.addLoginAsync(gLoginInfo3);
|
await Services.logins.addLoginAsync(gLoginInfo3);
|
||||||
gLoginMetaInfo3 = retrieveLoginMatching(gLoginInfo3);
|
gLoginMetaInfo3 = await retrieveOriginMatching(gLoginInfo3.origin);
|
||||||
await LoginTestUtils.checkLogins([gLoginInfo1, gLoginInfo2, gLoginInfo3]);
|
await LoginTestUtils.checkLogins([gLoginInfo1, gLoginInfo2, gLoginInfo3]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ add_task(async function test_addLogin_metainfo_duplicate() {
|
|||||||
* Tests that the existing metadata is not changed when modifyLogin is called
|
* Tests that the existing metadata is not changed when modifyLogin is called
|
||||||
* with an nsILoginInfo argument.
|
* with an nsILoginInfo argument.
|
||||||
*/
|
*/
|
||||||
add_task(function test_modifyLogin_nsILoginInfo_metainfo_ignored() {
|
add_task(async function test_modifyLogin_nsILoginInfo_metainfo_ignored() {
|
||||||
let newLoginInfo = gLoginInfo1.clone().QueryInterface(Ci.nsILoginMetaInfo);
|
let newLoginInfo = gLoginInfo1.clone().QueryInterface(Ci.nsILoginMetaInfo);
|
||||||
newLoginInfo.guid = Services.uuid.generateUUID().toString();
|
newLoginInfo.guid = Services.uuid.generateUUID().toString();
|
||||||
newLoginInfo.timeCreated = Date.now();
|
newLoginInfo.timeCreated = Date.now();
|
||||||
@@ -149,14 +149,14 @@ add_task(function test_modifyLogin_nsILoginInfo_metainfo_ignored() {
|
|||||||
newLoginInfo.timesUsed = 12;
|
newLoginInfo.timesUsed = 12;
|
||||||
Services.logins.modifyLogin(gLoginInfo1, newLoginInfo);
|
Services.logins.modifyLogin(gLoginInfo1, newLoginInfo);
|
||||||
|
|
||||||
newLoginInfo = retrieveLoginMatching(gLoginInfo1);
|
newLoginInfo = await retrieveOriginMatching(gLoginInfo1.origin);
|
||||||
assertMetaInfoEqual(newLoginInfo, gLoginMetaInfo1);
|
assertMetaInfoEqual(newLoginInfo, gLoginMetaInfo1);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the modifyLogin function with an nsIProperyBag argument.
|
* Tests the modifyLogin function with an nsIProperyBag argument.
|
||||||
*/
|
*/
|
||||||
add_task(function test_modifyLogin_nsIProperyBag_metainfo() {
|
add_task(async function test_modifyLogin_nsIProperyBag_metainfo() {
|
||||||
// Use a new reference time that is two minutes from now.
|
// Use a new reference time that is two minutes from now.
|
||||||
let newTimeMs = Date.now() + 120000;
|
let newTimeMs = Date.now() + 120000;
|
||||||
let newUUIDValue = Services.uuid.generateUUID().toString();
|
let newUUIDValue = Services.uuid.generateUUID().toString();
|
||||||
@@ -173,7 +173,7 @@ add_task(function test_modifyLogin_nsIProperyBag_metainfo() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
gLoginMetaInfo1 = retrieveLoginMatching(gLoginInfo1);
|
gLoginMetaInfo1 = await retrieveOriginMatching(gLoginInfo1.origin);
|
||||||
Assert.equal(gLoginMetaInfo1.guid, newUUIDValue);
|
Assert.equal(gLoginMetaInfo1.guid, newUUIDValue);
|
||||||
Assert.equal(gLoginMetaInfo1.timeCreated, newTimeMs);
|
Assert.equal(gLoginMetaInfo1.timeCreated, newTimeMs);
|
||||||
Assert.equal(gLoginMetaInfo1.timeLastUsed, newTimeMs + 2);
|
Assert.equal(gLoginMetaInfo1.timeLastUsed, newTimeMs + 2);
|
||||||
@@ -190,7 +190,7 @@ add_task(function test_modifyLogin_nsIProperyBag_metainfo() {
|
|||||||
);
|
);
|
||||||
gLoginInfo2.password = "new password";
|
gLoginInfo2.password = "new password";
|
||||||
|
|
||||||
gLoginMetaInfo2 = retrieveLoginMatching(gLoginInfo2);
|
gLoginMetaInfo2 = await retrieveOriginMatching(gLoginInfo2.origin);
|
||||||
Assert.equal(gLoginMetaInfo2.password, gLoginInfo2.password);
|
Assert.equal(gLoginMetaInfo2.password, gLoginInfo2.password);
|
||||||
Assert.equal(gLoginMetaInfo2.timeCreated, originalLogin.timeCreated);
|
Assert.equal(gLoginMetaInfo2.timeCreated, originalLogin.timeCreated);
|
||||||
Assert.equal(gLoginMetaInfo2.timeLastUsed, originalLogin.timeLastUsed);
|
Assert.equal(gLoginMetaInfo2.timeLastUsed, originalLogin.timeLastUsed);
|
||||||
@@ -207,7 +207,7 @@ add_task(function test_modifyLogin_nsIProperyBag_metainfo() {
|
|||||||
);
|
);
|
||||||
gLoginInfo2.password = "other password";
|
gLoginInfo2.password = "other password";
|
||||||
|
|
||||||
gLoginMetaInfo2 = retrieveLoginMatching(gLoginInfo2);
|
gLoginMetaInfo2 = await retrieveOriginMatching(gLoginInfo2.origin);
|
||||||
Assert.equal(gLoginMetaInfo2.password, gLoginInfo2.password);
|
Assert.equal(gLoginMetaInfo2.password, gLoginInfo2.password);
|
||||||
Assert.equal(gLoginMetaInfo2.timeCreated, originalLogin.timeCreated);
|
Assert.equal(gLoginMetaInfo2.timeCreated, originalLogin.timeCreated);
|
||||||
Assert.equal(gLoginMetaInfo2.timeLastUsed, originalLogin.timeLastUsed);
|
Assert.equal(gLoginMetaInfo2.timeLastUsed, originalLogin.timeLastUsed);
|
||||||
@@ -221,7 +221,7 @@ add_task(function test_modifyLogin_nsIProperyBag_metainfo() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
gLoginMetaInfo2 = retrieveLoginMatching(gLoginInfo2);
|
gLoginMetaInfo2 = await retrieveOriginMatching(gLoginInfo2.origin);
|
||||||
Assert.equal(gLoginMetaInfo2.timeCreated, originalLogin.timeCreated);
|
Assert.equal(gLoginMetaInfo2.timeCreated, originalLogin.timeCreated);
|
||||||
Assert.equal(gLoginMetaInfo2.timeLastUsed, originalLogin.timeLastUsed);
|
Assert.equal(gLoginMetaInfo2.timeLastUsed, originalLogin.timeLastUsed);
|
||||||
Assert.equal(gLoginMetaInfo2.timePasswordChanged, newTimeMs);
|
Assert.equal(gLoginMetaInfo2.timePasswordChanged, newTimeMs);
|
||||||
@@ -289,7 +289,16 @@ add_task(async function test_storage_metainfo() {
|
|||||||
await LoginTestUtils.reloadData();
|
await LoginTestUtils.reloadData();
|
||||||
await LoginTestUtils.checkLogins([gLoginInfo1, gLoginInfo2, gLoginInfo3]);
|
await LoginTestUtils.checkLogins([gLoginInfo1, gLoginInfo2, gLoginInfo3]);
|
||||||
|
|
||||||
assertMetaInfoEqual(retrieveLoginMatching(gLoginInfo1), gLoginMetaInfo1);
|
assertMetaInfoEqual(
|
||||||
assertMetaInfoEqual(retrieveLoginMatching(gLoginInfo2), gLoginMetaInfo2);
|
await retrieveOriginMatching(gLoginInfo1.origin),
|
||||||
assertMetaInfoEqual(retrieveLoginMatching(gLoginInfo3), gLoginMetaInfo3);
|
gLoginMetaInfo1
|
||||||
|
);
|
||||||
|
assertMetaInfoEqual(
|
||||||
|
await retrieveOriginMatching(gLoginInfo2.origin),
|
||||||
|
gLoginMetaInfo2
|
||||||
|
);
|
||||||
|
assertMetaInfoEqual(
|
||||||
|
await retrieveOriginMatching(gLoginInfo3.origin),
|
||||||
|
gLoginMetaInfo3
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Tests methods that find specific logins in the store (findLogins,
|
* Tests methods that find specific logins in the store (searchLogins and countLogins).
|
||||||
* searchLogins, and countLogins).
|
|
||||||
*
|
*
|
||||||
* The getAllLogins method is not tested explicitly here, because it is used by
|
* The getAllLogins method is not tested explicitly here, because it is used by
|
||||||
* all tests to verify additions, removals and modifications to the login store.
|
* all tests to verify additions, removals and modifications to the login store.
|
||||||
@@ -47,11 +46,11 @@ function checkSearchLogins(aQuery, aExpectedCount) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests findLogins, searchLogins, and countLogins with the same query.
|
* Tests searchLogins, and countLogins with the same query.
|
||||||
*
|
*
|
||||||
* @param aQuery
|
* @param aQuery
|
||||||
* The "origin", "formActionOrigin", and "httpRealm" properties of this
|
* The "origin", "formActionOrigin", and "httpRealm" properties of this
|
||||||
* object are passed as parameters to findLogins and countLogins. The
|
* object are passed as parameters to countLogins. The
|
||||||
* same object is then passed to the checkSearchLogins function.
|
* same object is then passed to the checkSearchLogins function.
|
||||||
* @param aExpectedCount
|
* @param aExpectedCount
|
||||||
* Number of logins from the test data that should be found. The actual
|
* Number of logins from the test data that should be found. The actual
|
||||||
@@ -65,7 +64,7 @@ function checkAllSearches(aQuery, aExpectedCount) {
|
|||||||
let expectedLogins = buildExpectedLogins(aQuery);
|
let expectedLogins = buildExpectedLogins(aQuery);
|
||||||
Assert.equal(expectedLogins.length, aExpectedCount);
|
Assert.equal(expectedLogins.length, aExpectedCount);
|
||||||
|
|
||||||
// The findLogins and countLogins functions support wildcard matches by
|
// The countLogins function support wildcard matches by
|
||||||
// specifying empty strings as parameters, while searchLogins requires
|
// specifying empty strings as parameters, while searchLogins requires
|
||||||
// omitting the property entirely.
|
// omitting the property entirely.
|
||||||
let origin = "origin" in aQuery ? aQuery.origin : "";
|
let origin = "origin" in aQuery ? aQuery.origin : "";
|
||||||
@@ -73,10 +72,6 @@ function checkAllSearches(aQuery, aExpectedCount) {
|
|||||||
"formActionOrigin" in aQuery ? aQuery.formActionOrigin : "";
|
"formActionOrigin" in aQuery ? aQuery.formActionOrigin : "";
|
||||||
let httpRealm = "httpRealm" in aQuery ? aQuery.httpRealm : "";
|
let httpRealm = "httpRealm" in aQuery ? aQuery.httpRealm : "";
|
||||||
|
|
||||||
// Test findLogins.
|
|
||||||
let logins = Services.logins.findLogins(origin, formActionOrigin, httpRealm);
|
|
||||||
LoginTestUtils.assertLoginListsEqual(logins, expectedLogins);
|
|
||||||
|
|
||||||
// Test countLogins.
|
// Test countLogins.
|
||||||
let count = Services.logins.countLogins(origin, formActionOrigin, httpRealm);
|
let count = Services.logins.countLogins(origin, formActionOrigin, httpRealm);
|
||||||
Assert.equal(count, expectedLogins.length);
|
Assert.equal(count, expectedLogins.length);
|
||||||
@@ -95,7 +90,7 @@ add_setup(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests findLogins, searchLogins, and countLogins with basic queries.
|
* Tests searchLogins, and countLogins with basic queries.
|
||||||
*/
|
*/
|
||||||
add_task(function test_search_all_basic() {
|
add_task(function test_search_all_basic() {
|
||||||
// Find all logins, using no filters in the search functions.
|
// Find all logins, using no filters in the search functions.
|
||||||
@@ -217,7 +212,7 @@ add_task(function test_search_all_full_case_sensitive() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests findLogins, searchLogins, and countLogins with queries that should
|
* Tests searchLogins, and countLogins with queries that should
|
||||||
* return no values.
|
* return no values.
|
||||||
*/
|
*/
|
||||||
add_task(function test_search_all_empty() {
|
add_task(function test_search_all_empty() {
|
||||||
|
|||||||
Reference in New Issue
Block a user