diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /toolkit/mozapps/extensions/test/xpcshell/test_permissions.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/mozapps/extensions/test/xpcshell/test_permissions.js')
-rw-r--r-- | toolkit/mozapps/extensions/test/xpcshell/test_permissions.js | 199 |
1 files changed, 199 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_permissions.js b/toolkit/mozapps/extensions/test/xpcshell/test_permissions.js new file mode 100644 index 0000000000..30c9aa92b0 --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_permissions.js @@ -0,0 +1,199 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// Checks that permissions set in preferences are correctly imported but can +// be removed by the user. + +const { PermissionTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/PermissionTestUtils.sys.mjs" +); + +const XPI_MIMETYPE = "application/x-xpinstall"; + +function newPrincipal(uri) { + return Services.scriptSecurityManager.createContentPrincipal( + NetUtil.newURI(uri), + {} + ); +} + +add_task(async function setup() { + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2"); + + Services.prefs.setCharPref( + "xpinstall.whitelist.add", + "https://test1.com,https://test2.com" + ); + Services.prefs.setCharPref( + "xpinstall.whitelist.add.36", + "https://test3.com,https://www.test4.com" + ); + Services.prefs.setCharPref( + "xpinstall.whitelist.add.test5", + "https://test5.com" + ); + + PermissionTestUtils.add( + "https://www.test9.com", + "install", + Ci.nsIPermissionManager.ALLOW_ACTION + ); + + await promiseStartupManager(); + + Assert.ok( + !AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("http://test1.com") + ) + ); + Assert.ok( + AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://test1.com") + ) + ); + Assert.ok( + AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://www.test2.com") + ) + ); + Assert.ok( + AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://test3.com") + ) + ); + Assert.ok( + !AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://test4.com") + ) + ); + Assert.ok( + AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://www.test4.com") + ) + ); + Assert.ok( + !AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("http://www.test5.com") + ) + ); + Assert.ok( + AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://www.test5.com") + ) + ); + + Assert.ok( + !AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("http://www.test6.com") + ) + ); + Assert.ok( + !AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://www.test6.com") + ) + ); + Assert.ok( + !AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://test7.com") + ) + ); + Assert.ok( + !AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://www.test8.com") + ) + ); + + // This should remain unaffected + Assert.ok( + !AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("http://www.test9.com") + ) + ); + Assert.ok( + AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://www.test9.com") + ) + ); + + Services.perms.removeAll(); + + Assert.ok( + !AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://test1.com") + ) + ); + Assert.ok( + !AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://www.test2.com") + ) + ); + Assert.ok( + !AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://test3.com") + ) + ); + Assert.ok( + !AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://www.test4.com") + ) + ); + Assert.ok( + !AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://www.test5.com") + ) + ); + + // Upgrade the application and verify that the permissions are still not there + await promiseRestartManager("2"); + + Assert.ok( + !AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://test1.com") + ) + ); + Assert.ok( + !AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://www.test2.com") + ) + ); + Assert.ok( + !AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://test3.com") + ) + ); + Assert.ok( + !AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://www.test4.com") + ) + ); + Assert.ok( + !AddonManager.isInstallAllowed( + XPI_MIMETYPE, + newPrincipal("https://www.test5.com") + ) + ); +}); |