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 */
11 /* import-globals-from head_websocket.js */
13 // These test should basically match the ones in test_websocket_server.js,
14 // but with multiple websocket clients making requests on the same server
16 const certOverrideService
= Cc
[
17 "@mozilla.org/security/certoverride;1"
18 ].getService(Ci
.nsICertOverrideService
);
21 add_setup(async
function setup() {
22 // turn off cert checking for these tests
23 certOverrideService
.setDisableAllSecurityChecksAndLetAttackersInterceptMyData(
28 // append cleanup to cleanup queue
29 registerCleanupFunction(async () => {
30 certOverrideService
.setDisableAllSecurityChecksAndLetAttackersInterceptMyData(
33 Services
.prefs
.clearUserPref("network.http.http2.websockets");
36 async
function spinup_and_check(proxy_kind
, ws_kind
) {
38 if (ws_kind
== NodeWebSocketServer
) {
42 Services
.prefs
.setBoolPref("network.http.http2.websockets", ws_h2
);
46 proxy
= new proxy_kind();
48 registerCleanupFunction(async () => proxy
.stop());
51 let wss
= new ws_kind();
53 registerCleanupFunction(async () => wss
.stop());
55 Assert
.notEqual(wss
.port(), null);
56 await wss
.registerMessageHandler((data
, ws
) => {
59 let url
= `wss://localhost:${wss.port()}`;
61 let conn1
= new WebSocketConnection();
62 await conn1
.open(url
);
64 let conn2
= new WebSocketConnection();
65 await conn2
.open(url
);
70 let mess2
= await conn2
.receiveMessages();
71 Assert
.deepEqual(mess2
, ["msg2"]);
73 conn1
.send("msg1 again");
75 while (mess1
.length
< 2) {
76 // receive could return only the first or both replies.
77 mess1
= mess1
.concat(await conn1
.receiveMessages());
79 Assert
.deepEqual(mess1
, ["msg1", "msg1 again"]);
83 Assert
.deepEqual({ status
: Cr
.NS_OK
}, await conn1
.finished());
84 Assert
.deepEqual({ status
: Cr
.NS_OK
}, await conn2
.finished());
93 async
function test_h1_websocket_direct() {
94 await
spinup_and_check(null, NodeWebSocketServer
);
98 async
function test_h2_websocket_direct() {
99 await
spinup_and_check(null, NodeWebSocketHttp2Server
);
102 // ws h1.1 with secure h1.1 proxy
103 async
function test_h1_ws_with_secure_h1_proxy() {
104 await
spinup_and_check(NodeHTTPSProxyServer
, NodeWebSocketServer
);
107 // ws h1.1 with insecure h1.1 proxy
108 async
function test_h1_ws_with_insecure_h1_proxy() {
109 await
spinup_and_check(NodeHTTPProxyServer
, NodeWebSocketServer
);
112 // ws h1.1 with h2 proxy
113 async
function test_h1_ws_with_h2_proxy() {
114 await
spinup_and_check(NodeHTTP2ProxyServer
, NodeWebSocketServer
);
117 // ws h2 with insecure h1.1 proxy
118 async
function test_h2_ws_with_insecure_h1_proxy() {
119 await
spinup_and_check(NodeHTTPProxyServer
, NodeWebSocketHttp2Server
);
122 // ws h2 with secure h1 proxy
123 async
function test_h2_ws_with_secure_h1_proxy() {
124 await
spinup_and_check(NodeHTTPSProxyServer
, NodeWebSocketHttp2Server
);
127 // ws h2 with secure h2 proxy
128 async
function test_h2_ws_with_h2_proxy() {
129 await
spinup_and_check(NodeHTTP2ProxyServer
, NodeWebSocketHttp2Server
);
132 add_task(test_h1_websocket_direct
);
133 add_task(test_h2_websocket_direct
);
134 add_task(test_h1_ws_with_secure_h1_proxy
);
135 add_task(test_h1_ws_with_insecure_h1_proxy
);
136 add_task(test_h1_ws_with_h2_proxy
);
138 // any multi-client test with h2 websocket and any kind of proxy will fail/hang
139 add_task(test_h2_ws_with_insecure_h1_proxy
);
140 add_task(test_h2_ws_with_secure_h1_proxy
);
141 add_task(test_h2_ws_with_h2_proxy
);