1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/update/tests/chrome/test_0121_check_requireBuiltinCert.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,112 @@ 1.4 +<?xml version="1.0"?> 1.5 +<!-- 1.6 +/* Any copyright is dedicated to the Public Domain. 1.7 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.8 + */ 1.9 +--> 1.10 + 1.11 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.12 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> 1.13 + 1.14 +<window title="Test update check with certificate that is not built-in and valid certificate attribute names and values" 1.15 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.16 + onload="runTestDefault();"> 1.17 +<script type="application/javascript" 1.18 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.19 +<script type="application/javascript" 1.20 + src="utils.js"/> 1.21 + 1.22 +<script type="application/javascript"> 1.23 +<![CDATA[ 1.24 + 1.25 +const TESTS = [ { 1.26 + pageid: PAGEID_CHECKING 1.27 +}, { 1.28 + pageid: PAGEID_ERRORS, 1.29 + buttonClick: "finish" 1.30 +} ]; 1.31 + 1.32 +Components.utils.import("resource://gre/modules/CertUtils.jsm"); 1.33 + 1.34 +const CERT_ATTRS = ["nickname", "emailAddress", "subjectName", "commonName", 1.35 + "organization", "organizationalUnit", "sha1Fingerprint", 1.36 + "md5Fingerprint", "tokenName", "issuerName", "serialNumber", 1.37 + "issuerCommonName", "issuerOrganization", 1.38 + "issuerOrganizationUnit", "dbKey", "windowTitle"]; 1.39 + 1.40 +var gRequest; 1.41 + 1.42 +function runTest() { 1.43 + debugDump("entering"); 1.44 + 1.45 + gRequest = AUS_Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]. 1.46 + createInstance(AUS_Ci.nsIXMLHttpRequest); 1.47 + gRequest.open("GET", "https://example.com/", true); 1.48 + gRequest.channel.notificationCallbacks = new BadCertHandler(true); 1.49 + gRequest.onload = function(event) { testXHRLoad(event); }; 1.50 + gRequest.onerror = function(event) { testXHRError(event); }; 1.51 + gRequest.send(null); 1.52 +} 1.53 + 1.54 +function testXHRError(aEvent) { 1.55 + debugDump("entering"); 1.56 + 1.57 + ok(true, "Entering testXHRError - something went wrong"); 1.58 + 1.59 + var request = aEvent.target; 1.60 + var status = 0; 1.61 + try { 1.62 + status = request.status; 1.63 + } 1.64 + catch (e) { 1.65 + } 1.66 + 1.67 + if (status == 0) 1.68 + status = request.channel.QueryInterface(AUS_Ci.nsIRequest).status; 1.69 + 1.70 + ok(false, "XHR onerror called: " + status); 1.71 + 1.72 + gRequest = null; 1.73 + finishTestDefault(); 1.74 +} 1.75 + 1.76 +function testXHRLoad(aEvent) { 1.77 + debugDump("entering"); 1.78 + 1.79 + var channel = aEvent.target.channel; 1.80 + var cert = channel.securityInfo.QueryInterface(AUS_Ci.nsISSLStatusProvider). 1.81 + SSLStatus.QueryInterface(AUS_Ci.nsISSLStatus).serverCert; 1.82 + CERT_ATTRS.forEach(function(aCertAttrName) { 1.83 + Services.prefs.setCharPref(PREF_APP_UPDATE_CERTS_BRANCH + "1." + 1.84 + aCertAttrName, cert[aCertAttrName]); 1.85 + }); 1.86 + 1.87 + Services.prefs.setBoolPref(PREF_APP_UPDATE_CERT_REQUIREBUILTIN, true); 1.88 + Services.prefs.setBoolPref(PREF_APP_UPDATE_CERT_CHECKATTRS, false); 1.89 + 1.90 + let url = URL_HTTPS_UPDATE_XML + "?showDetails=1" + getVersionParams(); 1.91 + gAppUpdateURLDefault = gDefaultPrefBranch.getCharPref(PREF_APP_UPDATE_URL); 1.92 + debugDump("setting default pref " + PREF_APP_UPDATE_URL + " to " + url); 1.93 + gDefaultPrefBranch.setCharPref(PREF_APP_UPDATE_URL, url); 1.94 + 1.95 + gRequest = null; 1.96 + gUP.checkForUpdates(); 1.97 +} 1.98 + 1.99 +function finishTest() { 1.100 + if (gRequest) { 1.101 + gRequest.abort(); 1.102 + gRequest = null; 1.103 + } 1.104 + finishTestDefault(); 1.105 +} 1.106 + 1.107 +]]> 1.108 +</script> 1.109 + 1.110 +<body xmlns="http://www.w3.org/1999/xhtml"> 1.111 + <p id="display"></p> 1.112 + <div id="content" style="display: none"></div> 1.113 + <pre id="test"></pre> 1.114 +</body> 1.115 +</window>