зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1767890 - Prevent packaged dump from being loaded r=robwu
Change tests and snippets in documentation to use `Date.now()` instead of an arbitrary number like `42`. This way, we make sure the packaged dump isn't loaded on top of the tests data. Indeed, since Bug 1718083 we load the packaged dump if it's newer than local data. Differential Revision: https://phabricator.services.mozilla.com/D145579
This commit is contained in:
Родитель
9c0b8b40b4
Коммит
7529049420
|
@ -82,13 +82,13 @@ async function addLogin(login) {
|
|||
let EXPECTED_BREACH = null;
|
||||
let EXPECTED_ERROR_MESSAGE = null;
|
||||
add_setup(async function setup_head() {
|
||||
const db = await RemoteSettings(LoginBreaches.REMOTE_SETTINGS_COLLECTION).db;
|
||||
const db = RemoteSettings(LoginBreaches.REMOTE_SETTINGS_COLLECTION).db;
|
||||
if (EXPECTED_BREACH) {
|
||||
await db.create(EXPECTED_BREACH, {
|
||||
useRecordId: true,
|
||||
});
|
||||
}
|
||||
await db.importChanges({}, 42);
|
||||
await db.importChanges({}, Date.now());
|
||||
if (EXPECTED_BREACH) {
|
||||
await RemoteSettings(LoginBreaches.REMOTE_SETTINGS_COLLECTION).emit(
|
||||
"sync",
|
||||
|
|
|
@ -306,8 +306,8 @@ add_task(async function test_setBreachesFromRemoteSettingsSync() {
|
|||
"Should be 0 breached login before not-breached-subdomain.host.com is added to fxmonitor-breaches collection and synced: "
|
||||
);
|
||||
gBrowserGlue.observe(null, "browser-glue-test", "add-breaches-sync-handler");
|
||||
const db = await RemoteSettings(LoginBreaches.REMOTE_SETTINGS_COLLECTION).db;
|
||||
await db.importChanges({}, 42, [nowExampleIsInBreachedRecords[0]]);
|
||||
const db = RemoteSettings(LoginBreaches.REMOTE_SETTINGS_COLLECTION).db;
|
||||
await db.importChanges({}, Date.now(), [nowExampleIsInBreachedRecords[0]]);
|
||||
await emitSync();
|
||||
|
||||
const breachesByLoginGUID = await LoginBreaches.getPotentialBreachesByLoginGUID(
|
||||
|
|
|
@ -184,7 +184,7 @@ async function setup(experiment) {
|
|||
],
|
||||
});
|
||||
|
||||
await client.db.importChanges({}, 42, [experiment], { clear: true });
|
||||
await client.db.importChanges({}, Date.now(), [experiment], { clear: true });
|
||||
}
|
||||
|
||||
async function cleanup() {
|
||||
|
|
|
@ -27,7 +27,7 @@ add_setup(async function() {
|
|||
id: `HEARTBEAT_MESSAGE_${Date.now()}`,
|
||||
};
|
||||
const client = RemoteSettings("cfr");
|
||||
await client.db.importChanges({}, 42, [testMessage], {
|
||||
await client.db.importChanges({}, Date.now(), [testMessage], {
|
||||
clear: true,
|
||||
});
|
||||
|
||||
|
@ -88,7 +88,7 @@ add_task(async function test_heartbeat_tactic_2() {
|
|||
frequency: { lifetime: 2 },
|
||||
};
|
||||
const client = RemoteSettings("message-groups");
|
||||
await client.db.importChanges({}, 42, [groupConfiguration], {
|
||||
await client.db.importChanges({}, Date.now(), [groupConfiguration], {
|
||||
clear: true,
|
||||
});
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ add_setup(async function() {
|
|||
id: `HEARTBEAT_MESSAGE_${Date.now()}`,
|
||||
};
|
||||
const client = RemoteSettings("cfr");
|
||||
await client.db.importChanges({}, 42, [testMessage], { clear: true });
|
||||
await client.db.importChanges({}, Date.now(), [testMessage], { clear: true });
|
||||
|
||||
// Force the CFR provider cache to 0 by modifying updateCycleInMs
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
|
@ -83,7 +83,9 @@ add_task(async function test_heartbeat_tactic_2() {
|
|||
userPreferences: ["browser.userPreference.messaging-experiments"],
|
||||
};
|
||||
const client = RemoteSettings("message-groups");
|
||||
await client.db.importChanges({}, 42, [groupConfiguration], { clear: true });
|
||||
await client.db.importChanges({}, Date.now(), [groupConfiguration], {
|
||||
clear: true,
|
||||
});
|
||||
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
|
|
|
@ -30,7 +30,7 @@ add_task(async function test_with_rs_messages() {
|
|||
const client = RemoteSettings("cfr");
|
||||
await client.db.importChanges(
|
||||
{},
|
||||
42,
|
||||
Date.now(),
|
||||
[
|
||||
{
|
||||
// Modify targeting and randomize message name to work around the message
|
||||
|
|
|
@ -460,7 +460,7 @@ A handle on the underlying database can be obtained through the ``.db`` attribut
|
|||
|
||||
.. code-block:: js
|
||||
|
||||
const db = await RemoteSettings("a-key").db;
|
||||
const db = RemoteSettings("a-key").db;
|
||||
|
||||
And records can be created manually (as if they were synchronized from the server):
|
||||
|
||||
|
@ -473,11 +473,11 @@ And records can be created manually (as if they were synchronized from the serve
|
|||
passwordSelector: "#pass-signin",
|
||||
});
|
||||
|
||||
If no timestamp is set, any call to ``.get()`` will trigger the load of initial data (JSON dump) if any, or a synchronization will be triggered. To avoid that, store a fake timestamp:
|
||||
If no timestamp is set, any call to ``.get()`` will trigger the load of initial data (JSON dump) if any, or a synchronization will be triggered. To avoid that, store a fake timestamp. We use ``Date.now()`` instead of an arbitrary number, to make sure it's higher than the dump's, and thus prevent its load from the test.
|
||||
|
||||
.. code-block:: js
|
||||
|
||||
await db.importChanges({}, 42);
|
||||
await db.importChanges({}, Date.now());
|
||||
|
||||
In order to bypass the potential target filtering of ``RemoteSettings("key").get()``, the low-level listing of records can be obtained with ``collection.list()``:
|
||||
|
||||
|
|
|
@ -419,8 +419,8 @@ add_task(async function testExceptionListRemoteSettings() {
|
|||
Services.prefs.setStringPref(EXCEPTION_LIST_PREF_NAME, "");
|
||||
|
||||
// Add some initial data
|
||||
let db = await RemoteSettings(COLLECTION_NAME).db;
|
||||
await db.importChanges({}, 42, []);
|
||||
let db = RemoteSettings(COLLECTION_NAME).db;
|
||||
await db.importChanges({}, Date.now(), []);
|
||||
|
||||
// make peuSerivce start working by calling
|
||||
// registerAndRunExceptionListObserver
|
||||
|
|
|
@ -53,8 +53,8 @@ add_task(async _ => {
|
|||
data: { current: records },
|
||||
});
|
||||
}
|
||||
let db = await RemoteSettings(COLLECTION_NAME).db;
|
||||
await db.importChanges({}, 42, [records[0]]);
|
||||
let db = RemoteSettings(COLLECTION_NAME).db;
|
||||
await db.importChanges({}, Date.now(), [records[0]]);
|
||||
await emitSync();
|
||||
|
||||
await uds.ensureUpdated();
|
||||
|
|
|
@ -171,8 +171,8 @@ add_task(async function testRemoteSettings() {
|
|||
});
|
||||
|
||||
// Add initial empty record.
|
||||
let db = await RemoteSettings(COLLECTION_NAME).db;
|
||||
await db.importChanges({}, 42, []);
|
||||
let db = RemoteSettings(COLLECTION_NAME).db;
|
||||
await db.importChanges({}, Date.now(), []);
|
||||
|
||||
// Test if the observer been called when adding to the service.
|
||||
let updateEvent = new UpdateEvent();
|
||||
|
|
|
@ -45,8 +45,8 @@ add_task(async _ => {
|
|||
];
|
||||
|
||||
// Add some initial data
|
||||
let db = await RemoteSettings(COLLECTION_NAME).db;
|
||||
await db.importChanges({}, 42, records);
|
||||
let db = RemoteSettings(COLLECTION_NAME).db;
|
||||
await db.importChanges({}, Date.now(), records);
|
||||
|
||||
let promise = waitForEvent(updateEvent, "update");
|
||||
let obs = data => {
|
||||
|
|
|
@ -46,7 +46,7 @@ add_task(async function test_experimentEnrollment() {
|
|||
randomizationUnit: "normandy_id",
|
||||
},
|
||||
});
|
||||
await rsClient.db.importChanges({}, 42, [recipe], {
|
||||
await rsClient.db.importChanges({}, Date.now(), [recipe], {
|
||||
clear: true,
|
||||
});
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ const { ExperimentManager } = ChromeUtils.import(
|
|||
|
||||
async function setup(recipes) {
|
||||
const client = RemoteSettings("nimbus-desktop-experiments");
|
||||
await client.db.importChanges({}, 42, recipes, {
|
||||
await client.db.importChanges({}, Date.now(), recipes, {
|
||||
clear: true,
|
||||
});
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ async function setup(configuration) {
|
|||
const client = RemoteSettings("nimbus-desktop-experiments");
|
||||
await client.db.importChanges(
|
||||
{},
|
||||
42,
|
||||
Date.now(),
|
||||
configuration || [REMOTE_CONFIGURATION_FOO, REMOTE_CONFIGURATION_BAR],
|
||||
{
|
||||
clear: true,
|
||||
|
|
|
@ -314,7 +314,7 @@ decorate_task(
|
|||
|
||||
const db = await RecipeRunner._remoteSettingsClientForTesting.db;
|
||||
const fakeSig = { signature: "abc" };
|
||||
await db.importChanges({}, 42, [
|
||||
await db.importChanges({}, Date.now(), [
|
||||
{ id: "match", recipe: matchRecipe, signature: fakeSig },
|
||||
{
|
||||
id: "noMatch",
|
||||
|
@ -391,7 +391,7 @@ decorate_task(
|
|||
const fakeSig = { signature: "abc" };
|
||||
await db.importChanges(
|
||||
{},
|
||||
42,
|
||||
Date.now(),
|
||||
[
|
||||
{
|
||||
id: "match",
|
||||
|
|
|
@ -632,21 +632,17 @@ LoginTestUtils.remoteSettings = {
|
|||
async setupWebsitesWithSharedCredentials(
|
||||
relatedRealms = [["other-example.com", "example.com", "example.co.uk"]]
|
||||
) {
|
||||
let db = await RemoteSettings(this.relatedRealmsCollection).db;
|
||||
let db = RemoteSettings(this.relatedRealmsCollection).db;
|
||||
await db.clear();
|
||||
await db.create({
|
||||
id: "some-fake-ID-abc",
|
||||
relatedRealms,
|
||||
});
|
||||
await db.importChanges({}, 9999999999999);
|
||||
await db.importChanges({}, Date.now());
|
||||
},
|
||||
async cleanWebsitesWithSharedCredentials() {
|
||||
let db = await RemoteSettings(this.relatedRealmsCollection).db;
|
||||
await db.importChanges({}, 9999999999999, [], { clear: true });
|
||||
},
|
||||
async updateTimestamp() {
|
||||
let db = await RemoteSettings(this.relatedRealmsCollection).db;
|
||||
await db.importChanges({}, 9999999999999 + 1);
|
||||
let db = RemoteSettings(this.relatedRealmsCollection).db;
|
||||
await db.importChanges({}, Date.now(), [], { clear: true });
|
||||
},
|
||||
improvedPasswordRulesCollection: "password-rules",
|
||||
|
||||
|
@ -654,7 +650,7 @@ LoginTestUtils.remoteSettings = {
|
|||
origin = "example.com",
|
||||
rules = "minlength: 6; maxlength: 16; required: lower, upper; required: digit; required: [&<>'\"!#$%(),:;=?[^`{|}~]]; max-consecutive: 2;"
|
||||
) {
|
||||
let db = await RemoteSettings(this.improvedPasswordRulesCollection).db;
|
||||
let db = RemoteSettings(this.improvedPasswordRulesCollection).db;
|
||||
await db.clear();
|
||||
await db.create({
|
||||
id: "some-fake-ID",
|
||||
|
@ -666,10 +662,10 @@ LoginTestUtils.remoteSettings = {
|
|||
Domain: origin,
|
||||
"password-rules": rules,
|
||||
});
|
||||
await db.importChanges({}, 9999999999999);
|
||||
await db.importChanges({}, Date.now());
|
||||
},
|
||||
async cleanImprovedPasswordRules() {
|
||||
let db = await RemoteSettings(this.improvedPasswordRulesCollection).db;
|
||||
await db.importChanges({}, 9999999999999, [], { clear: true });
|
||||
let db = RemoteSettings(this.improvedPasswordRulesCollection).db;
|
||||
await db.importChanges({}, Date.now(), [], { clear: true });
|
||||
},
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
/**
|
||||
* Tests retrieving remote LoginRecipes in the parent process.
|
||||
* See https://firefox-source-docs.mozilla.org/services/settings/#unit-tests for explanation of db.importChanges({}, 42);
|
||||
* See https://firefox-source-docs.mozilla.org/services/settings/#unit-tests for explanation of db.importChanges({}, Date.now());
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
@ -15,7 +15,7 @@ const { RemoteSettings } = ChromeUtils.import(
|
|||
const REMOTE_SETTINGS_COLLECTION = "password-recipes";
|
||||
|
||||
add_task(async function test_init_remote_recipe() {
|
||||
const db = await RemoteSettings(REMOTE_SETTINGS_COLLECTION).db;
|
||||
const db = RemoteSettings(REMOTE_SETTINGS_COLLECTION).db;
|
||||
await db.clear();
|
||||
const record1 = {
|
||||
id: "some-fake-ID",
|
||||
|
@ -23,7 +23,7 @@ add_task(async function test_init_remote_recipe() {
|
|||
description: "Some description here",
|
||||
usernameSelector: "#username",
|
||||
};
|
||||
await db.importChanges({}, 42, [record1], { clear: true });
|
||||
await db.importChanges({}, Date.now(), [record1], { clear: true });
|
||||
let parent = new LoginRecipesParent({ defaults: true });
|
||||
|
||||
let recipesParent = await parent.initializationPromise;
|
||||
|
@ -59,14 +59,14 @@ add_task(async function test_init_remote_recipe() {
|
|||
});
|
||||
|
||||
add_task(async function test_add_recipe_sync() {
|
||||
const db = await RemoteSettings(REMOTE_SETTINGS_COLLECTION).db;
|
||||
const db = RemoteSettings(REMOTE_SETTINGS_COLLECTION).db;
|
||||
const record1 = {
|
||||
id: "some-fake-ID",
|
||||
hosts: ["www.testDomain.com"],
|
||||
description: "Some description here",
|
||||
usernameSelector: "#username",
|
||||
};
|
||||
await db.importChanges({}, 42, [record1], { clear: true });
|
||||
await db.importChanges({}, Date.now(), [record1], { clear: true });
|
||||
let parent = new LoginRecipesParent({ defaults: true });
|
||||
let recipesParent = await parent.initializationPromise;
|
||||
|
||||
|
@ -95,14 +95,14 @@ add_task(async function test_add_recipe_sync() {
|
|||
});
|
||||
|
||||
add_task(async function test_remove_recipe_sync() {
|
||||
const db = await RemoteSettings(REMOTE_SETTINGS_COLLECTION).db;
|
||||
const db = RemoteSettings(REMOTE_SETTINGS_COLLECTION).db;
|
||||
const record1 = {
|
||||
id: "some-fake-ID",
|
||||
hosts: ["www.testDomain.com"],
|
||||
description: "Some description here",
|
||||
usernameSelector: "#username",
|
||||
};
|
||||
await db.importChanges({}, 42, [record1], { clear: true });
|
||||
await db.importChanges({}, Date.now(), [record1], { clear: true });
|
||||
let parent = new LoginRecipesParent({ defaults: true });
|
||||
let recipesParent = await parent.initializationPromise;
|
||||
|
||||
|
@ -124,7 +124,7 @@ add_task(async function test_remove_recipe_sync() {
|
|||
});
|
||||
|
||||
add_task(async function test_malformed_recipes_in_db() {
|
||||
const db = await RemoteSettings(REMOTE_SETTINGS_COLLECTION).db;
|
||||
const db = RemoteSettings(REMOTE_SETTINGS_COLLECTION).db;
|
||||
const malformedRecord = {
|
||||
id: "some-ID",
|
||||
hosts: ["www.testDomain.com"],
|
||||
|
@ -132,7 +132,7 @@ add_task(async function test_malformed_recipes_in_db() {
|
|||
usernameSelector: "#username",
|
||||
fieldThatDoesNotExist: "value",
|
||||
};
|
||||
await db.importChanges({}, 42, [malformedRecord], { clear: true });
|
||||
await db.importChanges({}, Date.now(), [malformedRecord], { clear: true });
|
||||
let parent = new LoginRecipesParent({ defaults: true });
|
||||
try {
|
||||
await parent.initializationPromise;
|
||||
|
@ -149,7 +149,7 @@ add_task(async function test_malformed_recipes_in_db() {
|
|||
description: "Some description here",
|
||||
usernameSelector: "#username",
|
||||
};
|
||||
await db.importChanges({}, 42, [missingHostsRecord], { clear: true });
|
||||
await db.importChanges({}, Date.now(), [missingHostsRecord], { clear: true });
|
||||
parent = new LoginRecipesParent({ defaults: true });
|
||||
try {
|
||||
await parent.initializationPromise;
|
||||
|
|
|
@ -209,10 +209,10 @@ add_task(async function test_selector_config_update() {
|
|||
add_task(async function test_selector_db_modification() {
|
||||
const engineSelector = new SearchEngineSelector();
|
||||
// Fill the database with some values that we can use to test that it is cleared.
|
||||
const db = await RemoteSettings(SearchUtils.SETTINGS_KEY).db;
|
||||
const db = RemoteSettings(SearchUtils.SETTINGS_KEY).db;
|
||||
await db.importChanges(
|
||||
{},
|
||||
42,
|
||||
Date.now(),
|
||||
[
|
||||
{
|
||||
id: "85e1f268-9ca5-4b52-a4ac-922df5c07264",
|
||||
|
@ -258,7 +258,7 @@ add_task(async function test_selector_db_modification_never_succeeds() {
|
|||
const db = RemoteSettings(SearchUtils.SETTINGS_KEY).db;
|
||||
await db.importChanges(
|
||||
{},
|
||||
42,
|
||||
Date.now(),
|
||||
[
|
||||
{
|
||||
id: "b70edfdd-1c3f-4b7b-ab55-38cb048636c0",
|
||||
|
@ -299,10 +299,10 @@ add_task(async function test_empty_results() {
|
|||
// Check that returning an empty result re-tries.
|
||||
const engineSelector = new SearchEngineSelector();
|
||||
// Fill the database with some values that we can use to test that it is cleared.
|
||||
const db = await RemoteSettings(SearchUtils.SETTINGS_KEY).db;
|
||||
const db = RemoteSettings(SearchUtils.SETTINGS_KEY).db;
|
||||
await db.importChanges(
|
||||
{},
|
||||
42,
|
||||
Date.now(),
|
||||
[
|
||||
{
|
||||
id: "df5655ca-e045-4f8c-a7ee-047eeb654722",
|
||||
|
|
|
@ -58,8 +58,8 @@ add_task(async function test_list_changes() {
|
|||
];
|
||||
|
||||
// Add some initial data.
|
||||
let db = await RemoteSettings(COLLECTION_NAME).db;
|
||||
await db.importChanges({}, 42, records);
|
||||
let db = RemoteSettings(COLLECTION_NAME).db;
|
||||
await db.importChanges({}, Date.now(), records);
|
||||
let promise = waitForEvent(updateEvent, "update");
|
||||
|
||||
exceptionListService.registerAndRunExceptionListObserver(
|
||||
|
@ -187,8 +187,8 @@ add_task(async function test_list_init_data() {
|
|||
];
|
||||
|
||||
// Add some initial data.
|
||||
let db = await RemoteSettings(COLLECTION_NAME).db;
|
||||
await db.importChanges({}, 42, records);
|
||||
let db = RemoteSettings(COLLECTION_NAME).db;
|
||||
await db.importChanges({}, Date.now(), records);
|
||||
|
||||
// The first registered feature make ExceptionListService get the initial data
|
||||
// from remote setting.
|
||||
|
|
|
@ -160,8 +160,8 @@ add_task(async function test_ignoreList_updates() {
|
|||
|
||||
add_task(async function test_ignoreList_db_modification() {
|
||||
// Fill the database with some values that we can use to test that it is cleared.
|
||||
const db = await RemoteSettings(IGNORELIST_KEY).db;
|
||||
await db.importChanges({}, 42, IGNORELIST_TEST_DATA, { clear: true });
|
||||
const db = RemoteSettings(IGNORELIST_KEY).db;
|
||||
await db.importChanges({}, Date.now(), IGNORELIST_TEST_DATA, { clear: true });
|
||||
|
||||
// Stub the get() so that the first call simulates a signature error, and
|
||||
// the second simulates success reading from the dump.
|
||||
|
@ -190,8 +190,8 @@ add_task(async function test_ignoreList_db_modification() {
|
|||
|
||||
add_task(async function test_ignoreList_db_modification_never_succeeds() {
|
||||
// Fill the database with some values that we can use to test that it is cleared.
|
||||
const db = await RemoteSettings(IGNORELIST_KEY).db;
|
||||
await db.importChanges({}, 42, IGNORELIST_TEST_DATA, { clear: true });
|
||||
const db = RemoteSettings(IGNORELIST_KEY).db;
|
||||
await db.importChanges({}, Date.now(), IGNORELIST_TEST_DATA, { clear: true });
|
||||
|
||||
// Now simulate the condition where for some reason we never get a
|
||||
// valid result.
|
||||
|
|
|
@ -21,7 +21,7 @@ async function createRecords(records) {
|
|||
...record,
|
||||
}));
|
||||
// Prevent packaged dump to be loaded with high collection timestamp
|
||||
return client.db.importChanges({}, 9999999999999, withId);
|
||||
return client.db.importChanges({}, Date.now(), withId);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче