tor-browser

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

test_dns_disable_ipv6.js (1126B)


      1 //
      2 // Tests that calling asyncResolve with the RESOLVE_DISABLE_IPV6 flag doesn't
      3 // return any IPv6 addresses.
      4 //
      5 
      6 "use strict";
      7 
      8 var listener = {
      9  onLookupComplete(inRequest, inRecord, inStatus) {
     10    if (inStatus != Cr.NS_OK) {
     11      Assert.equal(inStatus, Cr.NS_ERROR_UNKNOWN_HOST);
     12      do_test_finished();
     13      return;
     14    }
     15 
     16    while (true) {
     17      try {
     18        inRecord.QueryInterface(Ci.nsIDNSAddrRecord);
     19        var answer = inRecord.getNextAddrAsString();
     20        // If there is an answer it should be an IPv4  address
     21        dump(answer);
     22        Assert.ok(!answer.includes(":"));
     23        Assert.ok(answer.includes("."));
     24      } catch (e) {
     25        break;
     26      }
     27    }
     28    do_test_finished();
     29  },
     30 };
     31 
     32 const defaultOriginAttributes = {};
     33 
     34 function run_test() {
     35  do_test_pending();
     36  try {
     37    Services.dns.asyncResolve(
     38      "example.com",
     39      Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
     40      Ci.nsIDNSService.RESOLVE_DISABLE_IPV6,
     41      null, // resolverInfo
     42      listener,
     43      null,
     44      defaultOriginAttributes
     45    );
     46  } catch (e) {
     47    dump(e);
     48    Assert.ok(false);
     49    do_test_finished();
     50  }
     51 }