Bug 989137 - Part 12: Ability to ignore hashes of downloaded experiments; r=gfritzsche

We normally validate hashes of XPIs as part of installing experiments.
While a useful security feature, this patch makes that optional. This in
turn makes automated and manual testing easier.

--HG--
extra : rebase_source : 292653411391843fad3f62d0bee01e11779313b6
This commit is contained in:
Gregory Szorc 2014-04-10 13:18:19 -07:00
parent fcf9f29694
commit 6ab6b755f8
2 changed files with 26 additions and 2 deletions

View File

@ -252,6 +252,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: 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

@ -140,4 +140,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;
});