From 3af21bd5bf8481f8e5ee4eea6bbae3e0e07deeee Mon Sep 17 00:00:00 2001 From: Michael Kaply Date: Tue, 30 Jul 2019 23:03:28 +0000 Subject: [PATCH] Bug 1568921 - Don't allow addons to be uninstalled from AMO if policy prevents it. r=aswan Differential Revision: https://phabricator.services.mozilla.com/D39902 --HG-- extra : moz-landing-system : lando --- toolkit/mozapps/extensions/AddonManager.jsm | 4 ++++ .../test/browser/browser_webapi_uninstall.js | 22 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/toolkit/mozapps/extensions/AddonManager.jsm b/toolkit/mozapps/extensions/AddonManager.jsm index 9192aa83bf34..491963906323 100644 --- a/toolkit/mozapps/extensions/AddonManager.jsm +++ b/toolkit/mozapps/extensions/AddonManager.jsm @@ -3386,6 +3386,10 @@ var AddonManagerInternal = { return false; } + if (!(addon.permissions & AddonManager.PERM_CAN_UNINSTALL)) { + return Promise.reject({ message: "Addon cannot be uninstalled" }); + } + try { addon.uninstall(); return true; diff --git a/toolkit/mozapps/extensions/test/browser/browser_webapi_uninstall.js b/toolkit/mozapps/extensions/test/browser/browser_webapi_uninstall.js index 150fd7de7b90..399284e18029 100644 --- a/toolkit/mozapps/extensions/test/browser/browser_webapi_uninstall.js +++ b/toolkit/mozapps/extensions/test/browser/browser_webapi_uninstall.js @@ -28,20 +28,26 @@ add_task( testWithAPI(async function(browser) { const ID1 = "addon1@tests.mozilla.org"; const ID2 = "addon2@tests.mozilla.org"; + const ID3 = "addon3@tests.mozilla.org"; let provider = new MockProvider(); provider.addAddon(new MockAddon(ID1, "Test add-on 1", "extension", 0)); provider.addAddon(new MockAddon(ID2, "Test add-on 2", "extension", 0)); - let [a1, a2] = await promiseAddonsByIDs([ID1, ID2]); + let addon = new MockAddon(ID3, "Test add-on 3", "extension", 0); + addon.permissions &= ~AddonManager.PERM_CAN_UNINSTALL; + provider.addAddon(addon); + + let [a1, a2, a3] = await promiseAddonsByIDs([ID1, ID2, ID3]); isnot(a1, null, "addon1 is installed"); isnot(a2, null, "addon2 is installed"); + isnot(a3, null, "addon3 is installed"); let result = await API_uninstallByID(browser, ID1); is(result, true, "uninstall of addon1 succeeded"); - [a1, a2] = await promiseAddonsByIDs([ID1, ID2]); + [a1, a2, a3] = await promiseAddonsByIDs([ID1, ID2, ID3]); is(a1, null, "addon1 is uninstalled"); isnot(a2, null, "addon2 is still installed"); @@ -49,5 +55,17 @@ add_task( is(result, true, "uninstall of addon2 succeeded"); [a2] = await promiseAddonsByIDs([ID2]); is(a2, null, "addon2 is uninstalled"); + + await Assert.rejects( + API_uninstallByID(browser, ID3), + /Addon cannot be uninstalled/, + "Unable to uninstall addon" + ); + + // Cleanup addon3 + a3.permissions |= AddonManager.PERM_CAN_UNINSTALL; + await a3.uninstall(); + [a3] = await promiseAddonsByIDs([ID3]); + is(a3, null, "addon3 is uninstalled"); }) );