Bug 989137 - Part 13: Ability to ignore hashes of downloaded experiments. r=gfritzsche

This commit is contained in:
Georg Fritzsche 2014-04-17 15:47:36 +02:00
parent 6f0f2c7b08
commit 66edbad45a
2 changed files with 26 additions and 2 deletions

View File

@ -263,6 +263,10 @@ Experiments.Policy = function () {
this._log = Log.repository.getLoggerWithMessagePrefix(
"Browser.Experiments.Policy",
"Policy #" + gPolicyCounter++ + "::");
// Set to true to ignore hash verification on downloaded XPIs. This should
// not be used outside of testing.
this.ignoreHashes = false;
};
Experiments.Policy.prototype = {
@ -1498,8 +1502,9 @@ Experiments.ExperimentEntry.prototype = {
_installAddon: Task.async(function* () {
let deferred = Promise.defer();
let install = yield addonInstallForURL(this._manifestData.xpiURL,
this._manifestData.xpiHash);
let hash = this._policy.ignoreHashes ? null : this._manifestData.xpiHash;
let install = yield addonInstallForURL(this._manifestData.xpiURL, hash);
gActiveInstallURLs.add(install.sourceURI.spec);
let failureHandler = (install, handler) => {

View File

@ -141,4 +141,23 @@ add_task(function* test_startStop() {
Assert.equal(experiment.enabled, false, "Experiment should be disabled.");
addons = yield getExperimentAddons();
Assert.equal(addons.length, 0, "Experiment add-on is uninstalled.");
// Ensure hash validation works.
// We set an incorrect hash and expect the install to fail.
experiment._manifestData.xpiHash = "sha1:41014dcc66b4dcedcd973491a1530a32f0517d8a";
let errored = false;
try {
yield experiment.start();
} catch (ex) {
errored = true;
}
Assert.ok(experiment._failedStart, "Experiment failed to start.");
Assert.ok(errored, "start() threw an exception.");
// Make sure "ignore hashes" mode works.
gPolicy.ignoreHashes = true;
let changes = yield experiment.start();
Assert.equal(changes, experiment.ADDON_CHANGE_INSTALL);
yield experiment.stop();
gPolicy.ignoreHashes = false;
});