Bug 1656420 - Expose a function to indicate whether the production fxa stack is in use. r=rfkelly

Differential Revision: https://phabricator.services.mozilla.com/D85538
This commit is contained in:
Mark Hammond 2020-07-31 06:53:13 +00:00
Родитель 9b24bf03b8
Коммит 7b3c825579
3 изменённых файлов: 51 добавлений и 6 удалений

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

@ -216,6 +216,31 @@ var FxAccountsConfig = {
}
},
// Returns true if this user is using the FxA "production" systems, false
// if using any other configuration, including self-hosting or the FxA
// non-production systems such as "dev" or "staging".
// It's typically used as a proxy for "is this likely to be a self-hosted
// user?", but it's named this way to make the implementation less
// surprising. As a result, it's fairly conservative and would prefer to have
// a false-negative than a false-position as it determines things which users
// might consider sensitive (notably, telemetry).
// Note also that while it's possible to self-host just sync and not FxA, we
// don't make that distinction - that's a self-hoster from the POV of this
// function.
isProductionConfig() {
// Specifically, if the autoconfig URLs, or *any* of the URLs that
// we consider configurable are modified, we assume self-hosted.
if (this.getAutoConfigURL()) {
return false;
}
for (let pref of CONFIG_PREFS) {
if (Services.prefs.prefHasUserValue(pref)) {
return false;
}
}
return true;
},
// Read expected client configuration from the fxa auth server
// (from `identity.fxaccounts.autoconfig.uri`/.well-known/fxa-client-configuration)
// and replace all the relevant our prefs with the information found there.

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

@ -35,3 +35,21 @@ add_task(async function test_non_https_remote_server_uri() {
);
Services.prefs.clearUserPref("identity.fxaccounts.remote.root");
});
add_task(async function test_is_production_config() {
// should start with no auto-config URL.
Assert.ok(!FxAccounts.config.getAutoConfigURL());
// which means we are using prod.
Assert.ok(FxAccounts.config.isProductionConfig());
// Set an auto-config URL.
Services.prefs.setCharPref("identity.fxaccounts.autoconfig.uri", "http://x");
Assert.equal(FxAccounts.config.getAutoConfigURL(), "http://x");
Assert.ok(!FxAccounts.config.isProductionConfig());
// Clear the auto-config URL, but set one of the other config params.
Services.prefs.clearUserPref("identity.fxaccounts.autoconfig.uri");
Services.prefs.setCharPref("identity.sync.tokenserver.uri", "http://t");
Assert.ok(!FxAccounts.config.isProductionConfig());
Services.prefs.clearUserPref("identity.sync.tokenserver.uri");
});

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

@ -23,6 +23,8 @@ const { XPCOMUtils } = ChromeUtils.import(
XPCOMUtils.defineLazyModuleGetters(this, {
Async: "resource://services-common/async.js",
AuthenticationError: "resource://services-sync/browserid_identity.js",
fxAccounts: "resource://gre/modules/FxAccounts.jsm",
FxAccounts: "resource://gre/modules/FxAccounts.jsm",
Log: "resource://gre/modules/Log.jsm",
ObjectUtils: "resource://gre/modules/ObjectUtils.jsm",
Observers: "resource://services-common/observers.js",
@ -46,11 +48,7 @@ XPCOMUtils.defineLazyServiceGetter(
"@mozilla.org/base/telemetry;1",
"nsITelemetry"
);
ChromeUtils.defineModuleGetter(
this,
"fxAccounts",
"resource://gre/modules/FxAccounts.jsm"
);
XPCOMUtils.defineLazyGetter(
this,
"WeaveService",
@ -737,8 +735,12 @@ class SyncTelemetryImpl {
}
isProductionSyncUser() {
// If FxA isn't production then we treat sync as not being production.
// Further, there's the deprecated "services.sync.tokenServerURI" pref we
// need to consider - fxa doesn't consider that as if that's the only
// pref set, they *are* running a production fxa, just not production sync.
if (
Services.prefs.prefHasUserValue("identity.sync.tokenserver.uri") ||
!FxAccounts.config.isProductionConfig() ||
Services.prefs.prefHasUserValue("services.sync.tokenServerURI")
) {
log.trace(`Not sending telemetry ping for self-hosted Sync user`);