Bug 1571120 - Check for file paths before assuming a URL. r=aswan
authorMichael Kaply <mozilla@kaply.com>
Tue, 20 Aug 2019 20:52:36 +0000
changeset 489236 e7434e7979b281a9ed1808a2fc5424d0a9bcf3c3
parent 489235 398e8b80d4a8e33cfd4c9549326df0c72be9e49b
child 489237 d2326f350a1541624dcf8e46169a6363fa311adc
push id93210
push usermozilla@kaply.com
push dateWed, 21 Aug 2019 15:47:26 +0000
treeherderautoland@e7434e7979b2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1571120
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1571120 - Check for file paths before assuming a URL. r=aswan 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]