Bug 1587653 - Include breached logins in about:protections without a Monitor account and if PP is logged in. r=ewright

Also separate the Lockwise/Monitor data collection to map to the cards

Differential Revision: https://phabricator.services.mozilla.com/D85642
This commit is contained in:
Matthew Noorenberghe 2020-08-06 01:17:28 +00:00
Родитель e6e6f0c2ad
Коммит f158fda60e
5 изменённых файлов: 27 добавлений и 33 удалений

Просмотреть файл

@ -150,6 +150,7 @@ class AboutProtectionsParent extends JSWindowActorParent {
*
* @return {{
* numLogins: Number,
* potentiallyBreachedLogins: Number,
* mobileDeviceConnected: Boolean }}
*/
async getLoginData() {
@ -169,6 +170,16 @@ class AboutProtectionsParent extends JSWindowActorParent {
Services.logins.countLogins("", "", "") -
Services.logins.countLogins(FXA_PWDMGR_HOST, null, FXA_PWDMGR_REALM);
let potentiallyBreachedLogins = null;
// Get the stats for number of potentially breached Lockwise passwords
// if the Primary Password isn't locked.
if (userFacingLogins && Services.logins.isLoggedIn) {
const logins = await LoginHelper.getAllUserFacingLogins();
potentiallyBreachedLogins = await LoginBreaches.getPotentialBreachesByLoginGUID(
logins
);
}
let mobileDeviceConnected =
fxAccounts.device.recentDeviceList &&
fxAccounts.device.recentDeviceList.filter(
@ -177,6 +188,9 @@ class AboutProtectionsParent extends JSWindowActorParent {
return {
numLogins: userFacingLogins,
potentiallyBreachedLogins: potentiallyBreachedLogins
? potentiallyBreachedLogins.size
: 0,
mobileDeviceConnected,
};
}
@ -188,7 +202,6 @@ class AboutProtectionsParent extends JSWindowActorParent {
* numBreaches: Number,
* passwords: Number,
* userEmail: String|null,
* potentiallyBreachedLogins: Number,
* error: Boolean }}
* Monitor data.
*/
@ -202,7 +215,6 @@ class AboutProtectionsParent extends JSWindowActorParent {
}
let monitorData = {};
let potentiallyBreachedLogins = null;
let userEmail = null;
let token = await this.getMonitorScopedOAuthToken();
@ -210,14 +222,6 @@ class AboutProtectionsParent extends JSWindowActorParent {
if (token) {
monitorData = await this.fetchUserBreachStats(token);
// Get the stats for number of potentially breached Lockwise passwords if no master
// password is set.
if (!LoginHelper.isMasterPasswordSet()) {
const logins = await LoginHelper.getAllUserFacingLogins();
potentiallyBreachedLogins = await LoginBreaches.getPotentialBreachesByLoginGUID(
logins
);
}
// Send back user's email so the protections report can direct them to the proper
// OAuth flow on Monitor.
const { email } = await fxAccounts.getSignedInUser();
@ -257,9 +261,6 @@ class AboutProtectionsParent extends JSWindowActorParent {
return {
...monitorData,
userEmail,
potentiallyBreachedLogins: potentiallyBreachedLogins
? potentiallyBreachedLogins.size
: 0,
error: !!monitorData.errorMessage,
};
}
@ -369,9 +370,7 @@ class AboutProtectionsParent extends JSWindowActorParent {
return this.getMonitorData();
case "FetchUserLoginsData":
let { potentiallyBreachedLogins } = await this.getMonitorData();
let loginsData = await this.getLoginData();
return { ...loginsData, potentiallyBreachedLogins };
return this.getLoginData();
case "ClearMonitorCache":
monitorResponse = null;

Просмотреть файл

@ -9,11 +9,6 @@ const { AboutProtectionsParent } = ChromeUtils.import(
);
const ABOUT_LOGINS_URL = "about:logins";
let mockMonitorData = {
numBreaches: 2,
numBreachesResolved: 0,
};
add_task(async function testNoLoginsLockwiseCardUI() {
let tab = await BrowserTestUtils.openNewForegroundTab({
url: "about:protections",
@ -231,8 +226,9 @@ add_task(async function testLockwiseCardUIWithBreachedLogins() {
Services.logins.addLogin(TEST_LOGIN1);
info("Mock monitor data with a breached login to test the Lockwise UI");
mockMonitorData.potentiallyBreachedLogins = 1;
AboutProtectionsParent.setTestOverride(mockGetMonitorData(mockMonitorData));
AboutProtectionsParent.setTestOverride(
mockGetLoginDataWithSyncedDevices(false, 1)
);
await reloadTab(tab);
await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
@ -254,8 +250,9 @@ add_task(async function testLockwiseCardUIWithBreachedLogins() {
info(
"Mock monitor data with more than one breached logins to test the Lockwise UI"
);
mockMonitorData.potentiallyBreachedLogins = 2;
AboutProtectionsParent.setTestOverride(mockGetMonitorData(mockMonitorData));
AboutProtectionsParent.setTestOverride(
mockGetLoginDataWithSyncedDevices(false, 2)
);
await reloadTab(tab);
await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
const lockwiseScannedText = content.document.querySelector(

Просмотреть файл

@ -13,7 +13,6 @@ const monitorErrorData = {
};
const mockMonitorData = {
potentiallyBreachedLogins: 8,
numBreaches: 11,
numBreachesResolved: 0,
};

Просмотреть файл

@ -217,11 +217,7 @@ add_task(async function checkTelemetryClickEvents() {
// Add breached logins.
AboutProtectionsParent.setTestOverride(
mockGetMonitorData({
potentiallyBreachedLogins: 4,
numBreaches: 5,
numBreachesResolved: 0,
})
mockGetLoginDataWithSyncedDevices(false, 4)
);
await reloadTab(tab);
await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {

Просмотреть файл

@ -39,11 +39,15 @@ async function reloadTab(tab) {
}
// Used to replace AboutProtectionsHandler.getLoginData in front-end tests.
const mockGetLoginDataWithSyncedDevices = (mobileDeviceConnected = false) => {
const mockGetLoginDataWithSyncedDevices = (
mobileDeviceConnected = false,
potentiallyBreachedLogins = 0
) => {
return {
getLoginData: () => {
return {
numLogins: Services.logins.countLogins("", "", ""),
potentiallyBreachedLogins,
mobileDeviceConnected,
};
},
@ -62,7 +66,6 @@ const mockGetMonitorData = data => {
monitoredEmails: 1,
numBreaches: data.numBreaches,
passwords: 8,
potentiallyBreachedLogins: data.potentiallyBreachedLogins,
numBreachesResolved: data.numBreachesResolved,
passwordsResolved: 1,
error: false,