tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_http2_with_http3_proxy.js (10267B)


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