test_http2_with_proxy.js (10092B)
1 // test HTTP/2 with a HTTP/2 prooxy 2 3 "use strict"; 4 5 /* import-globals-from http2_test_common.js */ 6 7 const { NodeHTTP2ProxyServer, NodeHTTPSProxyServer } = 8 ChromeUtils.importESModule("resource://testing-common/NodeServer.sys.mjs"); 9 10 // We don't normally allow localhost channels to be proxied, but this 11 // is easier than updating all the certs and/or domains. 12 Services.prefs.setBoolPref("network.proxy.allow_hijacking_localhost", true); 13 registerCleanupFunction(() => { 14 Services.prefs.clearUserPref("network.proxy.allow_hijacking_localhost"); 15 }); 16 17 var concurrent_channels = []; 18 19 var loadGroup; 20 var serverPort; 21 var proxy; 22 23 add_setup(async function setup() { 24 serverPort = Services.env.get("MOZHTTP2_PORT"); 25 Assert.notEqual(serverPort, null); 26 dump("using port " + serverPort + "\n"); 27 28 // Set to allow the cert presented by our H2 server 29 do_get_profile(); 30 Services.prefs.setIntPref("network.http.speculative-parallel-limit", 0); 31 32 // The moz-http2 cert is for foo.example.com and is signed by http2-ca.pem 33 // so add that cert to the trust list as a signing cert. Some older tests in 34 // this suite use localhost with a TOFU exception, but new ones should use 35 // foo.example.com 36 let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService( 37 Ci.nsIX509CertDB 38 ); 39 addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u"); 40 addCertFromFile(certdb, "proxy-ca.pem", "CTu,u,u"); 41 42 Services.prefs.setBoolPref("network.http.http2.enabled", true); 43 Services.prefs.setBoolPref("network.http.altsvc.enabled", true); 44 Services.prefs.setBoolPref("network.http.altsvc.oe", true); 45 Services.prefs.setCharPref( 46 "network.dns.localDomains", 47 "foo.example.com, bar.example.com" 48 ); 49 Services.prefs.setBoolPref( 50 "network.cookieJarSettings.unblocked_for_testing", 51 true 52 ); 53 54 loadGroup = Cc["@mozilla.org/network/load-group;1"].createInstance( 55 Ci.nsILoadGroup 56 ); 57 58 Services.prefs.setStringPref( 59 "services.settings.server", 60 `data:,#remote-settings-dummy/v1` 61 ); 62 63 proxy = new NodeHTTP2ProxyServer(); 64 await proxy.start(); 65 }); 66 67 registerCleanupFunction(async () => { 68 Services.prefs.clearUserPref("network.http.speculative-parallel-limit"); 69 Services.prefs.clearUserPref("network.http.http2.enabled"); 70 Services.prefs.clearUserPref("network.http.altsvc.enabled"); 71 Services.prefs.clearUserPref("network.http.altsvc.oe"); 72 Services.prefs.clearUserPref("network.dns.localDomains"); 73 Services.prefs.clearUserPref( 74 "network.cookieJarSettings.unblocked_for_testing" 75 ); 76 77 await proxy.stop(); 78 }); 79 80 // hack - the header test resets the multiplex object on the server, 81 // so make sure header is always run before the multiplex test. 82 // 83 // make sure post_big runs first to test race condition in restarting 84 // a stalled stream when a SETTINGS frame arrives 85 add_task(async function do_test_http2_post_big() { 86 const { httpProxyConnectResponseCode } = 87 await test_http2_post_big(serverPort); 88 Assert.equal(httpProxyConnectResponseCode, 200); 89 }); 90 91 add_task(async function do_test_http2_basic() { 92 const { httpProxyConnectResponseCode } = await test_http2_basic(serverPort); 93 Assert.equal(httpProxyConnectResponseCode, 200); 94 }); 95 96 add_task(async function do_test_http2_concurrent() { 97 const { httpProxyConnectResponseCode } = await test_http2_concurrent( 98 concurrent_channels, 99 serverPort 100 ); 101 Assert.equal(httpProxyConnectResponseCode, 200); 102 }); 103 104 add_task(async function do_test_http2_concurrent_post() { 105 const { httpProxyConnectResponseCode } = await test_http2_concurrent_post( 106 concurrent_channels, 107 serverPort 108 ); 109 Assert.equal(httpProxyConnectResponseCode, 200); 110 }); 111 112 add_task(async function do_test_http2_basic_unblocked_dep() { 113 const { httpProxyConnectResponseCode } = 114 await test_http2_basic_unblocked_dep(serverPort); 115 Assert.equal(httpProxyConnectResponseCode, 200); 116 }); 117 118 add_task(async function do_test_http2_nospdy() { 119 const { httpProxyConnectResponseCode } = await test_http2_nospdy(serverPort); 120 Assert.equal(httpProxyConnectResponseCode, 200); 121 }); 122 123 add_task(async function do_test_http2_doubleheader() { 124 const { httpProxyConnectResponseCode } = 125 await test_http2_doubleheader(serverPort); 126 Assert.equal(httpProxyConnectResponseCode, 200); 127 }); 128 129 add_task(async function do_test_http2_xhr() { 130 await test_http2_xhr(serverPort); 131 }); 132 133 add_task(async function do_test_http2_header() { 134 const { httpProxyConnectResponseCode } = await test_http2_header(serverPort); 135 Assert.equal(httpProxyConnectResponseCode, 200); 136 }); 137 138 add_task(async function do_test_http2_invalid_response_header_name_spaces() { 139 const { httpProxyConnectResponseCode } = 140 await test_http2_invalid_response_header(serverPort, "name_spaces"); 141 Assert.equal(httpProxyConnectResponseCode, 200); 142 }); 143 144 add_task( 145 async function do_test_http2_invalid_response_header_value_line_feed() { 146 const { httpProxyConnectResponseCode } = 147 await test_http2_invalid_response_header(serverPort, "value_line_feed"); 148 Assert.equal(httpProxyConnectResponseCode, 200); 149 } 150 ); 151 152 add_task( 153 async function do_test_http2_invalid_response_header_value_carriage_return() { 154 const { httpProxyConnectResponseCode } = 155 await test_http2_invalid_response_header( 156 serverPort, 157 "value_carriage_return" 158 ); 159 Assert.equal(httpProxyConnectResponseCode, 200); 160 } 161 ); 162 163 add_task(async function do_test_http2_invalid_response_header_value_null() { 164 const { httpProxyConnectResponseCode } = 165 await test_http2_invalid_response_header(serverPort, "value_null"); 166 Assert.equal(httpProxyConnectResponseCode, 200); 167 }); 168 169 add_task(async function do_test_http2_cookie_crumbling() { 170 const { httpProxyConnectResponseCode } = 171 await test_http2_cookie_crumbling(serverPort); 172 Assert.equal(httpProxyConnectResponseCode, 200); 173 }); 174 175 add_task(async function do_test_http2_multiplex() { 176 var values = await test_http2_multiplex(serverPort); 177 Assert.equal(values[0].httpProxyConnectResponseCode, 200); 178 Assert.equal(values[1].httpProxyConnectResponseCode, 200); 179 Assert.notEqual(values[0].streamID, values[1].streamID); 180 }); 181 182 add_task(async function do_test_http2_big() { 183 const { httpProxyConnectResponseCode } = await test_http2_big(serverPort); 184 Assert.equal(httpProxyConnectResponseCode, 200); 185 }); 186 187 add_task(async function do_test_http2_huge_suspended() { 188 const { httpProxyConnectResponseCode } = 189 await test_http2_huge_suspended(serverPort); 190 Assert.equal(httpProxyConnectResponseCode, 200); 191 }); 192 193 add_task(async function do_test_http2_post() { 194 const { httpProxyConnectResponseCode } = await test_http2_post(serverPort); 195 Assert.equal(httpProxyConnectResponseCode, 200); 196 }); 197 198 add_task(async function do_test_http2_empty_post() { 199 const { httpProxyConnectResponseCode } = 200 await test_http2_empty_post(serverPort); 201 Assert.equal(httpProxyConnectResponseCode, 200); 202 }); 203 204 add_task(async function do_test_http2_patch() { 205 const { httpProxyConnectResponseCode } = await test_http2_patch(serverPort); 206 Assert.equal(httpProxyConnectResponseCode, 200); 207 }); 208 209 add_task(async function do_test_http2_blocking_download() { 210 const { httpProxyConnectResponseCode } = 211 await test_http2_blocking_download(serverPort); 212 Assert.equal(httpProxyConnectResponseCode, 200); 213 }); 214 215 add_task(async function do_test_http2_illegalhpacksoft() { 216 const { httpProxyConnectResponseCode } = 217 await test_http2_illegalhpacksoft(serverPort); 218 Assert.equal(httpProxyConnectResponseCode, 200); 219 }); 220 221 add_task(async function do_test_http2_illegalhpackhard() { 222 const { httpProxyConnectResponseCode } = 223 await test_http2_illegalhpackhard(serverPort); 224 Assert.equal(httpProxyConnectResponseCode, 200); 225 }); 226 227 add_task(async function do_test_http2_folded_header() { 228 const { httpProxyConnectResponseCode } = await test_http2_folded_header( 229 loadGroup, 230 serverPort 231 ); 232 Assert.equal(httpProxyConnectResponseCode, 200); 233 }); 234 235 add_task(async function do_test_http2_empty_data() { 236 const { httpProxyConnectResponseCode } = 237 await test_http2_empty_data(serverPort); 238 Assert.equal(httpProxyConnectResponseCode, 200); 239 }); 240 241 add_task(async function do_test_http2_status_phrase() { 242 const { httpProxyConnectResponseCode } = 243 await test_http2_status_phrase(serverPort); 244 Assert.equal(httpProxyConnectResponseCode, 200); 245 }); 246 247 add_task(async function do_test_http2_h11required_stream() { 248 // Add new tests above here - best to add new tests before h1 249 // streams get too involved 250 // These next two must always come in this order 251 const { httpProxyConnectResponseCode } = 252 await test_http2_h11required_stream(serverPort); 253 Assert.equal(httpProxyConnectResponseCode, 200); 254 }); 255 256 add_task(async function do_test_http2_h11required_session() { 257 const { httpProxyConnectResponseCode } = 258 await test_http2_h11required_session(serverPort); 259 Assert.equal(httpProxyConnectResponseCode, 200); 260 }); 261 262 add_task(async function do_test_http2_retry_rst() { 263 const { httpProxyConnectResponseCode } = 264 await test_http2_retry_rst(serverPort); 265 Assert.equal(httpProxyConnectResponseCode, 200); 266 }); 267 268 add_task(async function do_test_http2_wrongsuite_tls12() { 269 // For this test we need to start HTTPS 1.1 proxy because HTTP/2 proxy cannot be used. 270 proxy.unregisterFilter(); 271 let proxyHttp1 = new NodeHTTPSProxyServer(); 272 await proxyHttp1.start(); 273 proxyHttp1.registerFilter(); 274 registerCleanupFunction(() => { 275 proxyHttp1.stop(); 276 }); 277 const { httpProxyConnectResponseCode } = 278 await test_http2_wrongsuite_tls12(serverPort); 279 Assert.equal(httpProxyConnectResponseCode, 200); 280 proxyHttp1.unregisterFilter(); 281 proxy.registerFilter(); 282 }); 283 284 add_task(async function do_test_http2_wrongsuite_tls13() { 285 const { httpProxyConnectResponseCode } = 286 await test_http2_wrongsuite_tls13(serverPort); 287 Assert.equal(httpProxyConnectResponseCode, 200); 288 }); 289 290 add_task(async function do_test_http2_continuations_over_max_response_limit() { 291 const { httpProxyConnectResponseCode } = 292 await test_http2_continuations_over_max_response_limit( 293 loadGroup, 294 serverPort 295 ); 296 Assert.equal(httpProxyConnectResponseCode, 200); 297 });