Backed out 2 changesets (bug 1553831) for XPCshell failure in services/settings/test/unit/test_remote_settings.js

Backed out changeset d03a51956262 (bug 1553831)
Backed out changeset 4f62dfaee27f (bug 1553831)
This commit is contained in:
Dorel Luca 2019-05-31 14:43:50 +03:00
parent f8fc1d2bcc
commit 5e31d37927
2 changed files with 10 additions and 107 deletions

View File

@ -25,8 +25,6 @@ ChromeUtils.defineModuleGetter(this, "Utils",
"resource://services-settings/Utils.jsm");
ChromeUtils.defineModuleGetter(this, "Downloader",
"resource://services-settings/Attachments.jsm");
ChromeUtils.defineModuleGetter(this, "ObjectUtils",
"resource://gre/modules/ObjectUtils.jsm");
XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
@ -180,11 +178,6 @@ class RemoteSettingsClient extends EventEmitter {
return this._lastCheckTimePref || `services.settings.${this.bucketName}.${this.collectionName}.last_check`;
}
httpClient() {
const api = new KintoHttpClient(gServerURL);
return api.bucket(this.bucketName).collection(this.collectionName);
}
/**
* Open the underlying Kinto collection, using the appropriate adapter and options.
*/
@ -242,15 +235,9 @@ class RemoteSettingsClient extends EventEmitter {
if (verifySignature) {
console.debug("Verify signature of local data");
const { data: allData } = await kintoCollection.list({ order: "" });
const localRecords = allData.map(r => kintoCollection.cleanLocalFields(r));
const localRecords = data.map(r => kintoCollection.cleanLocalFields(r));
const timestamp = await kintoCollection.db.getLastModified();
let metadata = await kintoCollection.metadata();
if (syncIfEmpty && ObjectUtils.isEmpty(metadata)) {
// No sync occured yet, may have records from dump but no metadata.
console.debug(`Required metadata for ${this.identifier}, fetching from server.`);
metadata = await kintoCollection.pullMetadata(this.httpClient());
}
const metadata = await kintoCollection.metadata();
await this._validateCollectionSignature([],
timestamp,
metadata,
@ -329,20 +316,6 @@ class RemoteSettingsClient extends EventEmitter {
// to record the fact that a check happened.
if (expectedTimestamp <= collectionLastModified) {
console.debug(`${this.identifier} local data is up-to-date`);
// If the data is up-to-date but don't have metadata (records loaded from dump),
// we fetch them and validate the signature immediately.
if (this.verifySignature && ObjectUtils.isEmpty(await kintoCollection.metadata())) {
console.debug("Verify signature of local data");
const { data: allData } = await kintoCollection.list({ order: "" });
const localRecords = allData.map(r => kintoCollection.cleanLocalFields(r));
const metadata = await kintoCollection.pullMetadata(this.httpClient());
if (this.verifySignature) {
await this._validateCollectionSignature([],
collectionLastModified,
metadata,
{ localRecords });
}
}
reportStatus = UptakeTelemetry.STATUS.UP_TO_DATE;
return;
}
@ -352,10 +325,10 @@ class RemoteSettingsClient extends EventEmitter {
if (this.verifySignature) {
kintoCollection.hooks["incoming-changes"] = [async (payload, collection) => {
const { changes: remoteRecords, lastModified: timestamp } = payload;
const { data } = await collection.list({ order: "" }); // no need to sort.
const { data } = await kintoCollection.list({ order: "" }); // no need to sort.
const metadata = await collection.metadata();
// Local fields are stripped to compute the collection signature (server does not have them).
const localRecords = data.map(r => collection.cleanLocalFields(r));
const localRecords = data.map(r => kintoCollection.cleanLocalFields(r));
await this._validateCollectionSignature(remoteRecords,
timestamp,
metadata,
@ -505,7 +478,8 @@ class RemoteSettingsClient extends EventEmitter {
*/
async _retrySyncFromScratch(kintoCollection, expectedTimestamp) {
// Fetch collection metadata.
const client = this.httpClient();
const api = new KintoHttpClient(gServerURL);
const client = await api.bucket(this.bucketName).collection(this.collectionName);
const metadata = await client.getData({ query: { _expected: expectedTimestamp }});
// Fetch whole list of records.
const {

View File

@ -20,9 +20,6 @@ let client;
let clientWithDump;
async function clear_state() {
client.verifySignature = false;
clientWithDump.verifySignature = false;
// Clear local DB.
const collection = await client.openCollection();
await collection.clear();
@ -48,10 +45,11 @@ function run_test() {
Services.prefs.setCharPref("services.settings.server",
`http://localhost:${server.identity.primaryPort}/v1`);
Services.prefs.setCharPref("services.settings.loglevel", "debug");
client = RemoteSettings("password-fields");
client.verifySignature = false;
clientWithDump = RemoteSettings("language-dictionaries");
clientWithDump.verifySignature = false;
server.registerPathHandler("/v1/", handleResponse);
server.registerPathHandler("/v1/buckets/monitor/collections/changes/records", handleResponse);
@ -67,7 +65,6 @@ function run_test() {
server.stop(() => { });
});
}
add_task(clear_state);
add_task(async function test_records_obtained_from_server_are_stored_in_db() {
// Test an empty db populates
@ -218,74 +215,6 @@ add_task(async function test_get_can_verify_signature() {
});
add_task(clear_state);
add_task(async function test_get_does_not_verify_signature_if_load_dump() {
let called;
clientWithDump._verifier = {
async asyncVerifyContentSignature(serialized, signature) {
called = true;
return true;
},
};
// When dump is loaded, signature is not verified.
const records = await clientWithDump.get({ verifySignature: true });
ok(records.length > 0, "dump is loaded");
ok(!called, "signature is missing but not verified");
// If metadata is missing locally, it is not fetched if `syncIfEmpty` is disabled.
let error;
try {
await clientWithDump.get({ verifySignature: true, syncIfEmpty: false });
} catch (e) {
error = e;
}
ok(!called, "signer was not called");
equal(error.message, "Missing signature (main/language-dictionaries)", "signature is missing locally");
// If metadata is missing locally, it is fetched by default (`syncIfEmpty: true`)
await clientWithDump.get({ verifySignature: true });
const metadata = await (await clientWithDump.openCollection()).metadata();
ok(Object.keys(metadata).length > 0, "metadata was fetched");
ok(called, "signature was verified for the data that was in dump");
});
add_task(clear_state);
add_task(async function test_sync_pulls_metadata_if_missing_with_dump_is_up_to_date() {
let called;
clientWithDump._verifier = {
async asyncVerifyContentSignature(serialized, signature) {
called = true;
return true;
},
};
// When dump is loaded, signature is not verified.
const records = await clientWithDump.get({ verifySignature: true });
ok(records.length > 0, "dump is loaded");
ok(!called, "signature is missing but not verified");
// Synchronize the collection (local data is up-to-date, collection last modified > 42)
// Signature verification is disabled (see `clear_state()`), so we don't bother with
// fetching metadata.
await clientWithDump.maybeSync(42);
let metadata = await (await clientWithDump.openCollection()).metadata();
ok(!metadata, "metadata was not fetched");
// Synchronize again the collection (up-to-date, since collection last modified still > 42)
clientWithDump.verifySignature = true;
await clientWithDump.maybeSync(42);
// With signature verification, metadata was fetched.
metadata = await (await clientWithDump.openCollection()).metadata();
ok(Object.keys(metadata).length > 0, "metadata was fetched");
ok(called, "signature was verified for the data that was in dump");
// Metadata is present, signature will now verified.
called = false;
await clientWithDump.get({ verifySignature: true });
ok(called, "local signature is verified");
});
add_task(clear_state);
add_task(async function test_sync_event_provides_information_about_records() {
let eventData;
client.on("sync", ({ data }) => eventData = data);
@ -670,7 +599,7 @@ function getSampleResponse(req, port) {
},
"GET:/fake-x5u": {
"sampleHeaders": [
"Content-Type: application/octet-stream",
"Content-Type: /octet-stream",
],
"status": { status: 200, statusText: "OK" },
"responseBody": `-----BEGIN CERTIFICATE-----