Bug 1571120 - Check for file paths before assuming a URL. r=aswan a=jcristau
authorMichael Kaply <mozilla@kaply.com>
Tue, 20 Aug 2019 20:52:36 +0000
changeset 545242 f52321e0fba04f5290cced2b2cdc7d6ddac33e5b
parent 545241 2be563909f58a437d3a4072bd860df7d7553ed66
child 545243 fa4ecfc3c66249aa5b8d29432a5a23ae4e950e38
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan, jcristau
bugs1571120
milestone69.0
Bug 1571120 - Check for file paths before assuming a URL. r=aswan a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D41255
browser/components/enterprisepolicies/Policies.jsm
browser/components/enterprisepolicies/tests/xpcshell/policytest_v0.1.xpi
browser/components/enterprisepolicies/tests/xpcshell/test_extensions.js
browser/components/enterprisepolicies/tests/xpcshell/xpcshell.ini
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -644,28 +644,23 @@ var Policies = {
         runOncePerModification(
           "extensionsInstall",
           JSON.stringify(param.Install),
           async () => {
             await uninstallingPromise;
             for (let location of param.Install) {
               let uri;
               try {
-                uri = Services.io.newURI(location);
-              } catch (e) {
-                // If it's not a URL, it's probably a file path.
-                // Assume location is a file path
+                // We need to try as a file first because
+                // Windows paths are valid URIs.
                 // This is done for legacy support (old API)
-                try {
-                  let xpiFile = new FileUtils.File(location);
-                  uri = Services.io.newFileURI(xpiFile);
-                } catch (ex) {
-                  log.error(`Invalid extension path location - ${location}`);
-                  return;
-                }
+                let xpiFile = new FileUtils.File(location);
+                uri = Services.io.newFileURI(xpiFile);
+              } catch (e) {
+                uri = Services.io.newURI(location);
               }
               installAddonFromURL(uri.spec);
             }
           }
         );
       }
       if ("Locked" in param) {
         for (let ID of param.Locked) {
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..ee2a6289ee5c2abd373f4aefdae1356110c18596
GIT binary patch
literal 305
zc$^FHW@Zs#U|`^2cwSKLv+`YjW+RZd5r}yiWEgT2^D@&?i%ayfiu3bALpT|j6Q}Kp
z0^!mMZU#n{uZ#=~VC}Abd-)C-@U(olX`Lz=df>#7OLH4#BM-WY{R~c8=ybJwy|9Xe
z&7Jb{Yr1R)*m`UNr{3=NdMfgkvu}5r3(t~6eSs^U9Gd!IlFe@Om`pK=^o2LLZU5%q
z{#)?F=uG5ijZ>?ox{a3d7oGnynd`^BsGa}CVvG1*9=`YZLC^-<Ewjp2-((2zW@M6M
n#^n<U1`q%`mf;0R5Zzy_5PzZhDZrbR4Wf;aAs9%X02=}T?uTd9
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/tests/xpcshell/test_extensions.js
@@ -0,0 +1,83 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+const { AddonTestUtils } = ChromeUtils.import(
+  "resource://testing-common/AddonTestUtils.jsm"
+);
+const { AddonManager } = ChromeUtils.import(
+  "resource://gre/modules/AddonManager.jsm"
+);
+
+AddonTestUtils.init(this);
+AddonTestUtils.overrideCertDB();
+AddonTestUtils.appInfo = getAppInfo();
+
+const server = AddonTestUtils.createHttpServer({ hosts: ["example.com"] });
+const BASE_URL = `http://example.com/data`;
+
+let addonID = "policytest2@mozilla.com";
+
+add_task(async function setup() {
+  await AddonTestUtils.promiseStartupManager();
+
+  let webExtensionFile = AddonTestUtils.createTempWebExtensionFile({
+    manifest: {
+      applications: {
+        gecko: {
+          id: addonID,
+        },
+      },
+    },
+  });
+
+  server.registerFile("/data/policy_test.xpi", webExtensionFile);
+});
+
+add_task(async function test_addon_forceinstalled_remote() {
+  await Promise.all([
+    AddonTestUtils.promiseInstallEvent("onInstallEnded"),
+    setupPolicyEngineWithJson({
+      policies: {
+        Extensions: {
+          Install: [BASE_URL + "/policy_test.xpi"],
+          Locked: [addonID],
+        },
+      },
+    }),
+  ]);
+  let addon = await AddonManager.getAddonByID(addonID);
+  notEqual(addon, null, "Addon should not be null");
+  equal(addon.appDisabled, false, "Addon should not be disabled");
+  equal(
+    addon.permissions & AddonManager.PERM_CAN_UNINSTALL,
+    0,
+    "Addon should not be able to be uninstalled."
+  );
+  equal(
+    addon.permissions & AddonManager.PERM_CAN_DISABLE,
+    0,
+    "Addon should not be able to be disabled."
+  );
+  await addon.uninstall();
+});
+
+add_task(async function test_addon_forceinstalled_local() {
+  let addonID2 = "policytest@mozilla.com";
+
+  let file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
+  file.append("policytest_v0.1.xpi");
+  await Promise.all([
+    AddonTestUtils.promiseInstallEvent("onInstallEnded"),
+    setupPolicyEngineWithJson({
+      policies: {
+        Extensions: {
+          Install: [file.path],
+        },
+      },
+    }),
+  ]);
+  let addon = await AddonManager.getAddonByID(addonID2);
+  notEqual(addon, null, "Addon should not be null");
+  await addon.uninstall();
+});
--- a/browser/components/enterprisepolicies/tests/xpcshell/xpcshell.ini
+++ b/browser/components/enterprisepolicies/tests/xpcshell/xpcshell.ini
@@ -1,16 +1,19 @@
 [DEFAULT]
 firefox-appdir = browser
 head = head.js
+support-files =
+  policytest_v0.1.xpi
 
 [test_3rdparty.js]
 [test_appupdateurl.js]
 [test_clear_blocked_cookies.js]
 [test_defaultbrowsercheck.js]
+[test_extensions.js]
 [test_extensionsettings.js]
 [test_macosparser_unflatten.js]
 skip-if = os != 'mac'
 [test_permissions.js]
 [test_popups_cookies_addons_flash.js]
 support-files = config_popups_cookies_addons_flash.json
 [test_preferences.js]
 [test_proxy.js]