From 4d26cd3ddde2b7cc3825e709bcd167a048a478ce Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Tue, 30 Nov 2021 10:11:50 +0000 Subject: [PATCH] Bug 1742839 - Improve handling of missing last modified dates in remote settings database. r=robwu,leplatrem Differential Revision: https://phabricator.services.mozilla.com/D132053 --- services/settings/Database.jsm | 12 +++++++++++- .../test/unit/test_remote_settings_offline.js | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/services/settings/Database.jsm b/services/settings/Database.jsm index 5654e2bf119e..84f41ed851d3 100644 --- a/services/settings/Database.jsm +++ b/services/settings/Database.jsm @@ -177,7 +177,17 @@ class Database { this.identifier ); } - return entry ? entry.value : null; + if (!entry) { + return null; + } + // Some distributions where released with a modified dump that did not + // contain timestamps for last_modified. Work around this here, and return + // the timestamp as zero, so that the entries should get updated. + if (isNaN(entry.value)) { + console.warn(`Local timestamp is NaN for ${this.identifier}`); + return 0; + } + return entry.value; } async getMetadata() { diff --git a/services/settings/test/unit/test_remote_settings_offline.js b/services/settings/test/unit/test_remote_settings_offline.js index 94521b644723..cdf6dcdd9350 100644 --- a/services/settings/test/unit/test_remote_settings_offline.js +++ b/services/settings/test/unit/test_remote_settings_offline.js @@ -117,6 +117,20 @@ add_task(async function test_load_dump_after_non_empty_import() { }); add_task(clear_state); +add_task(async function test_load_dump_after_import_from_broken_distro() { + // Dump is updated regularly, verify that the dump matches our expectations + // before running the test. + ok(DUMP_LAST_MODIFIED > 1234, "Assuming dump to be newer than dummy 1234"); + + // No last_modified time. + await importData([{ id: "dummy" }]); + + const after = await client.get({ loadDumpIfNewer: true }); + equal(after.length, DUMP_RECORDS.length, "Imported dump"); + equal(await client.getLastModified(), DUMP_LAST_MODIFIED, "dump's timestamp"); +}); +add_task(clear_state); + add_task(async function test_skip_dump_if_same_last_modified() { await importData([{ last_modified: DUMP_LAST_MODIFIED, id: "dummy" }]);