Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <?xml version="1.0"?> |
michael@0 | 2 | <!-- |
michael@0 | 3 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 4 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 5 | */ |
michael@0 | 6 | --> |
michael@0 | 7 | |
michael@0 | 8 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 9 | <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> |
michael@0 | 10 | |
michael@0 | 11 | <window title="Test CertUtils.jsm checkCert - bug 340198 and bug 544442" |
michael@0 | 12 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
michael@0 | 13 | onload="testStart();"> |
michael@0 | 14 | <script type="application/javascript" |
michael@0 | 15 | src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
michael@0 | 16 | |
michael@0 | 17 | <script type="application/javascript"> |
michael@0 | 18 | <![CDATA[ |
michael@0 | 19 | |
michael@0 | 20 | const Cc = Components.classes; |
michael@0 | 21 | const Ci = Components.interfaces; |
michael@0 | 22 | const Cr = Components.results; |
michael@0 | 23 | |
michael@0 | 24 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 25 | |
michael@0 | 26 | Components.utils.import("resource://gre/modules/CertUtils.jsm"); |
michael@0 | 27 | |
michael@0 | 28 | function testStart() { |
michael@0 | 29 | ok(true, "Entering testStart"); |
michael@0 | 30 | |
michael@0 | 31 | var request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]. |
michael@0 | 32 | createInstance(Ci.nsIXMLHttpRequest); |
michael@0 | 33 | request.open("GET", "https://example.com/", true); |
michael@0 | 34 | request.channel.notificationCallbacks = new BadCertHandler(true); |
michael@0 | 35 | request.onerror = function(event) { testXHRError(event); }; |
michael@0 | 36 | request.onload = function(event) { testXHRLoad(event); }; |
michael@0 | 37 | request.send(null); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | function testXHRError(aEvent) { |
michael@0 | 41 | ok(true, "Entering testXHRError - something went wrong"); |
michael@0 | 42 | |
michael@0 | 43 | var request = aEvent.target; |
michael@0 | 44 | var status = 0; |
michael@0 | 45 | try { |
michael@0 | 46 | status = request.status; |
michael@0 | 47 | } |
michael@0 | 48 | catch (e) { |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | if (status == 0) |
michael@0 | 52 | status = request.channel.QueryInterface(Ci.nsIRequest).status; |
michael@0 | 53 | |
michael@0 | 54 | ok(false, "XHR onerror called: " + status); |
michael@0 | 55 | |
michael@0 | 56 | SimpleTest.finish(); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function getCheckCertResult(aChannel, aAllowNonBuiltIn, aCerts) { |
michael@0 | 60 | try { |
michael@0 | 61 | checkCert(aChannel, aAllowNonBuiltIn, aCerts); |
michael@0 | 62 | } |
michael@0 | 63 | catch (e) { |
michael@0 | 64 | return e.result; |
michael@0 | 65 | } |
michael@0 | 66 | return Cr.NS_OK; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | function testXHRLoad(aEvent) { |
michael@0 | 70 | ok(true, "Entering testXHRLoad"); |
michael@0 | 71 | |
michael@0 | 72 | var channel = aEvent.target.channel; |
michael@0 | 73 | |
michael@0 | 74 | var certs = null; |
michael@0 | 75 | is(getCheckCertResult(channel, false, certs), Cr.NS_ERROR_ABORT, |
michael@0 | 76 | "checkCert should throw NS_ERROR_ABORT when the certificate attributes " + |
michael@0 | 77 | "array passed to checkCert is null and the certificate is not builtin"); |
michael@0 | 78 | |
michael@0 | 79 | is(getCheckCertResult(channel, true, certs), Cr.NS_OK, |
michael@0 | 80 | "checkCert should not throw when the certificate attributes array " + |
michael@0 | 81 | "passed to checkCert is null and builtin certificates aren't enforced"); |
michael@0 | 82 | |
michael@0 | 83 | certs = [ { invalidAttribute: "Invalid attribute" } ]; |
michael@0 | 84 | is(getCheckCertResult(channel, false, certs), Cr.NS_ERROR_ILLEGAL_VALUE, |
michael@0 | 85 | "checkCert should throw NS_ERROR_ILLEGAL_VALUE when the certificate " + |
michael@0 | 86 | "attributes array passed to checkCert has an element that has an " + |
michael@0 | 87 | "attribute that does not exist on the certificate"); |
michael@0 | 88 | |
michael@0 | 89 | certs = [ { issuerName: "Incorrect issuerName" } ]; |
michael@0 | 90 | is(getCheckCertResult(channel, false, certs), Cr.NS_ERROR_ILLEGAL_VALUE, |
michael@0 | 91 | "checkCert should throw NS_ERROR_ILLEGAL_VALUE when the certificate " + |
michael@0 | 92 | "attributes array passed to checkCert has an element that has an " + |
michael@0 | 93 | "issuerName that is not the same as the certificate's"); |
michael@0 | 94 | |
michael@0 | 95 | var cert = channel.securityInfo.QueryInterface(Ci.nsISSLStatusProvider). |
michael@0 | 96 | SSLStatus.QueryInterface(Ci.nsISSLStatus).serverCert; |
michael@0 | 97 | |
michael@0 | 98 | certs = [ { issuerName: cert.issuerName, |
michael@0 | 99 | commonName: cert.commonName } ]; |
michael@0 | 100 | is(getCheckCertResult(channel, false, certs), Cr.NS_ERROR_ABORT, |
michael@0 | 101 | "checkCert should throw NS_ERROR_ABORT when the certificate attributes " + |
michael@0 | 102 | "array passed to checkCert has a single element that has the same " + |
michael@0 | 103 | "issuerName and commonName as the certificate's and the certificate is " + |
michael@0 | 104 | "not builtin"); |
michael@0 | 105 | |
michael@0 | 106 | is(getCheckCertResult(channel, true, certs), Cr.NS_OK, |
michael@0 | 107 | "checkCert should not throw when the certificate attributes array " + |
michael@0 | 108 | "passed to checkCert has a single element that has the same issuerName " + |
michael@0 | 109 | "and commonName as the certificate's and and builtin certificates " + |
michael@0 | 110 | "aren't enforced"); |
michael@0 | 111 | |
michael@0 | 112 | certs = [ { issuerName: "Incorrect issuerName", |
michael@0 | 113 | invalidAttribute: "Invalid attribute" }, |
michael@0 | 114 | { issuerName: cert.issuerName, |
michael@0 | 115 | commonName: "Invalid Common Name" }, |
michael@0 | 116 | { issuerName: cert.issuerName, |
michael@0 | 117 | commonName: cert.commonName } ]; |
michael@0 | 118 | is(getCheckCertResult(channel, false, certs), Cr.NS_ERROR_ABORT, |
michael@0 | 119 | "checkCert should throw NS_ERROR_ABORT when the certificate attributes " + |
michael@0 | 120 | "array passed to checkCert has an element that has the same issuerName " + |
michael@0 | 121 | "and commonName as the certificate's and the certificate is not builtin"); |
michael@0 | 122 | |
michael@0 | 123 | is(getCheckCertResult(channel, true, certs), Cr.NS_OK, |
michael@0 | 124 | "checkCert should not throw when the certificate attributes array " + |
michael@0 | 125 | "passed to checkCert has an element that has the same issuerName and " + |
michael@0 | 126 | "commonName as the certificate's and builtin certificates aren't enforced"); |
michael@0 | 127 | |
michael@0 | 128 | var mockChannel = { originalURI: Cc["@mozilla.org/network/io-service;1"]. |
michael@0 | 129 | getService(Ci.nsIIOService). |
michael@0 | 130 | newURI("http://example.com/", null, null) }; |
michael@0 | 131 | |
michael@0 | 132 | certs = [ ]; |
michael@0 | 133 | is(getCheckCertResult(mockChannel, false, certs), Cr.NS_ERROR_UNEXPECTED, |
michael@0 | 134 | "checkCert should throw NS_ERROR_UNEXPECTED when the certificate " + |
michael@0 | 135 | "attributes array passed to checkCert is not null and the channel's " + |
michael@0 | 136 | "originalURI is not https"); |
michael@0 | 137 | |
michael@0 | 138 | certs = null; |
michael@0 | 139 | is(getCheckCertResult(mockChannel, false, certs), Cr.NS_OK, |
michael@0 | 140 | "checkCert should not throw when the certificate attributes object " + |
michael@0 | 141 | "passed to checkCert is null and the the channel's originalURI is not " + |
michael@0 | 142 | "https"); |
michael@0 | 143 | |
michael@0 | 144 | SimpleTest.finish(); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | ]]> |
michael@0 | 148 | </script> |
michael@0 | 149 | |
michael@0 | 150 | <body xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 151 | <p id="display"></p> |
michael@0 | 152 | <div id="content" style="display: none"></div> |
michael@0 | 153 | <pre id="test"></pre> |
michael@0 | 154 | </body> |
michael@0 | 155 | </window> |