Bug 782118 - Dictionary add-ons cannot be updated from addons.mozilla.org. r=Unfocused

This commit is contained in:
Jesper Kristensen 2012-10-04 17:54:40 -04:00
Родитель cb4ad1ca42
Коммит 051967f32e
9 изменённых файлов: 409 добавлений и 22 удалений

Просмотреть файл

@ -266,30 +266,24 @@ function parseRDFManifest(aId, aType, aUpdateKey, aRequest) {
createInstance(Ci.nsIRDFDataSource);
rdfParser.parseString(ds, aRequest.channel.URI, aRequest.responseText);
switch (aType) {
case "extension":
var item = PREFIX_EXTENSION + aId;
break;
case "theme":
item = PREFIX_THEME + aId;
break;
default:
item = PREFIX_ITEM + aId;
break;
}
let extensionRes = gRDF.GetResource(item);
// Differentiating between add-on types is deprecated
let extensionRes = gRDF.GetResource(PREFIX_EXTENSION + aId);
let themeRes = gRDF.GetResource(PREFIX_THEME + aId);
let itemRes = gRDF.GetResource(PREFIX_ITEM + aId);
let addonRes = ds.ArcLabelsOut(extensionRes).hasMoreElements() ? extensionRes
: ds.ArcLabelsOut(themeRes).hasMoreElements() ? themeRes
: itemRes;
// If we have an update key then the update manifest must be signed
if (aUpdateKey) {
let signature = getProperty(ds, extensionRes, "signature");
let signature = getProperty(ds, addonRes, "signature");
if (!signature)
throw Components.Exception("Update manifest for " + aId + " does not contain a required signature");
let serializer = new RDFSerializer();
let updateString = null;
try {
updateString = serializer.serializeResource(ds, extensionRes);
updateString = serializer.serializeResource(ds, addonRes);
}
catch (e) {
throw Components.Exception("Failed to generate signed string for " + aId + ". Serializer threw " + e,
@ -312,7 +306,7 @@ function parseRDFManifest(aId, aType, aUpdateKey, aRequest) {
throw Components.Exception("The signature for " + aId + " was not created by the add-on's updateKey");
}
let updates = ds.GetTarget(extensionRes, EM_R("updates"), true);
let updates = ds.GetTarget(addonRes, EM_R("updates"), true);
// A missing updates property doesn't count as a failure, just as no avialable
// update information
@ -322,7 +316,7 @@ function parseRDFManifest(aId, aType, aUpdateKey, aRequest) {
}
if (!(updates instanceof Ci.nsIRDFResource))
throw Components.Exception("Missing updates property for " + extensionRes.Value);
throw Components.Exception("Missing updates property for " + addonRes.Value);
let cu = Cc["@mozilla.org/rdf/container-utils;1"].
getService(Ci.nsIRDFContainerUtils);

Просмотреть файл

@ -0,0 +1,25 @@
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>ab-CD@dictionaries.addons.mozilla.org</em:id>
<em:version>2.0</em:version>
<em:type>64</em:type>
<em:unpack>true</em:unpack>
<!-- Front End MetaData -->
<em:name>Test Dictionary</em:name>
<em:description>Test Description</em:description>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>

Просмотреть файл

@ -0,0 +1,24 @@
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>ef@dictionaries.addons.mozilla.org</em:id>
<em:version>2.0</em:version>
<em:unpack>true</em:unpack>
<!-- Front End MetaData -->
<em:name>Test Dictionary ef</em:name>
<em:description>Test Description</em:description>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>

Просмотреть файл

@ -0,0 +1,25 @@
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>gh@dictionaries.addons.mozilla.org</em:id>
<em:version>2.0</em:version>
<em:type>64</em:type>
<em:unpack>true</em:unpack>
<!-- Front End MetaData -->
<em:name>Test Dictionary gh</em:name>
<em:description>Test Description</em:description>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>

Просмотреть файл

@ -0,0 +1,23 @@
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>addon12@tests.mozilla.org</em:id>
<em:version>2.0</em:version>
<!-- Front End MetaData -->
<em:name>Test 12</em:name>
<em:description>Test Description</em:description>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>

Просмотреть файл

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:extension:ab-CD@dictionaries.addons.mozilla.org">
<em:updates>
<Seq>
<li>
<Description>
<em:version>2.0</em:version>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
<em:updateLink>http://localhost:4444/addons/test_dictionary_3.xpi</em:updateLink>
</Description>
</em:targetApplication>
</Description>
</li>
</Seq>
</em:updates>
</Description>
<Description about="urn:mozilla:extension:ef@dictionaries.addons.mozilla.org">
<em:updates>
<Seq>
<li>
<Description>
<em:version>2.0</em:version>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
<em:updateLink>http://localhost:4444/addons/test_dictionary_4.xpi</em:updateLink>
</Description>
</em:targetApplication>
</Description>
</li>
</Seq>
</em:updates>
</Description>
<Description about="urn:mozilla:extension:gh@dictionaries.addons.mozilla.org">
<em:updates>
<Seq>
<li>
<Description>
<em:version>2.0</em:version>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
<em:updateLink>http://localhost:4444/addons/test_dictionary_5.xpi</em:updateLink>
</Description>
</em:targetApplication>
</Description>
</li>
</Seq>
</em:updates>
</Description>
</RDF>

Просмотреть файл

@ -247,4 +247,24 @@
</Seq>
</em:updates>
</Description>
<Description about="urn:mozilla:item:addon12@tests.mozilla.org">
<em:updates>
<Seq>
<li>
<Description>
<em:version>2.0</em:version>
<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
<em:updateLink>http://localhost:4444/addons/test_update12.xpi</em:updateLink>
</Description>
</em:targetApplication>
</Description>
</li>
</Seq>
</em:updates>
</Description>
</RDF>

Просмотреть файл

@ -9,6 +9,9 @@ Components.utils.import("resource://gre/modules/Services.jsm");
Services.prefs.setIntPref("extensions.enabledScopes",
AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER);
// The test extension uses an insecure update url.
Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false);
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
const profileDir = gProfD.clone();
@ -100,6 +103,7 @@ function run_test() {
// Create and configure the HTTP server.
testserver = new HttpServer();
testserver.registerDirectory("/data/", do_get_file("data"));
testserver.registerDirectory("/addons/", do_get_file("addons"));
testserver.start(4444);
@ -564,7 +568,7 @@ function check_test_23() {
b1.uninstall();
restartManager();
testserver.stop(run_test_25);
run_test_25();
});
});
});
@ -632,10 +636,155 @@ function run_test_26() {
do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE);
HunspellEngine.deactivate();
do_test_finished();
b1.uninstall();
restartManager();
run_test_27();
});
});
});
}
// Tests that an update check from a normal add-on to a bootstrappable add-on works
function run_test_27() {
writeInstallRDFForExtension({
id: "ab-CD@dictionaries.addons.mozilla.org",
version: "1.0",
updateURL: "http://localhost:4444/data/test_dictionary.rdf",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}],
name: "Test Dictionary",
}, profileDir);
restartManager();
prepare_test({
"ab-CD@dictionaries.addons.mozilla.org": [
"onInstalling"
]
}, [
"onNewInstall",
"onDownloadStarted",
"onDownloadEnded",
"onInstallStarted",
"onInstallEnded"
], check_test_27);
AddonManagerPrivate.backgroundUpdateCheck();
}
function check_test_27(install) {
do_check_eq(install.existingAddon.pendingUpgrade.install, install);
restartManager();
AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
do_check_neq(b1, null);
do_check_eq(b1.version, "2.0");
do_check_eq(b1.type, "dictionary");
b1.uninstall();
restartManager();
run_test_28();
});
}
// Tests that an update check from a bootstrappable add-on to a normal add-on works
function run_test_28() {
writeInstallRDFForExtension({
id: "ef@dictionaries.addons.mozilla.org",
version: "1.0",
type: "64",
updateURL: "http://localhost:4444/data/test_dictionary.rdf",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}],
name: "Test Dictionary ef",
}, profileDir);
restartManager();
prepare_test({
"ef@dictionaries.addons.mozilla.org": [
"onInstalling"
]
}, [
"onNewInstall",
"onDownloadStarted",
"onDownloadEnded",
"onInstallStarted",
"onInstallEnded"
], check_test_28);
AddonManagerPrivate.backgroundUpdateCheck();
}
function check_test_28(install) {
do_check_eq(install.existingAddon.pendingUpgrade.install, install);
restartManager();
AddonManager.getAddonByID("ef@dictionaries.addons.mozilla.org", function(b2) {
do_check_neq(b2, null);
do_check_eq(b2.version, "2.0");
do_check_eq(b2.type, "extension");
b2.uninstall();
restartManager();
run_test_29();
});
}
// Tests that an update check from a bootstrappable add-on to a bootstrappable add-on works
function run_test_29() {
writeInstallRDFForExtension({
id: "gh@dictionaries.addons.mozilla.org",
version: "1.0",
type: "64",
updateURL: "http://localhost:4444/data/test_dictionary.rdf",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}],
name: "Test Dictionary gh",
}, profileDir);
restartManager();
prepare_test({
"gh@dictionaries.addons.mozilla.org": [
["onInstalling", false /* = no restart */],
["onInstalled", false]
]
}, [
"onNewInstall",
"onDownloadStarted",
"onDownloadEnded",
"onInstallStarted",
"onInstallEnded"
], check_test_29);
AddonManagerPrivate.backgroundUpdateCheck();
}
function check_test_29(install) {
AddonManager.getAddonByID("gh@dictionaries.addons.mozilla.org", function(b2) {
do_check_neq(b2, null);
do_check_eq(b2.version, "2.0");
do_check_eq(b2.type, "dictionary");
prepare_test({
"gh@dictionaries.addons.mozilla.org": [
["onUninstalling", false],
["onUninstalled", false],
]
}, [
], finish_test_29);
b2.uninstall();
});
}
function finish_test_29() {
testserver.stop(do_test_finished);
}

