Commit 29b17873 authored by Michael Kaply's avatar Michael Kaply
Browse files

Bug 1571120 - Check for file paths before assuming a URL. r=aswan

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

--HG--
extra : moz-landing-system : lando
parent 2b3f71bc
......@@ -649,18 +649,13 @@ var Policies = {
for (let location of param.Install) {
let uri;
try {
uri = Services.io.newURI(location);
} catch (e) {
// If it's not a URL, it's probably a file path.
// Assume location is a file path
// We need to try as a file first because
// Windows paths are valid URIs.
// This is done for legacy support (old API)
try {
let xpiFile = new FileUtils.File(location);
uri = Services.io.newFileURI(xpiFile);
} catch (ex) {
log.error(`Invalid extension path location - ${location}`);
return;
}
let xpiFile = new FileUtils.File(location);
uri = Services.io.newFileURI(xpiFile);
} catch (e) {
uri = Services.io.newURI(location);
}
installAddonFromURL(uri.spec);
}
......
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { AddonTestUtils } = ChromeUtils.import(
"resource://testing-common/AddonTestUtils.jsm"
);
const { AddonManager } = ChromeUtils.import(
"resource://gre/modules/AddonManager.jsm"
);
AddonTestUtils.init(this);
AddonTestUtils.overrideCertDB();
AddonTestUtils.appInfo = getAppInfo();
const server = AddonTestUtils.createHttpServer({ hosts: ["example.com"] });
const BASE_URL = `http://example.com/data`;
let addonID = "policytest2@mozilla.com";
add_task(async function setup() {
await AddonTestUtils.promiseStartupManager();
let webExtensionFile = AddonTestUtils.createTempWebExtensionFile({
manifest: {
applications: {
gecko: {
id: addonID,
},
},
},
});
server.registerFile("/data/policy_test.xpi", webExtensionFile);
});
add_task(async function test_addon_forceinstalled_remote() {
await Promise.all([
AddonTestUtils.promiseInstallEvent("onInstallEnded"),
setupPolicyEngineWithJson({
policies: {
Extensions: {
Install: [BASE_URL + "/policy_test.xpi"],
Locked: [addonID],
},
},
}),
]);
let addon = await AddonManager.getAddonByID(addonID);
notEqual(addon, null, "Addon should not be null");
equal(addon.appDisabled, false, "Addon should not be disabled");
equal(
addon.permissions & AddonManager.PERM_CAN_UNINSTALL,
0,
"Addon should not be able to be uninstalled."
);
equal(
addon.permissions & AddonManager.PERM_CAN_DISABLE,
0,
"Addon should not be able to be disabled."
);
await addon.uninstall();
});
add_task(async function test_addon_forceinstalled_local() {
let addonID2 = "policytest@mozilla.com";
let file = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
file.append("policytest_v0.1.xpi");
await Promise.all([
AddonTestUtils.promiseInstallEvent("onInstallEnded"),
setupPolicyEngineWithJson({
policies: {
Extensions: {
Install: [file.path],
},
},
}),
]);
let addon = await AddonManager.getAddonByID(addonID2);
notEqual(addon, null, "Addon should not be null");
await addon.uninstall();
});
[DEFAULT]
firefox-appdir = browser
head = head.js
support-files =
policytest_v0.1.xpi
[test_3rdparty.js]
[test_appupdateurl.js]
[test_clear_blocked_cookies.js]
[test_defaultbrowsercheck.js]
[test_extensions.js]
[test_extensionsettings.js]
[test_macosparser_unflatten.js]
skip-if = os != 'mac'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment