test_websocket_fails_2.js (2045B)
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/. */ 4 5 "use strict"; 6 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_websocket.js */ 11 12 const { NodeHTTPSProxyServer, NodeWebSocketServer } = 13 ChromeUtils.importESModule("resource://testing-common/NodeServer.sys.mjs"); 14 15 // We don't normally allow localhost channels to be proxied, but this 16 // is easier than updating all the certs and/or domains. 17 Services.prefs.setBoolPref("network.proxy.allow_hijacking_localhost", true); 18 registerCleanupFunction(() => { 19 Services.prefs.clearUserPref("network.proxy.allow_hijacking_localhost"); 20 }); 21 22 add_setup(() => { 23 Services.prefs.setBoolPref("network.http.http2.websockets", true); 24 }); 25 26 registerCleanupFunction(() => { 27 Services.prefs.clearUserPref("network.http.http2.websockets"); 28 }); 29 30 // TLS handshake to the end server fails with proxy 31 async function test_tls_fail_on_ws_server_over_proxy() { 32 // we are expecting a timeout, so lets shorten how long we must wait 33 Services.prefs.setIntPref("network.websocket.timeout.open", 1); 34 35 let proxy = new NodeHTTPSProxyServer(); 36 await proxy.start(); 37 38 let wss = new NodeWebSocketServer(); 39 // no cert to ws server 40 wss._skipCert = true; 41 await wss.start(); 42 43 registerCleanupFunction(async () => { 44 await wss.stop(); 45 await proxy.stop(); 46 Services.prefs.clearUserPref("network.websocket.timeout.open"); 47 }); 48 49 Assert.notEqual(wss.port(), null); 50 await wss.registerMessageHandler((data, ws) => { 51 ws.send(data); 52 }); 53 54 let chan = makeWebSocketChan(); 55 let url = `wss://localhost:${wss.port()}`; 56 const msg = "test tls fail on ws server over proxy"; 57 let [status] = await openWebSocketChannelPromise(chan, url, msg); 58 59 Assert.equal(status, Cr.NS_ERROR_NET_TIMEOUT_EXTERNAL); 60 } 61 add_task(test_tls_fail_on_ws_server_over_proxy);