Bug 1497928 - Make about:policies report an error if json doesn't contain a 'policies' object. r=felipe, a=RyanVM
authorFerenc Nagy <nagy.ferenc.jr@gmail.com>
Tue, 18 Dec 2018 18:23:18 -0200
changeset 509138 a5ccc1d7c95f301ed5c88e0ecb312026726ddc53
parent 509137 59e23e5ef5c6bda7fcec9e040947b89127630741
child 509139 1475a44efc760726647c49805b5faa4c2a0141ff
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe, RyanVM
bugs1497928
milestone65.0
Bug 1497928 - Make about:policies report an error if json doesn't contain a 'policies' object. r=felipe, a=RyanVM
browser/components/enterprisepolicies/EnterprisePolicies.js
browser/components/enterprisepolicies/tests/browser/browser.ini
browser/components/enterprisepolicies/tests/browser/browser_policies_mistyped_json.js
--- a/browser/components/enterprisepolicies/EnterprisePolicies.js
+++ b/browser/components/enterprisepolicies/EnterprisePolicies.js
@@ -378,16 +378,21 @@ class JSONPoliciesProvider {
     return configFile;
   }
 
   _readData() {
     try {
       let data = Cu.readUTF8File(this._getConfigurationFile());
       if (data) {
         this._policies = JSON.parse(data).policies;
+
+        if (!this._policies) {
+          log.error("Policies file doesn't contain a 'policies' object");
+          this._failed = true;
+        }
       }
     } catch (ex) {
       if (ex instanceof Components.Exception &&
           ex.result == Cr.NS_ERROR_FILE_NOT_FOUND) {
         // Do nothing, _policies will remain null
       } else if (ex instanceof SyntaxError) {
         log.error("Error parsing JSON file");
         this._failed = true;
--- a/browser/components/enterprisepolicies/tests/browser/browser.ini
+++ b/browser/components/enterprisepolicies/tests/browser/browser.ini
@@ -13,16 +13,17 @@ support-files =
   ../../../../../toolkit/components/antitracking/test/browser/subResources.sjs
 
 [browser_policies_basic_tests.js]
 [browser_policies_broken_json.js]
 [browser_policies_enterprise_only.js]
 [browser_policies_getActivePolicies.js]
 [browser_policies_macosparser_unflatten.js]
 skip-if = os != 'mac'
+[browser_policies_mistyped_json.js]
 [browser_policies_notice_in_aboutpreferences.js]
 [browser_policies_popups_cookies_addons_flash.js]
 [browser_policies_runOnce_helper.js]
 [browser_policies_setAndLockPref_API.js]
 [browser_policies_simple_pref_policies.js]
 [browser_policies_sorted_alphabetically.js]
 [browser_policy_app_update.js]
 [browser_policy_app_update_URL.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policies_mistyped_json.js
@@ -0,0 +1,14 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function test_json_with_mistyped_policies() {
+    // Note: The "polcies" string is intentionally mistyped
+    await setupPolicyEngineWithJson({
+        "polcies": {},
+    });
+
+    is(Services.policies.status, Ci.nsIEnterprisePolicies.FAILED, "Engine was correctly set to the error state");
+});
+