Loading toolkit/components/enterprisepolicies/EnterprisePolicies.js +15 −3 Original line number Diff line number Diff line Loading @@ -30,6 +30,9 @@ const PREF_PER_USER_DIR = "toolkit.policies.perUserDir"; // and set PREF_ALTERNATE_PATH in firefox.js as: // /your/repo/browser/components/enterprisepolicies/helpers/sample.json const PREF_ALTERNATE_PATH = "browser.policies.alternatePath"; // For testing GPO, you can set an alternate location in testing const PREF_ALTERNATE_GPO = "browser.policies.alternateGPO"; // For testing, we may want to set PREF_ALTERNATE_PATH to point to a file // relative to the test root directory. In order to enable this, the string // below may be placed at the beginning of that preference value and it will Loading Loading @@ -578,9 +581,12 @@ class WindowsGPOPoliciesProvider { // user policies first and then replace them if necessary. log.debug("root = HKEY_CURRENT_USER"); this._readData(wrk, wrk.ROOT_KEY_CURRENT_USER); // We don't access machine policies in testing if (!Cu.isInAutomation && !isXpcshell) { log.debug("root = HKEY_LOCAL_MACHINE"); this._readData(wrk, wrk.ROOT_KEY_LOCAL_MACHINE); } } get hasPolicies() { return this._policies !== null && !isEmptyObject(this._policies); Loading @@ -596,7 +602,13 @@ class WindowsGPOPoliciesProvider { _readData(wrk, root) { try { wrk.open(root, "SOFTWARE\\Policies", wrk.ACCESS_READ); let regLocation = "SOFTWARE\\Policies"; if (Cu.isInAutomation || isXpcshell) { try { regLocation = Services.prefs.getStringPref(PREF_ALTERNATE_GPO); } catch (e) {} } wrk.open(root, regLocation, wrk.ACCESS_READ); if (wrk.hasChild("Mozilla\\" + Services.appinfo.name)) { this._policies = WindowsGPOParser.readPolicies(wrk, this._policies); } Loading toolkit/components/enterprisepolicies/tests/browser/browser.ini +2 −0 Original line number Diff line number Diff line Loading @@ -6,4 +6,6 @@ support-files = [browser_policies_basic_tests.js] [browser_policies_broken_json.js] [browser_policies_enterprise_only.js] [browser_policies_gpo.js] skip-if = os != "win" [browser_policies_mistyped_json.js] toolkit/components/enterprisepolicies/tests/browser/browser_policies_gpo.js 0 → 100644 +68 −0 Original line number Diff line number Diff line /* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ "use strict"; add_task(async function setup_preferences() { await SpecialPowers.pushPrefEnv({ set: [ ["browser.policies.alternateGPO", "SOFTWARE\\Mozilla\\PolicyTesting"], ], }); }); add_task(async function test_gpo_policies() { let { Policies } = ChromeUtils.import( "resource:///modules/policies/Policies.jsm" ); let gpoPolicyRan = false; Policies.gpo_policy = { onProfileAfterChange(manager, param) { is(param, true, "Param matches what was in the registry"); gpoPolicyRan = true; }, }; let wrk = Cc["@mozilla.org/windows-registry-key;1"].createInstance( Ci.nsIWindowsRegKey ); let regLocation = "SOFTWARE\\Mozilla\\PolicyTesting\\Mozilla\\" + Services.appinfo.name; wrk.create(wrk.ROOT_KEY_CURRENT_USER, regLocation, wrk.ACCESS_WRITE); wrk.writeIntValue("gpo_policy", 1); wrk.close(); await setupPolicyEngineWithJson( // empty policies.json since we are using GPO { policies: {}, }, // custom schema { properties: { gpo_policy: { type: "boolean", }, }, } ); is( Services.policies.status, Ci.nsIEnterprisePolicies.ACTIVE, "Engine is active" ); ok(gpoPolicyRan, "GPO Policy ran correctly though onProfileAfterChange"); delete Policies.gpo_policy; wrk.open(wrk.ROOT_KEY_CURRENT_USER, "SOFTWARE\\Mozilla", wrk.ACCESS_WRITE); wrk.removeChild("PolicyTesting\\Mozilla\\" + Services.appinfo.name); wrk.removeChild("PolicyTesting\\Mozilla"); wrk.removeChild("PolicyTesting"); wrk.close(); }); Loading
toolkit/components/enterprisepolicies/EnterprisePolicies.js +15 −3 Original line number Diff line number Diff line Loading @@ -30,6 +30,9 @@ const PREF_PER_USER_DIR = "toolkit.policies.perUserDir"; // and set PREF_ALTERNATE_PATH in firefox.js as: // /your/repo/browser/components/enterprisepolicies/helpers/sample.json const PREF_ALTERNATE_PATH = "browser.policies.alternatePath"; // For testing GPO, you can set an alternate location in testing const PREF_ALTERNATE_GPO = "browser.policies.alternateGPO"; // For testing, we may want to set PREF_ALTERNATE_PATH to point to a file // relative to the test root directory. In order to enable this, the string // below may be placed at the beginning of that preference value and it will Loading Loading @@ -578,9 +581,12 @@ class WindowsGPOPoliciesProvider { // user policies first and then replace them if necessary. log.debug("root = HKEY_CURRENT_USER"); this._readData(wrk, wrk.ROOT_KEY_CURRENT_USER); // We don't access machine policies in testing if (!Cu.isInAutomation && !isXpcshell) { log.debug("root = HKEY_LOCAL_MACHINE"); this._readData(wrk, wrk.ROOT_KEY_LOCAL_MACHINE); } } get hasPolicies() { return this._policies !== null && !isEmptyObject(this._policies); Loading @@ -596,7 +602,13 @@ class WindowsGPOPoliciesProvider { _readData(wrk, root) { try { wrk.open(root, "SOFTWARE\\Policies", wrk.ACCESS_READ); let regLocation = "SOFTWARE\\Policies"; if (Cu.isInAutomation || isXpcshell) { try { regLocation = Services.prefs.getStringPref(PREF_ALTERNATE_GPO); } catch (e) {} } wrk.open(root, regLocation, wrk.ACCESS_READ); if (wrk.hasChild("Mozilla\\" + Services.appinfo.name)) { this._policies = WindowsGPOParser.readPolicies(wrk, this._policies); } Loading
toolkit/components/enterprisepolicies/tests/browser/browser.ini +2 −0 Original line number Diff line number Diff line Loading @@ -6,4 +6,6 @@ support-files = [browser_policies_basic_tests.js] [browser_policies_broken_json.js] [browser_policies_enterprise_only.js] [browser_policies_gpo.js] skip-if = os != "win" [browser_policies_mistyped_json.js]
toolkit/components/enterprisepolicies/tests/browser/browser_policies_gpo.js 0 → 100644 +68 −0 Original line number Diff line number Diff line /* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ "use strict"; add_task(async function setup_preferences() { await SpecialPowers.pushPrefEnv({ set: [ ["browser.policies.alternateGPO", "SOFTWARE\\Mozilla\\PolicyTesting"], ], }); }); add_task(async function test_gpo_policies() { let { Policies } = ChromeUtils.import( "resource:///modules/policies/Policies.jsm" ); let gpoPolicyRan = false; Policies.gpo_policy = { onProfileAfterChange(manager, param) { is(param, true, "Param matches what was in the registry"); gpoPolicyRan = true; }, }; let wrk = Cc["@mozilla.org/windows-registry-key;1"].createInstance( Ci.nsIWindowsRegKey ); let regLocation = "SOFTWARE\\Mozilla\\PolicyTesting\\Mozilla\\" + Services.appinfo.name; wrk.create(wrk.ROOT_KEY_CURRENT_USER, regLocation, wrk.ACCESS_WRITE); wrk.writeIntValue("gpo_policy", 1); wrk.close(); await setupPolicyEngineWithJson( // empty policies.json since we are using GPO { policies: {}, }, // custom schema { properties: { gpo_policy: { type: "boolean", }, }, } ); is( Services.policies.status, Ci.nsIEnterprisePolicies.ACTIVE, "Engine is active" ); ok(gpoPolicyRan, "GPO Policy ran correctly though onProfileAfterChange"); delete Policies.gpo_policy; wrk.open(wrk.ROOT_KEY_CURRENT_USER, "SOFTWARE\\Mozilla", wrk.ACCESS_WRITE); wrk.removeChild("PolicyTesting\\Mozilla\\" + Services.appinfo.name); wrk.removeChild("PolicyTesting\\Mozilla"); wrk.removeChild("PolicyTesting"); wrk.close(); });