Bug 989806 - Use reviewer certs for reviewer pages. r=fabrice

This commit is contained in:
Marco Castelluccio 2014-04-28 10:50:00 +02:00
parent 4399658f80
commit 44d314f69a
18 changed files with 368 additions and 5 deletions

Binary file not shown.

Binary file not shown.

View File

@ -212,3 +212,5 @@ http://example.cn:80 privileged
http://example.co.jp:80 privileged
http://example.fi:80 privileged
# Hosts for testing marketplace apps installations
https://marketplace.firefox.com:443 privileged

View File

@ -3104,7 +3104,10 @@ onInstallSuccessAck: function onInstallSuccessAck(aManifestURL,
throw "CERTDB_ERROR";
}
let [result, zipReader] = yield this._openSignedPackage(aZipFile, certDb);
let [result, zipReader] = yield this._openSignedPackage(aApp.installOrigin,
aApp.manifestURL,
aZipFile,
certDb);
// We cannot really know if the system date is correct or
// not. What we can know is if it's after the build date or not,
@ -3147,11 +3150,39 @@ onInstallSuccessAck: function onInstallSuccessAck(aManifestURL,
}).bind(this));
},
_openSignedPackage: function(aZipFile, aCertDb) {
_openSignedPackage: function(aInstallOrigin, aManifestURL, aZipFile, aCertDb) {
let deferred = Promise.defer();
let root = TrustedRootCertificate.index;
let useReviewerCerts = false;
try {
useReviewerCerts = Services.prefs.
getBoolPref("dom.mozApps.use_reviewer_certs");
} catch (ex) { }
// We'll use the reviewer and dev certificates only if the pref is set to
// true.
if (useReviewerCerts) {
let manifestPath = Services.io.newURI(aManifestURL, null, null).path;
switch (aInstallOrigin) {
case "https://marketplace.firefox.com":
root = manifestPath.startsWith("/reviewers/")
? Ci.nsIX509CertDB.AppMarketplaceProdReviewersRoot
: Ci.nsIX509CertDB.AppMarketplaceProdPublicRoot;
break;
case "https://marketplace-dev.allizom.org":
root = manifestPath.startsWith("/reviewers/")
? Ci.nsIX509CertDB.AppMarketplaceDevReviewersRoot
: Ci.nsIX509CertDB.AppMarketplaceDevPublicRoot;
break;
}
}
aCertDb.openSignedAppFileAsync(
TrustedRootCertificate.index, aZipFile,
root, aZipFile,
function(aRv, aZipReader) {
deferred.resolve([aRv, aZipReader]);
}

View File

@ -0,0 +1,28 @@
{
"version" : "2.0",
"name" : "Flashlight (Linterna)",
"description" : "Simple Flashlight that you can use everywhere without internet connection and also with cool modes: * Flashlight mode - * Disco mode - * Colors mode",
"launch_path" : "/index.html",
"icons": {
"16": "/img/icons/mortar-16.png",
"48": "/img/icons/mortar-48.png",
"60": "/img/icons/mortar-60.png",
"128": "/img/icons/mortar-128.png"
},
"developer": {
"name": "William Vargas",
"url" : "https://twitter.com/tecnowilliam"
},
"installs_allowed_from": ["*"],
"locales": {
"es": {
"description": "Una simple linterna que puedes utilizar en cualquier lugar sin conexión a internet y con opciones geniales: * Modo Linterna - * Modo Disco - * Modo Colores",
"developer": {
"name": "William Vargas",
"url" : "https://twitter.com/tecnowilliam"
}
}
},
"default_locale": "en",
"package_path": "marketplace_app.zip"
}

View File

@ -0,0 +1 @@
Content-Type: application/x-web-app-manifest+json

Binary file not shown.

View File

@ -0,0 +1,50 @@
{
"version": "0.2.2",
"name": "KitchenSink",
"description": "Tests and report APIs available on the device",
"launch_path": "/index.html",
"developer": {
"name": "Piotr Zalewa",
"url": "http://www.mozillalabs.com"
},
"icons": {
"16": "/img/icons/logo-16.png",
"32": "/img/icons/logo-32.png",
"64": "/img/icons/logo-64.png",
"128": "/img/icons/logo-128.png",
"256": "/img/icons/logo-256.png"
},
"type": "privileged",
"permissions": {
"alarms": {
"description": "Testing"
},
"browser": {
"description": "Testing"
},
"geolocation": {
"description": "Testing"
},
"contacts": {
"access": "readwrite",
"description": "Testing"
},
"device-storage:sdcard": {
"access": "readwrite",
"description": "Testing"
},
"fmradio": {
"description": "Testing"
},
"storage": {
"description": "Testing"
},
"systemXHR": {
"description": "Testing"
},
"tcp-socket": {
"description": "Testing"
}
},
"package_path": "marketplace_privileged_app.zip"
}

View File

@ -0,0 +1 @@
Content-Type: application/x-web-app-manifest+json

View File

@ -0,0 +1,20 @@
{
"name": "Stopwatch",
"description": "Simple stopwatch",
"launch_path": "/index.html",
"icons": {
"128": "/static/img/icon.png"
},
"developer": {
"name": "Andy McKay",
"url": "http://www.agmweb.ca/blog/andy/"
},
"locales": {
"fr": {
"description": "Simple chronomètre"
}
},
"installs_allowed_from": ["*"],
"default_locale": "en",
"package_path": "marketplace_reviewers_app.zip"
}

View File

@ -0,0 +1 @@
Content-Type: application/x-web-app-manifest+json

View File

@ -14,10 +14,14 @@ support-files =
signed_app_template.webapp
signed/*
test_packaged_app_common.js
marketplace/*
pkg_install_iframe.html
[test_app_update.html]
[test_bug_795164.html]
[test_install_receipts.html]
[test_marketplace_pkg_install.html]
skip-if = buildapp == "b2g" || toolkit == "android" # see bug 989806
[test_packaged_app_install.html]
[test_packaged_app_update.html]
[test_receipt_operations.html]

View File

@ -0,0 +1,26 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Cross Origin Helper</title>
</head>
<body>
<script type="application/javascript">
window.addEventListener("message", function onMessage(event) {
window.removeEventListener("message", onMessage, false);
var request = navigator.mozApps.installPackage(event.data);
request.onerror = function() {
parent.postMessage("Error: " + this.error.name, "*");
};
request.onsuccess = function() {
parent.postMessage("Application installed", "*");
};
}, false);
</script>
</body>
</html>

View File

@ -102,7 +102,7 @@ function readFile(path) {
function makeResource(templatePath, version, packagePath, packageSize,
appName, developerName, developerUrl) {
var res = readFile(templatePath, false).
var res = readFile(templatePath).
replace(/VERSIONTOKEN/g, version).
replace(/PACKAGEPATHTOKEN/g, packagePath).
replace(/PACKAGESIZETOKEN/g, packageSize).

View File

@ -0,0 +1,198 @@
<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=989806
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 989806</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="test_packaged_app_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=989806">Mozilla Bug 989806</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="application/javascript;version=1.7">
"use strict";
let gApp = null;
let gExternalInstallOrigin = "http://mochi.test:8888/";
let gExternalAppsPath = gExternalInstallOrigin + "tests/dom/apps/tests/marketplace/";
let gMarketplaceInstallOrigin = "https://marketplace.firefox.com/";
let gMarketplaceAppsPath = gMarketplaceInstallOrigin + "tests/dom/apps/tests/marketplace/";
SimpleTest.waitForExplicitFinish();
function checkAppOnInstallSuccess(aExpected) {
navigator.mozApps.mgmt.oninstall = function(evt) {
info("Got oninstall event");
gApp = evt.application;
gApp.ondownloaderror = function() {
ok(false, "Download should succeed (got error: " +
gApp.downloadError.name + ")");
PackagedTestHelper.finish();
};
gApp.ondownloadsuccess = function() {
info("App downloaded");
PackagedTestHelper.checkAppState(gApp, aExpected.version, aExpected,
true, true, PackagedTestHelper.next);
};
};
}
function checkAppOnInstallError(aExpectedError) {
navigator.mozApps.mgmt.oninstall = function(evt) {
info("Got oninstall event");
gApp = evt.application;
gApp.ondownloaderror = function() {
is(gApp.downloadError.name, aExpectedError,
"Download fails with expected error: " + aExpectedError);
if (gApp.downloadError.name != aExpectedError) {
PackagedTestHelper.finish();
} else {
PackagedTestHelper.next();
}
};
gApp.ondownloadsuccess = function() {
ok(false, "App download should fail");
PackagedTestHelper.finish();
};
};
}
function checkUninstallApp(aApp) {
let req = navigator.mozApps.mgmt.uninstall(aApp);
req.onsuccess = function() {
info("App uninstalled");
aApp.ondownloadsuccess = null;
aApp.ondownloaderror = null;
aApp.onprogress = null;
PackagedTestHelper.next();
};
req.onerror = function(evt) {
ok(false, "App uninstallation should succeed (got unexpected " +
evt.target.error.name + ")");
PackagedTestHelper.finish();
};
}
function installApp(installOrigin, manifestURL) {
let domParent = document.getElementById('container');
let ifr = document.createElement('iframe');
ifr.setAttribute('mozbrowser', 'true');
ifr.setAttribute("src", installOrigin + "tests/dom/apps/tests/pkg_install_iframe.html");
ifr.addEventListener("load", function onIFrameLoad() {
ifr.removeEventListener("load", onIFrameLoad, false);
ifr.contentWindow.postMessage(manifestURL, "*");
}, false);
ifr.addEventListener("mozbrowsererror", function onCertError(e) {
ifr.removeEventListener("mozbrowsererror", onCertError);
ok(false, "mozbrowsererror: " + e.detail.type);
domParent.removeChild(ifr);
PackagedTestHelper.finish();
});
window.addEventListener("message", function onMessage(event) {
window.removeEventListener("message", onMessage);
is(event.data, "Application installed", "Application installed");
domParent.removeChild(ifr);
});
domParent.appendChild(ifr);
}
PackagedTestHelper.setSteps([
function() {
SpecialPowers.setAllAppsLaunchable(true);
SpecialPowers.addPermission("webapps-manage", true, document);
SpecialPowers.addPermission("browser", true, document);
SpecialPowers.autoConfirmAppInstall(() =>
SpecialPowers.pushPrefEnv({set: [["dom.mozBrowserFramesEnabled", true]]},
PackagedTestHelper.next));
},
function() {
info("== TEST == Marketplace packaged app from https://marketplace.firefox.com/");
let miniManifestURL = gMarketplaceAppsPath + "marketplace_app.webapp"
let expected = {
name: "Flashlight (Linterna)",
manifestURL: miniManifestURL,
installOrigin: gMarketplaceInstallOrigin.slice(0, -1),
progress: 0,
installState: "installed",
downloadAvailable: false,
downloading: false,
readyToApplyDownload: false,
launch_path: "/index.html",
version: "2.0",
};
checkAppOnInstallSuccess(expected);
installApp(gMarketplaceInstallOrigin, miniManifestURL);
},
function() {
info("== TEST == Marketplace privileged app from https://marketplace.firefox.com/");
let miniManifestURL = gMarketplaceAppsPath + "marketplace_privileged_app.webapp"
let expected = {
name: "KitchenSink",
manifestURL: miniManifestURL,
installOrigin: gMarketplaceInstallOrigin.slice(0, -1),
progress: 0,
installState: "installed",
downloadAvailable: false,
downloading: false,
readyToApplyDownload: false,
launch_path: "/index.html",
version: "0.2.2",
};
checkAppOnInstallSuccess(expected);
installApp(gMarketplaceInstallOrigin, miniManifestURL);
},
function() {
info("== TEST == Marketplace reviewers packaged app from https://marketplace.firefox.com/");
checkAppOnInstallError("INVALID_SIGNATURE");
installApp(gMarketplaceInstallOrigin, gMarketplaceAppsPath + "marketplace_reviewers_app.webapp");
},
function() {
info("== TEST == Marketplace packaged app not from https://marketplace.firefox.com/");
checkAppOnInstallError("INSTALL_FROM_DENIED");
installApp(gExternalInstallOrigin, gExternalAppsPath + "marketplace_app.webapp");
},
function() {
info("== TEST == Marketplace privileged app not from https://marketplace.firefox.com/");
checkAppOnInstallError("INSTALL_FROM_DENIED");
installApp(gExternalInstallOrigin, gExternalAppsPath + "marketplace_privileged_app.webapp");
},
function() {
info("== TEST == Marketplace reviewers packaged app not from https://marketplace.firefox.com/");
checkAppOnInstallError("INVALID_SIGNATURE");
installApp(gExternalInstallOrigin, gExternalAppsPath + "marketplace_reviewers_app.webapp");
},
function() {
PackagedTestHelper.finish();
}
]);
addLoadEvent(PackagedTestHelper.start);
</script>
</pre>
<div id="container"></div>
</body>
</html>

View File

@ -52,6 +52,7 @@ var PackagedTestHelper = (function PackagedTestHelper() {
clearTimeout(timeoutID);
}
SpecialPowers.removePermission("webapps-manage", document);
SpecialPowers.removePermission("browser", document);
SimpleTest.finish();
}
@ -165,7 +166,7 @@ var PackagedTestHelper = (function PackagedTestHelper() {
is(aApp.manifest.size, aExpectedApp.size, "Check size");
}
if (aApp.manifest) {
is(aApp.manifest.launch_path, gSJSPath, "Check launch path");
is(aApp.manifest.launch_path, aExpectedApp.launch_path || gSJSPath, "Check launch path");
}
if (aExpectedApp.manifestURL) {
is(aApp.manifestURL, aExpectedApp.manifestURL, "Check manifestURL");