From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../test/xpcshell/test_signed_langpack.js | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 toolkit/mozapps/extensions/test/xpcshell/test_signed_langpack.js (limited to 'toolkit/mozapps/extensions/test/xpcshell/test_signed_langpack.js') diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_signed_langpack.js b/toolkit/mozapps/extensions/test/xpcshell/test_signed_langpack.js new file mode 100644 index 0000000000..8ad83b2ecb --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_signed_langpack.js @@ -0,0 +1,67 @@ +const PREF_SIGNATURES_GENERAL = "xpinstall.signatures.required"; +const PREF_SIGNATURES_LANGPACKS = "extensions.langpacks.signatures.required"; + +// Disable "xpc::IsInAutomation()", since it would override the behavior +// we're testing for. +Services.prefs.setBoolPref( + "security.turn_off_all_security_so_that_viruses_can_take_over_this_computer", + false +); + +// Try to install the given XPI file, and assert that the install +// succeeds. Uninstalls before returning. +async function installShouldSucceed(file) { + let install = await promiseInstallFile(file); + Assert.equal(install.state, AddonManager.STATE_INSTALLED); + Assert.notEqual(install.addon, null); + await install.addon.uninstall(); +} + +// Try to install the given XPI file, assert that the install fails +// due to lack of signing. +async function installShouldFail(file) { + let install; + try { + install = await AddonManager.getInstallForFile(file); + } catch (err) {} + Assert.equal(install.state, AddonManager.STATE_DOWNLOAD_FAILED); + Assert.equal(install.error, AddonManager.ERROR_SIGNEDSTATE_REQUIRED); + Assert.equal(install.addon, null); +} + +// Test that the preference controlling langpack signing works properly +// (and that the general preference for addon signing does not affect +// language packs). +add_task(async function () { + AddonTestUtils.useRealCertChecks = true; + + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); + await promiseStartupManager(); + + Services.prefs.setBoolPref(PREF_SIGNATURES_GENERAL, true); + Services.prefs.setBoolPref(PREF_SIGNATURES_LANGPACKS, true); + + // The signed langpack should always install. + let signedXPI = do_get_file("data/signing_checks/langpack_signed.xpi"); + await installShouldSucceed(signedXPI); + + // With signatures required, unsigned langpack should not install. + let unsignedXPI = do_get_file("data/signing_checks/langpack_unsigned.xpi"); + await installShouldFail(unsignedXPI); + + // Even with the general xpi signing pref off, an unsigned langapck + // should not install. + Services.prefs.setBoolPref(PREF_SIGNATURES_GENERAL, false); + await installShouldFail(unsignedXPI); + + // But with the langpack signing pref off, unsigned langpack should + // install only on non-release builds. + Services.prefs.setBoolPref(PREF_SIGNATURES_LANGPACKS, false); + if (AppConstants.MOZ_REQUIRE_SIGNING) { + await installShouldFail(unsignedXPI); + } else { + await installShouldSucceed(unsignedXPI); + } + + await promiseShutdownManager(); +}); -- cgit v1.2.3