summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpcshell/test_signed_langpack.js
blob: 8ad83b2ecb249c2e48230ad1da8b46b0c970cdbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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();
});