1 /* import-globals-from http2_test_common.js */
3 const { HttpServer
} = ChromeUtils
.importESModule(
4 "resource://testing-common/httpd.sys.mjs"
7 var concurrent_channels
= [];
14 function altsvcHttp1Server(metadata
, response
) {
15 response
.setStatusLine(metadata
.httpVersion
, 200, "OK");
16 response
.setHeader("Content-Type", "text/plain", false);
17 response
.setHeader("Connection", "close", false);
18 response
.setHeader("Alt-Svc", 'h2=":' + serverPort
+ '"', false);
19 var body
= "this is where a cool kid would write something neat.\n";
20 response
.bodyOutputStream
.write(body
, body
.length
);
23 function h1ServerWK(metadata
, response
) {
24 response
.setStatusLine(metadata
.httpVersion
, 200, "OK");
25 response
.setHeader("Content-Type", "application/json", false);
26 response
.setHeader("Connection", "close", false);
27 response
.setHeader("Cache-Control", "no-cache", false);
28 response
.setHeader("Access-Control-Allow-Origin", "*", false);
29 response
.setHeader("Access-Control-Allow-Method", "GET", false);
31 var body
= '["http://foo.example.com:' + httpserv
.identity
.primaryPort
+ '"]';
32 response
.bodyOutputStream
.write(body
, body
.length
);
35 function altsvcHttp1Server2(metadata
, response
) {
36 // this server should never be used thanks to an alt svc frame from the
37 // h2 server.. but in case of some async lag in setting the alt svc route
39 response
.setStatusLine(metadata
.httpVersion
, 200, "OK");
40 response
.setHeader("Content-Type", "text/plain", false);
41 response
.setHeader("Connection", "close", false);
42 var body
= "hanging.\n";
43 response
.bodyOutputStream
.write(body
, body
.length
);
46 function h1ServerWK2(metadata
, response
) {
47 response
.setStatusLine(metadata
.httpVersion
, 200, "OK");
48 response
.setHeader("Content-Type", "application/json", false);
49 response
.setHeader("Connection", "close", false);
50 response
.setHeader("Cache-Control", "no-cache", false);
51 response
.setHeader("Access-Control-Allow-Origin", "*", false);
52 response
.setHeader("Access-Control-Allow-Method", "GET", false);
55 '["http://foo.example.com:' + httpserv2
.identity
.primaryPort
+ '"]';
56 response
.bodyOutputStream
.write(body
, body
.length
);
59 add_setup(async
function setup() {
60 serverPort
= Services
.env
.get("MOZHTTP2_PORT");
61 Assert
.notEqual(serverPort
, null);
62 dump("using port " + serverPort
+ "\n");
64 // Set to allow the cert presented by our H2 server
67 Services
.prefs
.setIntPref("network.http.speculative-parallel-limit", 0);
69 // The moz-http2 cert is for foo.example.com and is signed by http2-ca.pem
70 // so add that cert to the trust list as a signing cert. Some older tests in
71 // this suite use localhost with a TOFU exception, but new ones should use
73 let certdb
= Cc
["@mozilla.org/security/x509certdb;1"].getService(
76 addCertFromFile(certdb
, "http2-ca.pem", "CTu,u,u");
78 Services
.prefs
.setBoolPref("network.http.http2.enabled", true);
79 Services
.prefs
.setBoolPref("network.http.http2.allow-push", true);
80 Services
.prefs
.setBoolPref("network.http.altsvc.enabled", true);
81 Services
.prefs
.setBoolPref("network.http.altsvc.oe", true);
82 Services
.prefs
.setCharPref(
83 "network.dns.localDomains",
84 "foo.example.com, bar.example.com"
86 Services
.prefs
.setBoolPref(
87 "network.cookieJarSettings.unblocked_for_testing",
91 loadGroup
= Cc
["@mozilla.org/network/load-group;1"].createInstance(
95 httpserv
= new HttpServer();
96 httpserv
.registerPathHandler("/altsvc1", altsvcHttp1Server
);
97 httpserv
.registerPathHandler("/.well-known/http-opportunistic", h1ServerWK
);
99 httpserv
.identity
.setPrimary(
102 httpserv
.identity
.primaryPort
105 httpserv2
= new HttpServer();
106 httpserv2
.registerPathHandler("/altsvc2", altsvcHttp1Server2
);
107 httpserv2
.registerPathHandler("/.well-known/http-opportunistic", h1ServerWK2
);
109 httpserv2
.identity
.setPrimary(
112 httpserv2
.identity
.primaryPort
116 registerCleanupFunction(async () => {
117 Services
.prefs
.clearUserPref("network.http.speculative-parallel-limit");
118 Services
.prefs
.clearUserPref("network.http.http2.enabled");
119 Services
.prefs
.clearUserPref("network.http.http2.allow-push");
120 Services
.prefs
.clearUserPref("network.http.altsvc.enabled");
121 Services
.prefs
.clearUserPref("network.http.altsvc.oe");
122 Services
.prefs
.clearUserPref("network.dns.localDomains");
123 Services
.prefs
.clearUserPref(
124 "network.cookieJarSettings.unblocked_for_testing"
126 await httpserv
.stop();
127 await httpserv2
.stop();
130 // hack - the header test resets the multiplex object on the server,
131 // so make sure header is always run before the multiplex test.
133 // make sure post_big runs first to test race condition in restarting
134 // a stalled stream when a SETTINGS frame arrives
135 add_task(async
function do_test_http2_post_big() {
136 const { httpProxyConnectResponseCode
} =
137 await
test_http2_post_big(serverPort
);
138 Assert
.equal(httpProxyConnectResponseCode
, -1);
141 add_task(async
function do_test_http2_basic() {
142 const { httpProxyConnectResponseCode
} = await
test_http2_basic(serverPort
);
143 Assert
.equal(httpProxyConnectResponseCode
, -1);
146 add_task(async
function do_test_http2_concurrent() {
147 const { httpProxyConnectResponseCode
} = await
test_http2_concurrent(
151 Assert
.equal(httpProxyConnectResponseCode
, -1);
154 add_task(async
function do_test_http2_concurrent_post() {
155 const { httpProxyConnectResponseCode
} = await
test_http2_concurrent_post(
159 Assert
.equal(httpProxyConnectResponseCode
, -1);
162 add_task(async
function do_test_http2_basic_unblocked_dep() {
163 const { httpProxyConnectResponseCode
} =
164 await
test_http2_basic_unblocked_dep(serverPort
);
165 Assert
.equal(httpProxyConnectResponseCode
, -1);
168 add_task(async
function do_test_http2_nospdy() {
169 const { httpProxyConnectResponseCode
} = await
test_http2_nospdy(serverPort
);
170 Assert
.equal(httpProxyConnectResponseCode
, -1);
173 add_task(async
function do_test_http2_push1() {
174 const { httpProxyConnectResponseCode
} = await
test_http2_push1(
178 Assert
.equal(httpProxyConnectResponseCode
, -1);
181 add_task(async
function do_test_http2_push2() {
182 const { httpProxyConnectResponseCode
} = await
test_http2_push2(
186 Assert
.equal(httpProxyConnectResponseCode
, -1);
189 add_task(async
function do_test_http2_push3() {
190 const { httpProxyConnectResponseCode
} = await
test_http2_push3(
194 Assert
.equal(httpProxyConnectResponseCode
, -1);
197 add_task(async
function do_test_http2_push4() {
198 const { httpProxyConnectResponseCode
} = await
test_http2_push4(
202 Assert
.equal(httpProxyConnectResponseCode
, -1);
205 add_task(async
function do_test_http2_push5() {
206 const { httpProxyConnectResponseCode
} = await
test_http2_push5(
210 Assert
.equal(httpProxyConnectResponseCode
, -1);
213 add_task(async
function do_test_http2_push6() {
214 const { httpProxyConnectResponseCode
} = await
test_http2_push6(
218 Assert
.equal(httpProxyConnectResponseCode
, -1);
221 add_task(async
function do_test_http2_altsvc() {
222 const { httpProxyConnectResponseCode
} = await
test_http2_altsvc(
223 httpserv
.identity
.primaryPort
,
224 httpserv2
.identity
.primaryPort
,
227 Assert
.equal(httpProxyConnectResponseCode
, -1);
230 add_task(async
function do_test_http2_doubleheader() {
231 const { httpProxyConnectResponseCode
} =
232 await
test_http2_doubleheader(serverPort
);
233 Assert
.equal(httpProxyConnectResponseCode
, -1);
236 add_task(async
function do_test_http2_xhr() {
237 await
test_http2_xhr(serverPort
);
240 add_task(async
function do_test_http2_header() {
241 const { httpProxyConnectResponseCode
} = await
test_http2_header(serverPort
);
242 Assert
.equal(httpProxyConnectResponseCode
, -1);
245 add_task(async
function do_test_http2_invalid_response_header_name_spaces() {
246 const { httpProxyConnectResponseCode
} =
247 await
test_http2_invalid_response_header(serverPort
, "name_spaces");
248 Assert
.equal(httpProxyConnectResponseCode
, -1);
252 async
function do_test_http2_invalid_response_header_value_line_feed() {
253 const { httpProxyConnectResponseCode
} =
254 await
test_http2_invalid_response_header(serverPort
, "value_line_feed");
255 Assert
.equal(httpProxyConnectResponseCode
, -1);
260 async
function do_test_http2_invalid_response_header_value_carriage_return() {
261 const { httpProxyConnectResponseCode
} =
262 await
test_http2_invalid_response_header(
264 "value_carriage_return"
266 Assert
.equal(httpProxyConnectResponseCode
, -1);
270 add_task(async
function do_test_http2_invalid_response_header_value_null() {
271 const { httpProxyConnectResponseCode
} =
272 await
test_http2_invalid_response_header(serverPort
, "value_null");
273 Assert
.equal(httpProxyConnectResponseCode
, -1);
276 add_task(async
function do_test_http2_cookie_crumbling() {
277 const { httpProxyConnectResponseCode
} =
278 await
test_http2_cookie_crumbling(serverPort
);
279 Assert
.equal(httpProxyConnectResponseCode
, -1);
282 add_task(async
function do_test_http2_multiplex() {
283 var values
= await
test_http2_multiplex(serverPort
);
284 Assert
.equal(values
[0].httpProxyConnectResponseCode
, -1);
285 Assert
.equal(values
[1].httpProxyConnectResponseCode
, -1);
286 Assert
.notEqual(values
[0].streamID
, values
[1].streamID
);
289 add_task(async
function do_test_http2_big() {
290 const { httpProxyConnectResponseCode
} = await
test_http2_big(serverPort
);
291 Assert
.equal(httpProxyConnectResponseCode
, -1);
294 add_task(async
function do_test_http2_huge_suspended() {
295 const { httpProxyConnectResponseCode
} =
296 await
test_http2_huge_suspended(serverPort
);
297 Assert
.equal(httpProxyConnectResponseCode
, -1);
300 add_task(async
function do_test_http2_post() {
301 const { httpProxyConnectResponseCode
} = await
test_http2_post(serverPort
);
302 Assert
.equal(httpProxyConnectResponseCode
, -1);
305 add_task(async
function do_test_http2_empty_post() {
306 const { httpProxyConnectResponseCode
} =
307 await
test_http2_empty_post(serverPort
);
308 Assert
.equal(httpProxyConnectResponseCode
, -1);
311 add_task(async
function do_test_http2_patch() {
312 const { httpProxyConnectResponseCode
} = await
test_http2_patch(serverPort
);
313 Assert
.equal(httpProxyConnectResponseCode
, -1);
316 add_task(async
function do_test_http2_pushapi_1() {
317 const { httpProxyConnectResponseCode
} = await
test_http2_pushapi_1(
321 Assert
.equal(httpProxyConnectResponseCode
, -1);
324 add_task(async
function do_test_http2_continuations() {
325 const { httpProxyConnectResponseCode
} = await
test_http2_continuations(
329 Assert
.equal(httpProxyConnectResponseCode
, -1);
332 add_task(async
function do_test_http2_blocking_download() {
333 const { httpProxyConnectResponseCode
} =
334 await
test_http2_blocking_download(serverPort
);
335 Assert
.equal(httpProxyConnectResponseCode
, -1);
338 add_task(async
function do_test_http2_illegalhpacksoft() {
339 const { httpProxyConnectResponseCode
} =
340 await
test_http2_illegalhpacksoft(serverPort
);
341 Assert
.equal(httpProxyConnectResponseCode
, -1);
344 add_task(async
function do_test_http2_illegalhpackhard() {
345 const { httpProxyConnectResponseCode
} =
346 await
test_http2_illegalhpackhard(serverPort
);
347 Assert
.equal(httpProxyConnectResponseCode
, -1);
350 add_task(async
function do_test_http2_folded_header() {
351 const { httpProxyConnectResponseCode
} = await
test_http2_folded_header(
355 Assert
.equal(httpProxyConnectResponseCode
, -1);
358 add_task(async
function do_test_http2_empty_data() {
359 const { httpProxyConnectResponseCode
} =
360 await
test_http2_empty_data(serverPort
);
361 Assert
.equal(httpProxyConnectResponseCode
, -1);
364 add_task(async
function do_test_http2_status_phrase() {
365 const { httpProxyConnectResponseCode
} =
366 await
test_http2_status_phrase(serverPort
);
367 Assert
.equal(httpProxyConnectResponseCode
, -1);
370 add_task(async
function do_test_http2_doublepush() {
371 const { httpProxyConnectResponseCode
} = await
test_http2_doublepush(
375 Assert
.equal(httpProxyConnectResponseCode
, -1);
378 add_task(async
function do_test_http2_disk_cache_push() {
379 const { httpProxyConnectResponseCode
} = await
test_http2_disk_cache_push(
383 Assert
.equal(httpProxyConnectResponseCode
, -1);
386 add_task(async
function do_test_http2_h11required_stream() {
387 // Add new tests above here - best to add new tests before h1
388 // streams get too involved
389 // These next two must always come in this order
390 const { httpProxyConnectResponseCode
} =
391 await
test_http2_h11required_stream(serverPort
);
392 Assert
.equal(httpProxyConnectResponseCode
, -1);
395 add_task(async
function do_test_http2_h11required_session() {
396 const { httpProxyConnectResponseCode
} =
397 await
test_http2_h11required_session(serverPort
);
398 Assert
.equal(httpProxyConnectResponseCode
, -1);
401 add_task(async
function do_test_http2_retry_rst() {
402 const { httpProxyConnectResponseCode
} =
403 await
test_http2_retry_rst(serverPort
);
404 Assert
.equal(httpProxyConnectResponseCode
, -1);
407 add_task(async
function do_test_http2_wrongsuite_tls12() {
408 const { httpProxyConnectResponseCode
} =
409 await
test_http2_wrongsuite_tls12(serverPort
);
410 Assert
.equal(httpProxyConnectResponseCode
, -1);
413 add_task(async
function do_test_http2_wrongsuite_tls13() {
414 const { httpProxyConnectResponseCode
} =
415 await
test_http2_wrongsuite_tls13(serverPort
);
416 Assert
.equal(httpProxyConnectResponseCode
, -1);
419 add_task(async
function do_test_http2_push_firstparty1() {
420 const { httpProxyConnectResponseCode
} = await
test_http2_push_firstparty1(
424 Assert
.equal(httpProxyConnectResponseCode
, -1);
427 add_task(async
function do_test_http2_push_firstparty2() {
428 const { httpProxyConnectResponseCode
} = await
test_http2_push_firstparty2(
432 Assert
.equal(httpProxyConnectResponseCode
, -1);
435 add_task(async
function do_test_http2_push_firstparty3() {
436 const { httpProxyConnectResponseCode
} = await
test_http2_push_firstparty3(
440 Assert
.equal(httpProxyConnectResponseCode
, -1);
443 add_task(async
function do_test_http2_push_userContext1() {
444 const { httpProxyConnectResponseCode
} = await
test_http2_push_userContext1(
448 Assert
.equal(httpProxyConnectResponseCode
, -1);
451 add_task(async
function do_test_http2_push_userContext2() {
452 const { httpProxyConnectResponseCode
} = await
test_http2_push_userContext2(
456 Assert
.equal(httpProxyConnectResponseCode
, -1);
459 add_task(async
function do_test_http2_push_userContext3() {
460 const { httpProxyConnectResponseCode
} = await
test_http2_push_userContext3(
464 Assert
.equal(httpProxyConnectResponseCode
, -1);
467 add_task(async
function do_test_http2_continuations_over_max_response_limit() {
468 const { httpProxyConnectResponseCode
} =
469 await
test_http2_continuations_over_max_response_limit(
473 Assert
.equal(httpProxyConnectResponseCode
, -1);