Просмотреть файл

@ -1091,7 +1091,11 @@ function run_test_17() {
do_check_eq(aInstall.version, "3.0");
},
onDownloadFailed: function(aInstall) {
do_execute_soon(run_test_18);
AddonManager.getAddonByID("addon9@tests.mozilla.org", function(a9) {
a9.uninstall();
restartManager();
do_execute_soon(run_test_18);
});
}
});
@ -1131,6 +1135,8 @@ function run_test_18() {
},
onUpdateFinished: function() {
a10.uninstall();
restartManager();
run_test_19();
}
}, AddonManager.UPDATE_WHEN_USER_REQUESTED);
@ -1166,8 +1172,64 @@ function run_test_19() {
},
onUpdateFinished: function() {
end_test();
a11.uninstall();
restartManager();
run_test_20();
}
}, AddonManager.UPDATE_WHEN_USER_REQUESTED);
});
}
// Test that the update succeeds when the update.rdf URN contains a type prefix
// different from the add-on type
function run_test_20() {
writeInstallRDFForExtension({
id: "addon12@tests.mozilla.org",
version: "1.0",
updateURL: "http://localhost:4444/data/test_update.rdf",
targetApplications: [{
id: "xpcshell@tests.mozilla.org",
minVersion: "1",
maxVersion: "1"
}],
name: "Test Addon 12",
}, profileDir);
restartManager();
prepare_test({}, [
"onNewInstall",
"onDownloadStarted",
"onDownloadEnded"
], continue_test_20);
AddonManagerPrivate.backgroundUpdateCheck();
}
function continue_test_20(install) {
do_check_neq(install.existingAddon, null);
do_check_eq(install.existingAddon.id, "addon12@tests.mozilla.org");
prepare_test({
"addon12@tests.mozilla.org": [
"onInstalling"
]
}, [
"onInstallStarted",
"onInstallEnded",
], check_test_20);
}
function check_test_20(install) {
do_check_eq(install.existingAddon.pendingUpgrade.install, install);
restartManager();
AddonManager.getAddonByID("addon12@tests.mozilla.org", function(a12) {
do_check_neq(a12, null);
do_check_eq(a12.version, "2.0");
do_check_eq(a12.type, "extension");
a12.uninstall();
restartManager();
end_test();
});
}