Bug 1453804 - Ensure sync password validator will ever run r=markh

MozReview-Commit-ID: 8weadIdJHjl

--HG--
extra : rebase_source : c4248fc5408d6daada4681fd0d51937103df5f92
This commit is contained in:
Thom Chiovoloni 2018-04-12 14:40:00 -07:00
Родитель de8c3b42fa
Коммит c67edfba07
4 изменённых файлов: 58 добавлений и 5 удалений

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

@ -232,6 +232,27 @@ class CollectionValidator {
deletedRecords: [...serverDeleted]
};
}
async validate(engine) {
let start = Cu.now();
let clientItems = await this.getClientItems();
let serverItems = await this.getServerItems(engine);
let serverRecordCount = serverItems.length;
let result = await this.compareClientWithServer(clientItems, serverItems);
let end = Cu.now();
let duration = end - start;
engine._log.debug(`Validated ${this.name} in ${duration}ms`);
engine._log.debug(`Problem summary`);
for (let { name, count } of result.problemData.getSummary()) {
engine._log.debug(` ${name}: ${count}`);
}
return {
duration,
version: this.version,
problems: result.problemData,
recordCount: serverRecordCount
};
}
}
// Default to 0, some engines may override.

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

@ -154,6 +154,9 @@ var Doctor = {
}
let validator = engine.getValidator();
if (!validator) {
// This is probably only possible in profile downgrade cases.
log.warn(`engine.getValidator returned null for ${engineName
} but the pref that controls validation is enabled.`);
continue;
}

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

@ -141,7 +141,11 @@ PasswordEngine.prototype = {
changes[id] = info.timePasswordChanged / 1000;
}
return changes;
}
},
getValidator() {
return new PasswordValidator();
},
};
function PasswordStore(name, engine) {
@ -378,10 +382,6 @@ PasswordTracker.prototype = {
}
},
getValidator() {
return new PasswordValidator();
},
async _trackLogin(login) {
if (Utils.getSyncCredentialsHosts().has(login.hostname)) {
// Skip over Weave password/passphrase changes.

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

@ -218,3 +218,32 @@ add_task(async function test_password_dupe() {
}
});
add_task(async function test_sync_password_validation() {
// This test isn't in test_password_validator to avoid duplicating cleanup.
_("Ensure that if a password validation happens, it ends up in the ping");
let engine = Service.engineManager.get("passwords");
let server = await serverForFoo(engine);
await SyncTestingInfrastructure(server);
Svc.Prefs.set("engine.passwords.validation.interval", 0);
Svc.Prefs.set("engine.passwords.validation.percentageChance", 100);
Svc.Prefs.set("engine.passwords.validation.maxRecords", -1);
Svc.Prefs.set("engine.passwords.validation.enabled", true);
try {
let ping = await wait_for_ping(() => Service.sync());
let engineInfo = ping.engines.find(e => e.name == "passwords");
ok(engineInfo, "Engine should be in ping");
let validation = engineInfo.validation;
ok(validation, "Engine should have validation info");
} finally {
await cleanup(engine, server);
}
});