tor-browser

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

test_http3_with_proxy.js (5543B)


      1 "use strict";
      2 
      3 /* import-globals-from http3_common.js */
      4 
      5 const { Http3ProxyFilter, NodeHTTP2ProxyServer } = ChromeUtils.importESModule(
      6  "resource://testing-common/NodeServer.sys.mjs"
      7 );
      8 
      9 // Max concurent stream number in neqo is 100.
     10 // Openning 120 streams will test queuing of streams.
     11 let number_of_parallel_requests = 120;
     12 let h3Route;
     13 let httpsOrigin;
     14 let h3AltSvc;
     15 let h3Port;
     16 let h3ServerDomain;
     17 let prefs;
     18 
     19 let pps = Cc["@mozilla.org/network/protocol-proxy-service;1"].getService();
     20 let proxyHost;
     21 let proxyPort;
     22 let proxyFilter;
     23 
     24 add_setup(async function () {
     25  let h2Port = Services.env.get("MOZHTTP2_PORT");
     26  Assert.notEqual(h2Port, null);
     27  Assert.notEqual(h2Port, "");
     28  h3Port = await create_h3_server();
     29  Assert.notEqual(h3Port, null);
     30  Assert.notEqual(h3Port, "");
     31  h3AltSvc = ":" + h3Port;
     32  h3ServerDomain = "foo.example.com";
     33  h3Route = `${h3ServerDomain}:${h3Port}`;
     34  do_get_profile();
     35  prefs = Services.prefs;
     36 
     37  prefs.setBoolPref("network.http.http3.enable", true);
     38  // We always resolve elements of localDomains as it's hardcoded without the
     39  // following pref:
     40  prefs.setBoolPref("network.proxy.allow_hijacking_localhost", true);
     41  prefs.setBoolPref("network.http.altsvc.oe", true);
     42 
     43  if (mozinfo.os == "android") {
     44    // Set necessary prefs to make Firefox connect to the http3Server on the
     45    // host machine.
     46    prefs.setCharPref("network.dns.localDomains", "");
     47    const overrideService = Cc[
     48      "@mozilla.org/network/native-dns-override;1"
     49    ].getService(Ci.nsINativeDNSResolverOverride);
     50    overrideService.addIPOverride(h3ServerDomain, "10.0.2.2");
     51    prefs.setCharPref(
     52      "network.http.http3.alt-svc-mapping-for-testing",
     53      `${h3ServerDomain};h3=:${h3Port}`
     54    );
     55  } else {
     56    prefs.setCharPref(
     57      "network.dns.localDomains",
     58      "foo.example.com, alt1.example.com"
     59    );
     60  }
     61 
     62  // The certificate for the http3server server is for foo.example.com and
     63  // is signed by http2-ca.pem so add that cert to the trust list as a
     64  // signing cert.
     65  let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
     66    Ci.nsIX509CertDB
     67  );
     68  addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u");
     69  addCertFromFile(certdb, "proxy-ca.pem", "CTu,u,u");
     70  httpsOrigin = `https://${h3ServerDomain}:${h2Port}/`;
     71 
     72  proxyHost = "alt1.example.com";
     73  proxyPort = (await create_masque_proxy_server()).masqueProxyPort;
     74  Assert.notEqual(proxyPort, null);
     75  Assert.notEqual(proxyPort, "");
     76  proxyFilter = new Http3ProxyFilter(
     77    proxyHost,
     78    proxyPort,
     79    0,
     80    "/.well-known/masque/udp/{target_host}/{target_port}/",
     81    ""
     82  );
     83  pps.registerFilter(proxyFilter, 10);
     84 
     85  registerCleanupFunction(() => {
     86    prefs.clearUserPref("network.http.http3.enable");
     87    prefs.clearUserPref("network.dns.localDomains");
     88    prefs.clearUserPref("network.proxy.allow_hijacking_localhost");
     89    prefs.clearUserPref("network.http.altsvc.oe");
     90    prefs.clearUserPref("network.http.http3.alt-svc-mapping-for-testing");
     91    pps.unregisterFilter(proxyFilter);
     92    if (mozinfo.os == "android") {
     93      const overrideService = Cc[
     94        "@mozilla.org/network/native-dns-override;1"
     95      ].getService(Ci.nsINativeDNSResolverOverride);
     96      overrideService.clearOverrides();
     97    }
     98  });
     99 });
    100 
    101 add_task(async function test_https_alt_svc() {
    102  await waitForHttp3Route(httpsOrigin + "http3-test", h3Route, h3AltSvc, {
    103    delayMs: 500,
    104  });
    105 });
    106 
    107 add_task(async function test_multiple_requests() {
    108  await do_test_multiple_requests(
    109    number_of_parallel_requests,
    110    h3Route,
    111    httpsOrigin
    112  );
    113 });
    114 
    115 add_task(async function test_request_cancelled_by_server() {
    116  await do_test_request_cancelled_by_server(h3Route, httpsOrigin);
    117 });
    118 
    119 add_task(async function test_stream_cancelled_by_necko() {
    120  await do_test_stream_cancelled_by_necko(h3Route, httpsOrigin);
    121 });
    122 
    123 add_task(async function test_multiple_request_one_is_cancelled() {
    124  await do_test_multiple_request_one_is_cancelled(
    125    number_of_parallel_requests,
    126    h3Route,
    127    httpsOrigin
    128  );
    129 });
    130 
    131 add_task(async function test_multiple_request_one_is_cancelled_by_necko() {
    132  await do_test_multiple_request_one_is_cancelled_by_necko(
    133    number_of_parallel_requests,
    134    h3Route,
    135    httpsOrigin
    136  );
    137 });
    138 
    139 add_task(async function test_post() {
    140  await do_test_post(httpsOrigin, h3Route);
    141 });
    142 
    143 add_task(async function test_patch() {
    144  await do_test_patch(httpsOrigin, h3Route);
    145 });
    146 
    147 add_task(
    148  {
    149    // Skip this test on Android because the httpOrigin (http://foo.example.com)
    150    // is on 127.0.0.1, while the http3Server (https://foo.example.com) is
    151    // on 10.0.2.2. Currently, we can't change the IP mapping dynamically.
    152    skip_if: () => mozinfo.os == "android",
    153  },
    154  async function test_http_alt_svc() {
    155    setup_h1_server(h3ServerDomain);
    156    await waitForHttp3Route(httpOrigin + "http3-test", h3Route, h3AltSvc, {
    157      delayMs: 500,
    158    });
    159  }
    160 );
    161 
    162 add_task(async function test_slow_receiver() {
    163  await do_test_slow_receiver(httpsOrigin, h3Route);
    164 });
    165 
    166 // This test should be at the end, because it will close http3
    167 // connection and the transaction will switch to already existing http2
    168 // connection.
    169 // TODO: Bug 1582667 should try to fix issue with connection being closed.
    170 add_task(async function test_version_fallback() {
    171  let proxy = new NodeHTTP2ProxyServer();
    172  await proxy.startWithoutProxyFilter(proxyPort);
    173  registerCleanupFunction(async () => {
    174    await proxy.stop();
    175  });
    176  Assert.equal(proxyPort, proxy.port());
    177  info(`proxy port=${proxy.port()}\n`);
    178 
    179  await do_test_version_fallback(httpsOrigin);
    180 });