Skip to content

Commit

Permalink
Bug 1600007 - Check entire policy for empty objects. r=mconley
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D55713

--HG--
extra : moz-landing-system : lando
  • Loading branch information
mkaply committed Dec 4, 2019
1 parent 6504573 commit 712501b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function test_empty_policy() {
await setupPolicyEngineWithJson({
policies: {
Certificates: {},
},
});

equal(
Services.policies.status,
Ci.nsIEnterprisePolicies.INACTIVE,
"Engine is not active"
);
});

add_task(async function test_empty_array() {
await setupPolicyEngineWithJson({
policies: {
RequestedLocales: [],
},
});

equal(
Services.policies.status,
Ci.nsIEnterprisePolicies.ACTIVE,
"Engine is active"
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ support-files =
[test_appupdateurl.js]
[test_clear_blocked_cookies.js]
[test_defaultbrowsercheck.js]
[test_empty_policy.js]
[test_extensions.js]
[test_extensionsettings.js]
[test_macosparser_unflatten.js]
Expand Down
18 changes: 16 additions & 2 deletions toolkit/components/enterprisepolicies/EnterprisePolicies.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ let env = Cc["@mozilla.org/process/environment;1"].getService(
);
const isXpcshell = env.exists("XPCSHELL_TEST_PROFILE_DIR");

// We're only testing for empty objects, not
// empty strings or empty arrays.
function isEmptyObject(obj) {
if (typeof obj != "object" || Array.isArray(obj)) {
return false;
}
for (let key of Object.keys(obj)) {
if (!isEmptyObject(obj[key])) {
return false;
}
}
return true;
}

function EnterprisePoliciesManager() {
Services.obs.addObserver(this, "profile-after-change", true);
Services.obs.addObserver(this, "final-ui-startup", true);
Expand Down Expand Up @@ -443,7 +457,7 @@ class JSONPoliciesProvider {
get hasPolicies() {
return (
this._failed ||
(this._policies !== null && Object.keys(this._policies).length)
(this._policies !== null && !isEmptyObject(this._policies))
);
}

Expand Down Expand Up @@ -554,7 +568,7 @@ class WindowsGPOPoliciesProvider {
}

get hasPolicies() {
return this._policies !== null && Object.keys(this._policies).length;
return this._policies !== null && !isEmptyObject(this._policies);
}

get policies() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"use strict";

add_task(async function test_app_update_URL() {
add_task(async function test_empty_toplevel() {
await setupPolicyEngineWithJson({
policies: {},
});
Expand Down

0 comments on commit 712501b

Please sign in to comment.