Bug 1919344 - Add isEnterprise check to Services.policies. a=RyanVM

Original Revision: https://phabricator.services.mozilla.com/D222522

Differential Revision: https://phabricator.services.mozilla.com/D233112
This commit is contained in:
Mike Kaply 2025-01-11 02:14:15 +00:00
parent b9447ec32f
commit 1348276c1d
3 changed files with 44 additions and 26 deletions

View file

@ -12,7 +12,7 @@ const { AppConstants } = ChromeUtils.importESModule(
add_task(async function test_telemetry_basic() {
await setupPolicyEngineWithJson({
policies: {
DisableAboutSupport: true,
BlockAboutSupport: true,
},
});
@ -21,6 +21,7 @@ add_task(async function test_telemetry_basic() {
"policies.is_enterprise",
true
);
equal(Services.policies.isEnterprise, true);
});
add_task(async function test_telemetry_just_roots() {
@ -37,12 +38,13 @@ add_task(async function test_telemetry_just_roots() {
"policies.is_enterprise",
AppConstants.IS_ESR
);
equal(Services.policies.isEnterprise, AppConstants.IS_ESR);
});
add_task(async function test_telemetry_roots_plus_policy() {
await setupPolicyEngineWithJson({
policies: {
DisableAboutSupport: true,
BlockAboutSupport: true,
Certificates: {
ImportEnterpriseRoots: true,
},
@ -54,6 +56,7 @@ add_task(async function test_telemetry_roots_plus_policy() {
"policies.is_enterprise",
true
);
equal(Services.policies.isEnterprise, true);
});
add_task(async function test_telemetry_esr() {
@ -63,6 +66,7 @@ add_task(async function test_telemetry_esr() {
"policies.is_enterprise",
AppConstants.IS_ESR
);
equal(Services.policies.isEnterprise, AppConstants.IS_ESR);
});
add_task(async function test_telemetry_esr_mac_eol() {
@ -75,6 +79,7 @@ add_task(async function test_telemetry_esr_mac_eol() {
"policies.is_enterprise",
false
);
equal(Services.policies.isEnterprise, false);
});
add_task(async function test_telemetry_esr_win_eol() {
@ -87,6 +92,7 @@ add_task(async function test_telemetry_esr_win_eol() {
"policies.is_enterprise",
false
);
equal(Services.policies.isEnterprise, false);
});
add_task(async function test_telemetry_esr_distro() {
@ -99,4 +105,5 @@ add_task(async function test_telemetry_esr_distro() {
"policies.is_enterprise",
AppConstants.IS_ESR
);
equal(Services.policies.isEnterprise, AppConstants.IS_ESR);
});

View file

@ -124,35 +124,18 @@ EnterprisePoliciesManager.prototype = {
this.status = Ci.nsIEnterprisePolicies.ACTIVE;
this._parsedPolicies = {};
this._reportEnterpriseTelemetry(provider.policies);
this._activatePolicies(provider.policies);
this._reportEnterpriseTelemetry();
Services.prefs.setBoolPref(PREF_POLICIES_APPLIED, true);
},
_reportEnterpriseTelemetry(policies = {}) {
let excludedDistributionIDs = [
"mozilla-mac-eol-esr115",
"mozilla-win-eol-esr115",
];
let distroId = Services.prefs
.getDefaultBranch(null)
.getCharPref("distribution.id", "");
let policiesLength = Object.keys(policies).length;
Services.telemetry.scalarSet("policies.count", policiesLength);
let isEnterprise =
// As we migrate folks to ESR for other reasons (deprecating an OS),
// we need to add checks here for distribution IDs.
(AppConstants.IS_ESR && !excludedDistributionIDs.includes(distroId)) ||
// If there are multiple policies then its enterprise.
policiesLength > 1 ||
// If ImportEnterpriseRoots isn't the only policy then it's enterprise.
(policiesLength && !policies.Certificates?.ImportEnterpriseRoots);
Services.telemetry.scalarSet("policies.is_enterprise", isEnterprise);
_reportEnterpriseTelemetry() {
Services.telemetry.scalarSet(
"policies.count",
Object.keys(this._parsedPolicies || {}).length
);
Services.telemetry.scalarSet("policies.is_enterprise", this.isEnterprise);
},
_chooseProvider() {
@ -472,6 +455,30 @@ EnterprisePoliciesManager.prototype = {
}
return false;
},
get isEnterprise() {
let excludedDistributionIDs = [
"mozilla-mac-eol-esr115",
"mozilla-win-eol-esr115",
];
let distroId = Services.prefs
.getDefaultBranch(null)
.getCharPref("distribution.id", "");
let policiesLength = Object.keys(this._parsedPolicies || {}).length;
let isEnterprise =
// As we migrate folks to ESR for other reasons (deprecating an OS),
// we need to add checks here for distribution IDs.
(AppConstants.IS_ESR && !excludedDistributionIDs.includes(distroId)) ||
// If there are multiple policies then its enterprise.
policiesLength > 1 ||
// If ImportEnterpriseRoots isn't the only policy then it's enterprise.
(!!policiesLength &&
!this._parsedPolicies.Certificates?.ImportEnterpriseRoots);
return isEnterprise;
},
};
let DisallowedFeatures = {};

View file

@ -14,6 +14,10 @@ interface nsIEnterprisePolicies : nsISupports
const short FAILED = 2;
readonly attribute short status;
// We only consider a build to be enterprise when certain conditions are
// met. This value is set between profile-do-change and addons-startup,
// so it should be usable from most places.
readonly attribute short isEnterprise;
boolean isAllowed(in ACString feature);