test_http2.js (12008B)
1 /* import-globals-from http2_test_common.js */ 2 3 const { HttpServer } = ChromeUtils.importESModule( 4 "resource://testing-common/httpd.sys.mjs" 5 ); 6 7 var concurrent_channels = []; 8 var httpserv = null; 9 var httpserv2 = null; 10 11 var loadGroup; 12 var serverPort; 13 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); 21 } 22 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); 30 31 var body = '["http://foo.example.com:' + httpserv.identity.primaryPort + '"]'; 32 response.bodyOutputStream.write(body, body.length); 33 } 34 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 38 // up we have it. 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); 44 } 45 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); 53 54 var body = 55 '["http://foo.example.com:' + httpserv2.identity.primaryPort + '"]'; 56 response.bodyOutputStream.write(body, body.length); 57 } 58 59 add_setup(async function setup() { 60 serverPort = Services.env.get("MOZHTTP2_PORT"); 61 Assert.notEqual(serverPort, null); 62 dump("using port " + serverPort + "\n"); 63 64 // Set to allow the cert presented by our H2 server 65 do_get_profile(); 66 67 Services.prefs.setIntPref("network.http.speculative-parallel-limit", 0); 68 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 72 // foo.example.com 73 let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService( 74 Ci.nsIX509CertDB 75 ); 76 addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u"); 77 78 Services.prefs.setBoolPref("network.http.http2.enabled", true); 79 Services.prefs.setBoolPref("network.http.altsvc.enabled", true); 80 Services.prefs.setBoolPref("network.http.altsvc.oe", true); 81 Services.prefs.setCharPref( 82 "network.dns.localDomains", 83 "foo.example.com, bar.example.com" 84 ); 85 Services.prefs.setBoolPref( 86 "network.cookieJarSettings.unblocked_for_testing", 87 true 88 ); 89 90 loadGroup = Cc["@mozilla.org/network/load-group;1"].createInstance( 91 Ci.nsILoadGroup 92 ); 93 94 httpserv = new HttpServer(); 95 httpserv.registerPathHandler("/altsvc1", altsvcHttp1Server); 96 httpserv.registerPathHandler("/.well-known/http-opportunistic", h1ServerWK); 97 httpserv.start(-1); 98 httpserv.identity.setPrimary( 99 "http", 100 "foo.example.com", 101 httpserv.identity.primaryPort 102 ); 103 104 httpserv2 = new HttpServer(); 105 httpserv2.registerPathHandler("/altsvc2", altsvcHttp1Server2); 106 httpserv2.registerPathHandler("/.well-known/http-opportunistic", h1ServerWK2); 107 httpserv2.start(-1); 108 httpserv2.identity.setPrimary( 109 "http", 110 "foo.example.com", 111 httpserv2.identity.primaryPort 112 ); 113 }); 114 115 registerCleanupFunction(async () => { 116 Services.prefs.clearUserPref("network.http.speculative-parallel-limit"); 117 Services.prefs.clearUserPref("network.http.http2.enabled"); 118 Services.prefs.clearUserPref("network.http.altsvc.enabled"); 119 Services.prefs.clearUserPref("network.http.altsvc.oe"); 120 Services.prefs.clearUserPref("network.dns.localDomains"); 121 Services.prefs.clearUserPref( 122 "network.cookieJarSettings.unblocked_for_testing" 123 ); 124 await httpserv.stop(); 125 await httpserv2.stop(); 126 }); 127 128 // hack - the header test resets the multiplex object on the server, 129 // so make sure header is always run before the multiplex test. 130 // 131 // make sure post_big runs first to test race condition in restarting 132 // a stalled stream when a SETTINGS frame arrives 133 add_task(async function do_test_http2_post_big() { 134 const { httpProxyConnectResponseCode } = 135 await test_http2_post_big(serverPort); 136 Assert.equal(httpProxyConnectResponseCode, -1); 137 }); 138 139 add_task(async function do_test_http2_basic() { 140 const { httpProxyConnectResponseCode } = await test_http2_basic(serverPort); 141 Assert.equal(httpProxyConnectResponseCode, -1); 142 }); 143 144 add_task(async function do_test_http2_concurrent() { 145 const { httpProxyConnectResponseCode } = await test_http2_concurrent( 146 concurrent_channels, 147 serverPort 148 ); 149 Assert.equal(httpProxyConnectResponseCode, -1); 150 }); 151 152 add_task(async function do_test_http2_concurrent_post() { 153 const { httpProxyConnectResponseCode } = await test_http2_concurrent_post( 154 concurrent_channels, 155 serverPort 156 ); 157 Assert.equal(httpProxyConnectResponseCode, -1); 158 }); 159 160 add_task(async function do_test_http2_basic_unblocked_dep() { 161 const { httpProxyConnectResponseCode } = 162 await test_http2_basic_unblocked_dep(serverPort); 163 Assert.equal(httpProxyConnectResponseCode, -1); 164 }); 165 166 add_task(async function do_test_http2_nospdy() { 167 const { httpProxyConnectResponseCode } = await test_http2_nospdy(serverPort); 168 Assert.equal(httpProxyConnectResponseCode, -1); 169 }); 170 171 add_task(async function do_test_http2_altsvc() { 172 const { httpProxyConnectResponseCode } = await test_http2_altsvc( 173 httpserv.identity.primaryPort, 174 httpserv2.identity.primaryPort, 175 false 176 ); 177 Assert.equal(httpProxyConnectResponseCode, -1); 178 }); 179 180 add_task(async function do_test_http2_doubleheader() { 181 const { httpProxyConnectResponseCode } = 182 await test_http2_doubleheader(serverPort); 183 Assert.equal(httpProxyConnectResponseCode, -1); 184 }); 185 186 add_task(async function do_test_http2_xhr() { 187 await test_http2_xhr(serverPort); 188 }); 189 190 add_task(async function do_test_http2_header() { 191 const { httpProxyConnectResponseCode } = await test_http2_header(serverPort); 192 Assert.equal(httpProxyConnectResponseCode, -1); 193 }); 194 195 add_task(async function do_test_http2_invalid_response_header_name_spaces() { 196 const { httpProxyConnectResponseCode } = 197 await test_http2_invalid_response_header(serverPort, "name_spaces"); 198 Assert.equal(httpProxyConnectResponseCode, -1); 199 }); 200 201 add_task( 202 async function do_test_http2_invalid_response_header_value_line_feed() { 203 const { httpProxyConnectResponseCode } = 204 await test_http2_invalid_response_header(serverPort, "value_line_feed"); 205 Assert.equal(httpProxyConnectResponseCode, -1); 206 } 207 ); 208 209 add_task( 210 async function do_test_http2_invalid_response_header_value_carriage_return() { 211 const { httpProxyConnectResponseCode } = 212 await test_http2_invalid_response_header( 213 serverPort, 214 "value_carriage_return" 215 ); 216 Assert.equal(httpProxyConnectResponseCode, -1); 217 } 218 ); 219 220 add_task(async function do_test_http2_invalid_response_header_value_null() { 221 const { httpProxyConnectResponseCode } = 222 await test_http2_invalid_response_header(serverPort, "value_null"); 223 Assert.equal(httpProxyConnectResponseCode, -1); 224 }); 225 226 add_task(async function do_test_http2_cookie_crumbling() { 227 const { httpProxyConnectResponseCode } = 228 await test_http2_cookie_crumbling(serverPort); 229 Assert.equal(httpProxyConnectResponseCode, -1); 230 }); 231 232 add_task(async function do_test_http2_multiplex() { 233 var values = await test_http2_multiplex(serverPort); 234 Assert.equal(values[0].httpProxyConnectResponseCode, -1); 235 Assert.equal(values[1].httpProxyConnectResponseCode, -1); 236 Assert.notEqual(values[0].streamID, values[1].streamID); 237 }); 238 239 add_task(async function do_test_http2_big() { 240 const { httpProxyConnectResponseCode } = await test_http2_big(serverPort); 241 Assert.equal(httpProxyConnectResponseCode, -1); 242 }); 243 244 add_task(async function do_test_http2_huge_suspended() { 245 const { httpProxyConnectResponseCode } = 246 await test_http2_huge_suspended(serverPort); 247 Assert.equal(httpProxyConnectResponseCode, -1); 248 }); 249 250 add_task(async function do_test_http2_post() { 251 const { httpProxyConnectResponseCode } = await test_http2_post(serverPort); 252 Assert.equal(httpProxyConnectResponseCode, -1); 253 }); 254 255 add_task(async function do_test_http2_empty_post() { 256 const { httpProxyConnectResponseCode } = 257 await test_http2_empty_post(serverPort); 258 Assert.equal(httpProxyConnectResponseCode, -1); 259 }); 260 261 add_task(async function do_test_http2_patch() { 262 const { httpProxyConnectResponseCode } = await test_http2_patch(serverPort); 263 Assert.equal(httpProxyConnectResponseCode, -1); 264 }); 265 266 add_task(async function do_test_http2_blocking_download() { 267 const { httpProxyConnectResponseCode } = 268 await test_http2_blocking_download(serverPort); 269 Assert.equal(httpProxyConnectResponseCode, -1); 270 }); 271 272 add_task(async function do_test_http2_illegalhpacksoft() { 273 const { httpProxyConnectResponseCode } = 274 await test_http2_illegalhpacksoft(serverPort); 275 Assert.equal(httpProxyConnectResponseCode, -1); 276 }); 277 278 add_task(async function do_test_http2_illegalhpackhard() { 279 const { httpProxyConnectResponseCode } = 280 await test_http2_illegalhpackhard(serverPort); 281 Assert.equal(httpProxyConnectResponseCode, -1); 282 }); 283 284 add_task(async function do_test_http2_folded_header() { 285 const { httpProxyConnectResponseCode } = await test_http2_folded_header( 286 loadGroup, 287 serverPort 288 ); 289 Assert.equal(httpProxyConnectResponseCode, -1); 290 }); 291 292 add_task(async function do_test_http2_empty_data() { 293 const { httpProxyConnectResponseCode } = 294 await test_http2_empty_data(serverPort); 295 Assert.equal(httpProxyConnectResponseCode, -1); 296 }); 297 298 add_task(async function do_test_http2_status_phrase() { 299 const { httpProxyConnectResponseCode } = 300 await test_http2_status_phrase(serverPort); 301 Assert.equal(httpProxyConnectResponseCode, -1); 302 }); 303 304 add_task(async function do_test_http2_h11required_stream() { 305 // Add new tests above here - best to add new tests before h1 306 // streams get too involved 307 // These next two must always come in this order 308 const { httpProxyConnectResponseCode } = 309 await test_http2_h11required_stream(serverPort); 310 Assert.equal(httpProxyConnectResponseCode, -1); 311 }); 312 313 add_task(async function do_test_http2_h11required_session() { 314 const { httpProxyConnectResponseCode } = 315 await test_http2_h11required_session(serverPort); 316 Assert.equal(httpProxyConnectResponseCode, -1); 317 }); 318 319 add_task(async function do_test_http2_retry_rst() { 320 const { httpProxyConnectResponseCode } = 321 await test_http2_retry_rst(serverPort); 322 Assert.equal(httpProxyConnectResponseCode, -1); 323 }); 324 325 add_task(async function do_test_http2_wrongsuite_tls12() { 326 const { httpProxyConnectResponseCode } = 327 await test_http2_wrongsuite_tls12(serverPort); 328 Assert.equal(httpProxyConnectResponseCode, -1); 329 }); 330 331 add_task(async function do_test_http2_wrongsuite_tls13() { 332 const { httpProxyConnectResponseCode } = 333 await test_http2_wrongsuite_tls13(serverPort); 334 Assert.equal(httpProxyConnectResponseCode, -1); 335 }); 336 337 add_task(async function do_test_http2_continuations_over_max_response_limit() { 338 const { httpProxyConnectResponseCode } = 339 await test_http2_continuations_over_max_response_limit( 340 loadGroup, 341 serverPort 342 ); 343 Assert.equal(httpProxyConnectResponseCode, -1); 344 });