tor-browser

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

test_trr_ttl.js (1583B)


      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 trr_test_setup();
      8 registerCleanupFunction(async () => {
      9  trr_clear_prefs();
     10 });
     11 
     12 let trrServer = null;
     13 add_task(async function setup() {
     14  trrServer = new TRRServer();
     15  registerCleanupFunction(async () => {
     16    await trrServer.stop();
     17  });
     18  await trrServer.start();
     19  dump(`port = ${trrServer.port()}\n`);
     20 
     21  Services.prefs.setCharPref(
     22    "network.trr.uri",
     23    `https://foo.example.com:${trrServer.port()}/dns-query`
     24  );
     25  Services.prefs.setIntPref("network.trr.mode", Ci.nsIDNSService.MODE_TRRFIRST);
     26 });
     27 
     28 add_task(async function check_ttl_works() {
     29  await trrServer.registerDoHAnswers("example.com", "A", {
     30    answers: [
     31      {
     32        name: "example.com",
     33        ttl: 55,
     34        type: "A",
     35        flush: false,
     36        data: "1.2.3.4",
     37      },
     38    ],
     39  });
     40  let { inRecord } = await new TRRDNSListener("example.com", {
     41    expectedAnswer: "1.2.3.4",
     42  });
     43  equal(inRecord.QueryInterface(Ci.nsIDNSAddrRecord).ttl, 55);
     44  await trrServer.registerDoHAnswers("example.org", "A", {
     45    answers: [
     46      {
     47        name: "example.org",
     48        ttl: 999,
     49        type: "A",
     50        flush: false,
     51        data: "1.2.3.4",
     52      },
     53    ],
     54  });
     55  // Simple check to see that TRR works.
     56  ({ inRecord } = await new TRRDNSListener("example.org", {
     57    expectedAnswer: "1.2.3.4",
     58  }));
     59  equal(inRecord.QueryInterface(Ci.nsIDNSAddrRecord).ttl, 999);
     60 });