Bug 1637512 - Test that IPv6 TRR requests fallback to DNS properly r=dragana,necko-reviewers
authorValentin Gosu <valentin.gosu@gmail.com>
Thu, 04 Jun 2020 11:10:36 +0000
changeset 533876 3b999337cd40c0e4d937bfe38e5e91d64790a77e
parent 533875 604346d2f6dade76d63d499532ce9a1c5d50d9cb
child 533877 3f3c444a38ad7f3c7ae953cb2778b0fef2e63307
push id37479
push userapavel@mozilla.com
push dateThu, 04 Jun 2020 15:32:20 +0000
treeherdermozilla-central@0d21bdf3fc01 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana, necko-reviewers
bugs1637512
milestone79.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1637512 - Test that IPv6 TRR requests fallback to DNS properly r=dragana,necko-reviewers Depends on D78237 Differential Revision: https://phabricator.services.mozilla.com/D78238
netwerk/test/unit/test_trr.js
--- a/netwerk/test/unit/test_trr.js
+++ b/netwerk/test/unit/test_trr.js
@@ -116,39 +116,40 @@ const BAD_IP = (() => {
 
 class DNSListener {
   constructor(
     name,
     expectedAnswer,
     expectedSuccess = true,
     delay,
     trrServer = "",
-    expectEarlyFail = false
+    expectEarlyFail = false,
+    flags = 0
   ) {
     this.name = name;
     this.expectedAnswer = expectedAnswer;
     this.expectedSuccess = expectedSuccess;
     this.delay = delay;
     this.promise = new Promise(resolve => {
       this.resolve = resolve;
     });
     if (trrServer == "") {
       this.request = dns.asyncResolve(
         name,
-        0,
+        flags,
         this,
         mainThread,
         defaultOriginAttributes
       );
     } else {
       try {
         this.request = dns.asyncResolveWithTrrServer(
           name,
           trrServer,
-          0,
+          flags,
           this,
           mainThread,
           defaultOriginAttributes
         );
         Assert.ok(!expectEarlyFail);
       } catch (e) {
         Assert.ok(expectEarlyFail);
         this.resolve([e]);
@@ -2003,8 +2004,81 @@ add_task(async function test_dohrollout_
   await doThenCheckMode(undefined, 2, 2);
   await doThenCheckMode(3, undefined, 3);
 
   Services.prefs.clearUserPref("network.trr.mode");
   equal(dns.currentTrrMode, 2);
   Services.prefs.clearUserPref("doh-rollout.mode");
   equal(dns.currentTrrMode, 0);
 });
+
+add_task(async function test_ipv6_trr_fallback() {
+  dns.clearCache(true);
+  let httpserver = new HttpServer();
+  httpserver.registerPathHandler("/content", (metadata, response) => {
+    response.setHeader("Content-Type", "text/plain");
+    response.setHeader("Cache-Control", "no-cache");
+
+    const responseBody = "anybody";
+    response.bodyOutputStream.write(responseBody, responseBody.length);
+  });
+  httpserver.start(-1);
+
+  Services.prefs.setBoolPref("network.captive-portal-service.testMode", true);
+  let url = `http://127.0.0.1:666/doom_port_should_not_be_open`;
+  Services.prefs.setCharPref("network.connectivity-service.IPv6.url", url);
+  let ncs = Cc[
+    "@mozilla.org/network/network-connectivity-service;1"
+  ].getService(Ci.nsINetworkConnectivityService);
+
+  function promiseObserverNotification(topic, matchFunc) {
+    return new Promise((resolve, reject) => {
+      Services.obs.addObserver(function observe(subject, topic, data) {
+        let matches =
+          typeof matchFunc != "function" || matchFunc(subject, data);
+        if (!matches) {
+          return;
+        }
+        Services.obs.removeObserver(observe, topic);
+        resolve({ subject, data });
+      }, topic);
+    });
+  }
+
+  let checks = promiseObserverNotification(
+    "network:connectivity-service:ip-checks-complete"
+  );
+
+  ncs.recheckIPConnectivity();
+
+  await checks;
+  equal(
+    ncs.IPv6,
+    Ci.nsINetworkConnectivityService.NOT_AVAILABLE,
+    "Check IPv6 support (expect NOT_AVAILABLE)"
+  );
+
+  Services.prefs.setIntPref("network.trr.mode", 2);
+  Services.prefs.setCharPref(
+    "network.trr.uri",
+    `https://foo.example.com:${h2Port}/doh?responseIP=4.4.4.4`
+  );
+  const override = Cc["@mozilla.org/network/native-dns-override;1"].getService(
+    Ci.nsINativeDNSResolverOverride
+  );
+  override.addIPOverride("ipv6.host.com", "1:1::2");
+
+  await new DNSListener(
+    "ipv6.host.com",
+    "1:1::2",
+    true,
+    0,
+    "",
+    false,
+    Ci.nsIDNSService.RESOLVE_DISABLE_IPV4
+  );
+
+  Services.prefs.clearUserPref("network.captive-portal-service.testMode");
+  Services.prefs.clearUserPref("network.connectivity-service.IPv6.url");
+
+  override.clearOverrides();
+  await httpserver.stop();
+}).only();