1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* import-globals-from head_cache.js */
8 /* import-globals-from head_cookies.js */
9 /* import-globals-from head_channels.js */
10 /* import-globals-from head_servers.js */
12 function makeChan(uri) {
13 let chan = NetUtil.newChannel({
15 loadUsingSystemPrincipal: true,
16 }).QueryInterface(Ci.nsIHttpChannel);
17 chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
21 async function test_cert_failure(server_creator, https_proxy) {
22 let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
25 addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u");
26 addCertFromFile(certdb, "proxy-ca.pem", "CTu,u,u");
28 let server = new server_creator();
30 registerCleanupFunction(async () => {
34 await server.registerPathHandler("/test", (req, resp) => {
39 if (server_creator == NodeHTTPServer) {
40 url = `http://localhost:${server.port()}/test`;
42 url = `https://localhost:${server.port()}/test`;
44 let chan = makeChan(url);
45 let req = await new Promise(resolve => {
46 chan.asyncOpen(new ChannelListener(resolve, null, CL_ALLOW_UNKNOWN_CL));
48 equal(req.status, Cr.NS_OK);
49 equal(req.QueryInterface(Ci.nsIHttpChannel).responseStatus, 200);
50 let secinfo = req.securityInfo;
51 if (server_creator == NodeHTTPServer) {
53 Assert.equal(secinfo, null);
55 // In the case we are connecting to an insecure HTTP server
56 // through a secure proxy, nsHttpChannel will have the security
57 // info from the proxy.
58 // We will discuss this behavir in bug 1785777.
59 secinfo.QueryInterface(Ci.nsITransportSecurityInfo);
60 Assert.equal(secinfo.serverCert.commonName, " Proxy Test Cert");
63 secinfo.QueryInterface(Ci.nsITransportSecurityInfo);
64 Assert.equal(secinfo.serverCert.commonName, " HTTP2 Test Cert");
68 add_task(async function test_http() {
69 await test_cert_failure(NodeHTTPServer, false);
72 add_task(async function test_https() {
73 await test_cert_failure(NodeHTTPSServer, false);
76 add_task(async function test_http2() {
77 await test_cert_failure(NodeHTTP2Server, false);
80 add_task(async function test_http_proxy_http_server() {
81 let proxy = new NodeHTTPProxyServer();
83 registerCleanupFunction(() => {
86 await test_cert_failure(NodeHTTPServer, false);
89 add_task(async function test_http_proxy_https_server() {
90 let proxy = new NodeHTTPProxyServer();
92 registerCleanupFunction(() => {
95 await test_cert_failure(NodeHTTPSServer, false);
98 add_task(async function test_http_proxy_http2_server() {
99 let proxy = new NodeHTTPProxyServer();
101 registerCleanupFunction(() => {
104 await test_cert_failure(NodeHTTP2Server, false);
107 add_task(async function test_https_proxy_http_server() {
108 let proxy = new NodeHTTPSProxyServer();
110 registerCleanupFunction(() => {
113 await test_cert_failure(NodeHTTPServer, true);
116 add_task(async function test_https_proxy_https_server() {
117 let proxy = new NodeHTTPSProxyServer();
119 registerCleanupFunction(() => {
122 await test_cert_failure(NodeHTTPSServer, true);
125 add_task(async function test_https_proxy_http2_server() {
126 let proxy = new NodeHTTPSProxyServer();
128 registerCleanupFunction(() => {
131 await test_cert_failure(NodeHTTP2Server, true);
134 add_task(async function test_http2_proxy_http_server() {
135 let proxy = new NodeHTTP2ProxyServer();
137 registerCleanupFunction(() => {
141 await test_cert_failure(NodeHTTPServer, true);
144 add_task(async function test_http2_proxy_https_server() {
145 let proxy = new NodeHTTP2ProxyServer();
147 registerCleanupFunction(() => {
151 await test_cert_failure(NodeHTTPSServer, true);
154 add_task(async function test_http2_proxy_http2_server() {
155 let proxy = new NodeHTTP2ProxyServer();
157 registerCleanupFunction(() => {
161 await test_cert_failure(NodeHTTP2Server, true);