tor-browser

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

test_tls13_disabled.js (2403B)


      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 registerCleanupFunction(async () => {
      6  Services.prefs.clearUserPref("security.tls.version.max");
      7  http3_clear_prefs();
      8 });
      9 
     10 let httpsUri;
     11 
     12 add_task(async function setup() {
     13  let h2Port = Services.env.get("MOZHTTP2_PORT");
     14  Assert.notEqual(h2Port, null);
     15  Assert.notEqual(h2Port, "");
     16  httpsUri = "https://foo.example.com:" + h2Port + "/";
     17 
     18  await http3_setup_tests("h3", true);
     19 });
     20 
     21 let Listener = function () {};
     22 
     23 Listener.prototype = {
     24  resumed: false,
     25 
     26  onStartRequest: function testOnStartRequest(request) {
     27    Assert.equal(request.status, Cr.NS_OK);
     28    Assert.equal(request.responseStatus, 200);
     29  },
     30 
     31  onDataAvailable: function testOnDataAvailable(request, stream, off, cnt) {
     32    read_stream(stream, cnt);
     33  },
     34 
     35  onStopRequest: function testOnStopRequest(request) {
     36    let httpVersion = "";
     37    try {
     38      httpVersion = request.protocolVersion;
     39    } catch (e) {}
     40    if (this.expect_http3) {
     41      Assert.equal(httpVersion, "h3");
     42    } else {
     43      Assert.notEqual(httpVersion, "h3");
     44    }
     45 
     46    this.finish();
     47  },
     48 };
     49 
     50 function chanPromise(chan, listener) {
     51  return new Promise(resolve => {
     52    function finish(result) {
     53      resolve(result);
     54    }
     55    listener.finish = finish;
     56    chan.asyncOpen(listener);
     57  });
     58 }
     59 
     60 function makeChan(uri) {
     61  let chan = NetUtil.newChannel({
     62    uri,
     63    loadUsingSystemPrincipal: true,
     64  }).QueryInterface(Ci.nsIHttpChannel);
     65  chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
     66  return chan;
     67 }
     68 
     69 async function test_http3_used(expect_http3) {
     70  let listener = new Listener();
     71  listener.expect_http3 = expect_http3;
     72  let chan = makeChan(httpsUri);
     73  await chanPromise(chan, listener);
     74 }
     75 
     76 add_task(async function test_tls13_pref() {
     77  await test_http3_used(true);
     78  // Try one more time.
     79  await test_http3_used(true);
     80 
     81  // Disable TLS1.3
     82  Services.prefs.setIntPref("security.tls.version.max", 3);
     83  await test_http3_used(false);
     84  // Try one more time.
     85  await test_http3_used(false);
     86 
     87  // Enable TLS1.3
     88  Services.obs.notifyObservers(null, "net:cancel-all-connections");
     89  Services.prefs.setIntPref("security.tls.version.max", 4);
     90  await test_http3_used(true);
     91  // Try one more time.
     92  await test_http3_used(true);
     93 });