Bug 1533638 - Prevent XPIProvider.getNewSideloads from rejecting if one of the sideloaded extensions is invalid. r=kmag
authorLuca Greco <lgreco@mozilla.com>
Fri, 22 Mar 2019 19:50:16 +0000
changeset 465773 67cb542606682bfa8cdf359a48d54b5d461a010c
parent 465772 981a62a09810bbe2e051687b8831af4972427649
child 465774 0539b9847dd53c4cdb75108b4e580bc518642690
push id35746
push usershindli@mozilla.com
push dateSat, 23 Mar 2019 09:46:24 +0000
treeherdermozilla-central@02b7484f316b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1533638
milestone68.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 1533638 - Prevent XPIProvider.getNewSideloads from rejecting if one of the sideloaded extensions is invalid. r=kmag Differential Revision: https://phabricator.services.mozilla.com/D22735
toolkit/mozapps/extensions/internal/XPIProvider.jsm
toolkit/mozapps/extensions/test/xpcshell/test_sideloads.js
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -2695,17 +2695,17 @@ var XPIProvider = {
       XPIDatabaseReconcile.processFileChanges({}, false);
       XPIDatabase.updateActiveAddons();
     }
 
     let addons = await Promise.all(
       Array.from(XPIStates.sideLoadedAddons.keys(),
                  id => this.getAddonByID(id)));
 
-    return addons.filter(addon => (addon.seen === false &&
+    return addons.filter(addon => (addon && addon.seen === false &&
                                    addon.permissions & AddonManager.PERM_CAN_ENABLE));
   },
 
   /**
    * Called to test whether this provider supports installing a particular
    * mimetype.
    *
    * @param {string} aMimetype
--- a/toolkit/mozapps/extensions/test/xpcshell/test_sideloads.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_sideloads.js
@@ -1,14 +1,18 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "49");
 
+const ID1 = "addon1@tests.mozilla.org";
+const ID2 = "addon2@tests.mozilla.org";
+const ID3 = "addon3@tests.mozilla.org";
+
 async function createWebExtension(details) {
   let options = {
     manifest: {
       applications: {gecko: {id: details.id}},
 
       name: details.name,
 
       permissions: details.permissions,
@@ -23,33 +27,30 @@ async function createWebExtension(detail
 
   await AddonTestUtils.manuallyInstall(xpi);
 }
 
 add_task(async function test_sideloading() {
   Services.prefs.setIntPref("extensions.autoDisableScopes", 15);
   Services.prefs.setIntPref("extensions.startupScanScopes", 0);
 
-  const ID1 = "addon1@tests.mozilla.org";
   await createWebExtension({
     id: ID1,
     name: "Test 1",
     userDisabled: true,
     permissions: ["history", "https://*/*"],
     iconURL: "foo-icon.png",
   });
 
-  const ID2 = "addon2@tests.mozilla.org";
   await createWebExtension({
     id: ID2,
     name: "Test 2",
     permissions: ["<all_urls>"],
   });
 
-  const ID3 = "addon3@tests.mozilla.org";
   await createWebExtension({
     id: ID3,
     name: "Test 3",
     permissions: ["<all_urls>"],
   });
 
   await promiseStartupManager();
 
@@ -60,8 +61,44 @@ add_task(async function test_sideloading
   deepEqual(sideloaded.map(a => a.id),
             [ID1, ID2, ID3],
             "Got the correct sideload add-ons");
 
   deepEqual(sideloaded.map(a => a.userDisabled),
             [true, true, true],
             "All sideloaded add-ons are disabled");
 });
+
+add_task(async function test_getNewSideload_on_invalid_extension() {
+  let destDir = AddonTestUtils.profileExtensions.clone();
+
+  let xpi = AddonTestUtils.createTempWebExtensionFile({
+    manifest: {
+      applications: {gecko: {id: "@invalid-extension"}},
+      name: "Invalid Extension",
+    },
+  });
+
+  // Create an invalid sideload by creating a file name that doesn't match the
+  // actual extension id.
+  await OS.File.copy(xpi.path, OS.Path.join(destDir.path, "@wrong-extension-filename.xpi"));
+
+  // Verify that getNewSideloads does not reject or throw when one of the sideloaded extensions
+  // is invalid.
+  const newSideloads = await AddonManagerPrivate.getNewSideloads();
+
+  const sideloadsInfo = newSideloads
+    .sort((a, b) => a.id.localeCompare(b.id))
+    .map(({id, seen, userDisabled, permissions}) => {
+      return {
+        id, seen, userDisabled,
+        canEnable: Boolean(permissions & AddonManager.PERM_CAN_ENABLE),
+      };
+    });
+
+  const expectedInfo = {seen: false, userDisabled: true, canEnable: true};
+
+  Assert.deepEqual(sideloadsInfo, [
+    {id: ID1, ...expectedInfo},
+    {id: ID2, ...expectedInfo},
+    {id: ID3, ...expectedInfo},
+  ], "Got the expected sideloaded extensions");
+});