tor-browser

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

test_dns_disable_ipv4.js (1880B)


      1 //
      2 // Tests that calling asyncResolve with the RESOLVE_DISABLE_IPV4 flag doesn't
      3 // return any IPv4 addresses.
      4 //
      5 
      6 "use strict";
      7 
      8 const gOverride = Cc["@mozilla.org/network/native-dns-override;1"].getService(
      9  Ci.nsINativeDNSResolverOverride
     10 );
     11 
     12 const defaultOriginAttributes = {};
     13 
     14 add_task(async function test_none() {
     15  let [, inRecord] = await new Promise(resolve => {
     16    let listener = {
     17      onLookupComplete(inRequest, inRecord1, inStatus) {
     18        resolve([inRequest, inRecord1, inStatus]);
     19      },
     20      QueryInterface: ChromeUtils.generateQI(["nsIDNSListener"]),
     21    };
     22 
     23    Services.dns.asyncResolve(
     24      "example.org",
     25      Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
     26      Ci.nsIDNSService.RESOLVE_DISABLE_IPV4,
     27      null, // resolverInfo
     28      listener,
     29      null,
     30      defaultOriginAttributes
     31    );
     32  });
     33 
     34  if (inRecord && inRecord.QueryInterface(Ci.nsIDNSAddrRecord)) {
     35    while (inRecord.hasMore()) {
     36      let nextIP = inRecord.getNextAddrAsString();
     37      ok(nextIP.includes(":"), `${nextIP} should be IPv6`);
     38    }
     39  }
     40 });
     41 
     42 add_task(async function test_some() {
     43  Services.dns.clearCache(true);
     44  gOverride.addIPOverride("example.com", "1.1.1.1");
     45  gOverride.addIPOverride("example.org", "::1:2:3");
     46  let [, inRecord] = await new Promise(resolve => {
     47    let listener = {
     48      onLookupComplete(inRequest, inRecord1, inStatus) {
     49        resolve([inRequest, inRecord1, inStatus]);
     50      },
     51      QueryInterface: ChromeUtils.generateQI(["nsIDNSListener"]),
     52    };
     53 
     54    Services.dns.asyncResolve(
     55      "example.org",
     56      Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
     57      Ci.nsIDNSService.RESOLVE_DISABLE_IPV4,
     58      null, // resolverInfo
     59      listener,
     60      null,
     61      defaultOriginAttributes
     62    );
     63  });
     64 
     65  ok(inRecord.QueryInterface(Ci.nsIDNSAddrRecord));
     66  equal(inRecord.getNextAddrAsString(), "::1:2:3");
     67  equal(inRecord.hasMore(), false);
     68 });