tor-browser

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

test_http3_non_ascii_header.js (2709B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 /* import-globals-from head_http3.js */
      8 
      9 function makeChan(uri) {
     10  let chan = NetUtil.newChannel({
     11    uri,
     12    loadUsingSystemPrincipal: true,
     13  }).QueryInterface(Ci.nsIHttpChannel);
     14  chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
     15  return chan;
     16 }
     17 
     18 function channelOpenPromise(chan, flags) {
     19  return new Promise(resolve => {
     20    function finish(req, buffer) {
     21      resolve([req, buffer]);
     22    }
     23    chan.asyncOpen(new ChannelListener(finish, null, flags));
     24  });
     25 }
     26 
     27 let h2Port;
     28 let h3Port;
     29 
     30 add_setup(async function setup() {
     31  h2Port = Services.env.get("MOZHTTP2_PORT");
     32  Assert.notEqual(h2Port, null);
     33  Assert.notEqual(h2Port, "");
     34 
     35  h3Port = Services.env.get("MOZHTTP3_PORT");
     36  Assert.notEqual(h3Port, null);
     37  Assert.notEqual(h3Port, "");
     38 
     39  Services.prefs.setBoolPref("network.http.http3.enable", true);
     40  Services.prefs.setCharPref("network.dns.localDomains", "foo.example.com");
     41  Services.prefs.setBoolPref("network.dns.disableIPv6", true);
     42  Services.prefs.setCharPref(
     43    "network.http.http3.alt-svc-mapping-for-testing",
     44    `foo.example.com;h3=:${h3Port}`
     45  );
     46 
     47  let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
     48    Ci.nsIX509CertDB
     49  );
     50  addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u");
     51 
     52  let chan = makeChan(`https://localhost`);
     53  await channelOpenPromise(chan, CL_EXPECT_FAILURE);
     54 });
     55 
     56 // Test non-ASCII header with HTTP/3 and HTTP/2 fallback
     57 // Http3Session::TryActivating fails to parse the non-utf8 headers
     58 // and returns NS_ERROR_HTTP2_FALLBACK_TO_HTTP1 so we fallback to h2.
     59 // When bug 1999659 is fixed we should instead succeed.
     60 add_task(async function test_non_ascii_header() {
     61  // First request with non-ASCII header
     62  let chan1 = makeChan(`https://foo.example.com:${h2Port}/100`);
     63  chan1.setRequestHeader("x-panel-title", "ä", false);
     64 
     65  let [req1, buf1] = await channelOpenPromise(
     66    chan1,
     67    CL_IGNORE_CL | CL_ALLOW_UNKNOWN_CL
     68  );
     69 
     70  let protocol1 = req1.protocolVersion;
     71  Assert.strictEqual(protocol1, "h3", `Using ${protocol1}`);
     72  Assert.equal(req1.responseStatus, 200);
     73  info(buf1);
     74 
     75  // Second request with different non-ASCII header
     76  let chan2 = makeChan(`https://foo.example.com:${h2Port}/100`);
     77  chan2.setRequestHeader("x-panel-title", "ö", false);
     78 
     79  let [req2] = await channelOpenPromise(
     80    chan2,
     81    CL_IGNORE_CL | CL_ALLOW_UNKNOWN_CL
     82  );
     83 
     84  let protocol2 = req2.protocolVersion;
     85  Assert.strictEqual(protocol2, "h3", `Using ${protocol2}`);
     86  Assert.equal(req2.responseStatus, 200);
     87 });