Commit 122d3025 authored by Mark Banner's avatar Mark Banner
Browse files

Bug 1593561 - Ensure the search service can still run if the distribution...

Bug 1593561 - Ensure the search service can still run if the distribution directory is unreadable by the current user. r=mikedeboer

Differential Revision: https://phabricator.services.mozilla.com/D52095

--HG--
extra : moz-landing-system : lando
parent d8178cef
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -1144,11 +1144,20 @@ SearchService.prototype = {
          distDirs.push(dir);
        }
      } catch (ex) {
        if (!(ex instanceof OS.File.Error) || !ex.becauseNoSuchFile) {
        if (!(ex instanceof OS.File.Error)) {
          throw ex;
        }
        if (ex.becauseAccessDenied) {
          Cu.reportError(
            "Not loading distribution files because access was denied."
          );
        } else if (!ex.becauseNoSuchFile) {
          throw ex;
        }
      } finally {
        iterator.close();
        // If there's an issue on close, we can't do anything about it. It could
        // be that reading the iterator never fully opened.
        iterator.close().catch(Cu.reportError);
      }
    }

+4 −0
Original line number Diff line number Diff line
@@ -35,6 +35,9 @@ function installAddonEngine(name = "engine-addon") {
/**
 * Copy the engine-distribution.xml engine to a fake distribution
 * created in the profile, and registered with the directory service.
 *
 * @returns {nsIFile}
 *   An object referencing the distribution directory.
 */
function installDistributionEngine() {
  const XRE_APP_DISTRIBUTION_DIR = "XREAppDist";
@@ -64,4 +67,5 @@ function installDistributionEngine() {
      return null;
    },
  });
  return distDir;
}
+35 −0
Original line number Diff line number Diff line
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Tests if the search service manages to initialize correctly when the
 * distribution directory can't be accessed due to access denied.
 */

add_task(async function setup() {
  await AddonTestUtils.promiseStartupManager();
});

add_task(async function test_distribution_unreadable() {
  configureToLoadJarEngines();
  const distributionDir = installDistributionEngine();
  const oldPermissions = distributionDir.permissions;
  distributionDir.permissions = 0o000;

  registerCleanupFunction(() => {
    distributionDir.permissions = oldPermissions;
  });

  Assert.ok(!Services.search.isInitialized);

  await Services.search.init().then(aStatus => {
    Assert.ok(
      Components.isSuccessCode(aStatus),
      "Should have passed initialization"
    );
    Assert.ok(
      Services.search.isInitialized,
      "Should have flagged the search service as initialized"
    );
  });
});
+2 −0
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@ skip-if = true # Is confusing
[test_defaultEngine_fallback.js]
[test_defaultEngine.js]
[test_defaultPrivateEngine.js]
[test_distribution_unreadable.js]
skip-if = os == "win" # Windows doesn't have the same sort of permissions management.
[test_engine_selector_application.js]
[test_engine_selector_order.js]
[test_engine_selector.js]