tor-browser

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

test_httpssvc_priority.js (3445B)


      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  Services.prefs.clearUserPref("network.dns.echconfig.enabled");
     11 });
     12 
     13 add_task(async function testPriorityAndECHConfig() {
     14  let trrServer = new TRRServer();
     15  registerCleanupFunction(async () => {
     16    await trrServer.stop();
     17  });
     18  await trrServer.start();
     19 
     20  Services.prefs.setBoolPref("network.dns.echconfig.enabled", false);
     21  Services.prefs.setIntPref("network.trr.mode", 3);
     22  Services.prefs.setCharPref(
     23    "network.trr.uri",
     24    `https://foo.example.com:${trrServer.port()}/dns-query`
     25  );
     26 
     27  await trrServer.registerDoHAnswers("test.priority.com", "HTTPS", {
     28    answers: [
     29      {
     30        name: "test.priority.com",
     31        ttl: 55,
     32        type: "HTTPS",
     33        flush: false,
     34        data: {
     35          priority: 1,
     36          name: "test.p1.com",
     37          values: [{ key: "alpn", value: ["h2", "h3"] }],
     38        },
     39      },
     40      {
     41        name: "test.priority.com",
     42        ttl: 55,
     43        type: "HTTPS",
     44        flush: false,
     45        data: {
     46          priority: 4,
     47          name: "test.p4.com",
     48          values: [{ key: "echconfig", value: "456..." }],
     49        },
     50      },
     51      {
     52        name: "test.priority.com",
     53        ttl: 55,
     54        type: "HTTPS",
     55        flush: false,
     56        data: {
     57          priority: 3,
     58          name: "test.p3.com",
     59          values: [{ key: "ipv4hint", value: "1.2.3.4" }],
     60        },
     61      },
     62      {
     63        name: "test.priority.com",
     64        ttl: 55,
     65        type: "HTTPS",
     66        flush: false,
     67        data: {
     68          priority: 2,
     69          name: "test.p2.com",
     70          values: [{ key: "echconfig", value: "123..." }],
     71        },
     72      },
     73    ],
     74  });
     75 
     76  let { inRecord } = await new TRRDNSListener("test.priority.com", {
     77    type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC,
     78  });
     79 
     80  let answer = inRecord.QueryInterface(Ci.nsIDNSHTTPSSVCRecord).records;
     81  Assert.equal(answer.length, 4);
     82 
     83  Assert.equal(answer[0].priority, 1);
     84  Assert.equal(answer[0].name, "test.p1.com");
     85 
     86  Assert.equal(answer[1].priority, 2);
     87  Assert.equal(answer[1].name, "test.p2.com");
     88 
     89  Assert.equal(answer[2].priority, 3);
     90  Assert.equal(answer[2].name, "test.p3.com");
     91 
     92  Assert.equal(answer[3].priority, 4);
     93  Assert.equal(answer[3].name, "test.p4.com");
     94 
     95  Services.prefs.setBoolPref("network.dns.echconfig.enabled", true);
     96  Services.dns.clearCache(true);
     97  ({ inRecord } = await new TRRDNSListener("test.priority.com", {
     98    type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC,
     99  }));
    100 
    101  answer = inRecord.QueryInterface(Ci.nsIDNSHTTPSSVCRecord).records;
    102  Assert.equal(answer.length, 4);
    103 
    104  Assert.equal(answer[0].priority, 2);
    105  Assert.equal(answer[0].name, "test.p2.com");
    106  Assert.equal(
    107    answer[0].values[0].QueryInterface(Ci.nsISVCParamEchConfig).echconfig,
    108    "123...",
    109    "got correct answer"
    110  );
    111 
    112  Assert.equal(answer[1].priority, 4);
    113  Assert.equal(answer[1].name, "test.p4.com");
    114  Assert.equal(
    115    answer[1].values[0].QueryInterface(Ci.nsISVCParamEchConfig).echconfig,
    116    "456...",
    117    "got correct answer"
    118  );
    119 
    120  Assert.equal(answer[2].priority, 1);
    121  Assert.equal(answer[2].name, "test.p1.com");
    122 
    123  Assert.equal(answer[3].priority, 3);
    124  Assert.equal(answer[3].name, "test.p3.com");
    125 });