Bug 1598562 - Prevent Remote Settings server URL to be modified in release r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D54262

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mathieu Leplatre 2019-11-29 10:29:44 +00:00
parent 494d580be4
commit 11ef5b562c
3 changed files with 24 additions and 18 deletions

View File

@ -60,11 +60,6 @@ const DB_NAME = "remote-settings";
const TELEMETRY_COMPONENT = "remotesettings";
XPCOMUtils.defineLazyGetter(this, "console", () => Utils.log);
XPCOMUtils.defineLazyPreferenceGetter(
this,
"gServerURL",
"services.settings.server"
);
/**
* cacheProxy returns an object Proxy that will memoize properties of the target.
@ -277,7 +272,7 @@ class RemoteSettingsClient extends EventEmitter {
}
httpClient() {
const api = new KintoHttpClient(gServerURL);
const api = new KintoHttpClient(Utils.SERVER_URL);
return api.bucket(this.bucketName).collection(this.collectionName);
}
@ -398,7 +393,7 @@ class RemoteSettingsClient extends EventEmitter {
async sync(options) {
// We want to know which timestamp we are expected to obtain in order to leverage
// cache busting. We don't provide ETag because we don't want a 304.
const { changes } = await Utils.fetchLatestChanges(gServerURL, {
const { changes } = await Utils.fetchLatestChanges(Utils.SERVER_URL, {
filters: {
collection: this.collectionName,
bucket: this.bucketName,
@ -547,7 +542,7 @@ class RemoteSettingsClient extends EventEmitter {
// Fetch changes from server, and make sure we overwrite local data.
const strategy = Kinto.syncStrategy.PULL_ONLY;
syncResult = await kintoCollection.sync({
remote: gServerURL,
remote: Utils.SERVER_URL,
strategy,
expectedTimestamp,
});

View File

@ -8,6 +8,11 @@ const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"AppConstants",
"resource://gre/modules/AppConstants.jsm"
);
XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
@ -25,7 +30,19 @@ XPCOMUtils.defineLazyGetter(this, "log", () => {
});
});
XPCOMUtils.defineLazyPreferenceGetter(
this,
"gServerURL",
"services.settings.server"
);
var Utils = {
get SERVER_URL() {
return AppConstants.RELEASE_OR_BETA && !Cu.isInAutomation
? "https://firefox.settings.services.mozilla.com/v1"
: gServerURL;
},
CHANGES_PATH: "/buckets/monitor/collections/changes/records",
/**

View File

@ -47,7 +47,6 @@ XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
const PREF_SETTINGS_DEFAULT_BUCKET = "services.settings.default_bucket";
const PREF_SETTINGS_BRANCH = "services.settings.";
const PREF_SETTINGS_SERVER = "server";
const PREF_SETTINGS_DEFAULT_SIGNER = "default_signer";
const PREF_SETTINGS_SERVER_BACKOFF = "server.backoff";
const PREF_SETTINGS_LAST_UPDATE = "last_update_seconds";
@ -70,11 +69,6 @@ XPCOMUtils.defineLazyGetter(this, "gPrefs", () => {
return Services.prefs.getBranch(PREF_SETTINGS_BRANCH);
});
XPCOMUtils.defineLazyGetter(this, "console", () => Utils.log);
XPCOMUtils.defineLazyPreferenceGetter(
this,
"gServerURL",
PREF_SETTINGS_BRANCH + PREF_SETTINGS_SERVER
);
/**
* Default entry filtering function, in charge of excluding remote settings entries
@ -228,7 +222,7 @@ function remoteSettingsFunction() {
let pollResult;
try {
pollResult = await Utils.fetchLatestChanges(gServerURL, {
pollResult = await Utils.fetchLatestChanges(Utils.SERVER_URL, {
expectedTimestamp,
lastEtag,
});
@ -375,7 +369,7 @@ function remoteSettingsFunction() {
const {
changes,
currentEtag: serverTimestamp,
} = await Utils.fetchLatestChanges(gServerURL);
} = await Utils.fetchLatestChanges(Utils.SERVER_URL);
const collections = await Promise.all(
changes.map(async change => {
@ -402,8 +396,8 @@ function remoteSettingsFunction() {
);
return {
serverURL: gServerURL,
pollingEndpoint: gServerURL + Utils.CHANGES_PATH,
serverURL: Utils.SERVER_URL,
pollingEndpoint: Utils.SERVER_URL + Utils.CHANGES_PATH,
serverTimestamp,
localTimestamp: gPrefs.getCharPref(PREF_SETTINGS_LAST_ETAG, null),
lastCheck: gPrefs.getIntPref(PREF_SETTINGS_LAST_UPDATE, 0),