Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / netwerk / test / unit / test_websocket_fails_2.js
blob57c9b321ad90aa6f3b88619a5f95393b91255768
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/. */
5 "use strict";
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 */
11 /* import-globals-from head_websocket.js */
13 let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
14 Ci.nsIX509CertDB
17 add_setup(() => {
18 Services.prefs.setBoolPref("network.http.http2.websockets", true);
19 });
21 registerCleanupFunction(() => {
22 Services.prefs.clearUserPref("network.http.http2.websockets");
23 });
25 // TLS handshake to the end server fails with proxy
26 async function test_tls_fail_on_ws_server_over_proxy() {
27 // we are expecting a timeout, so lets shorten how long we must wait
28 Services.prefs.setIntPref("network.websocket.timeout.open", 1);
30 // no cert to ws server
31 addCertFromFile(certdb, "proxy-ca.pem", "CTu,u,u");
33 let proxy = new NodeHTTPSProxyServer();
34 await proxy.start();
36 let wss = new NodeWebSocketServer();
37 await wss.start();
39 registerCleanupFunction(async () => {
40 await wss.stop();
41 await proxy.stop();
42 Services.prefs.clearUserPref("network.websocket.timeout.open");
43 });
45 Assert.notEqual(wss.port(), null);
46 await wss.registerMessageHandler((data, ws) => {
47 ws.send(data);
48 });
50 let chan = makeWebSocketChan();
51 let url = `wss://localhost:${wss.port()}`;
52 const msg = "test tls fail on ws server over proxy";
53 let [status] = await openWebSocketChannelPromise(chan, url, msg);
55 Assert.equal(status, Cr.NS_ERROR_NET_TIMEOUT_EXTERNAL);
57 add_task(test_tls_fail_on_ws_server_over_proxy);