Bug 1552886 - Modernize test_trr.js (part 2) r=dragana
authorValentin Gosu <valentin.gosu@gmail.com>
Wed, 29 May 2019 21:40:11 +0000
changeset 476318 f2b37969fe0b44b5e811caa4e8f0e1ef347f4371
parent 476317 a2ec4ac648cfd975770679be53525cb104368400
child 476319 fb18d0ab83796cd7496b19dddeb25c4688e89aa2
push id36092
push userarchaeopteryx@coole-files.de
push dateFri, 31 May 2019 17:03:46 +0000
treeherdermozilla-central@8384972e1f6a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana
bugs1552886
milestone69.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 1552886 - Modernize test_trr.js (part 2) r=dragana Differential Revision: https://phabricator.services.mozilla.com/D31801
netwerk/test/unit/test_trr.js
testing/xpcshell/moz-http2/moz-http2.js
--- a/netwerk/test/unit/test_trr.js
+++ b/netwerk/test/unit/test_trr.js
@@ -19,17 +19,17 @@ add_task(function setup() {
   do_get_profile();
 
   Services.prefs.setBoolPref("network.http.spdy.enabled", true);
   Services.prefs.setBoolPref("network.http.spdy.enabled.http2", true);
   // the TRR server is on 127.0.0.1
   Services.prefs.setCharPref("network.trr.bootstrapAddress", "127.0.0.1");
 
   // use the h2 server as DOH provider
-  Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/dns`);
+  Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/doh`);
   // make all native resolve calls "secretly" resolve localhost instead
   Services.prefs.setBoolPref("network.dns.native-is-localhost", true);
 
   // 0 - off, 1 - race, 2 TRR first, 3 TRR only, 4 shadow
   Services.prefs.setIntPref("network.trr.mode", 2); // TRR first
   Services.prefs.setBoolPref("network.trr.wait-for-portal", false);
   // don't confirm that TRR is working, just go!
   Services.prefs.setCharPref("network.trr.confirmationNS", "skip");
@@ -48,16 +48,17 @@ registerCleanupFunction(() => {
   Services.prefs.clearUserPref("network.trr.wait-for-portal");
   Services.prefs.clearUserPref("network.trr.allow-rfc1918");
   Services.prefs.clearUserPref("network.trr.useGET");
   Services.prefs.clearUserPref("network.trr.confirmationNS");
   Services.prefs.clearUserPref("network.trr.bootstrapAddress");
   Services.prefs.clearUserPref("network.trr.blacklist-duration");
   Services.prefs.clearUserPref("network.trr.request-timeout");
   Services.prefs.clearUserPref("network.trr.disable-ECS");
+  Services.prefs.clearUserPref("network.trr.early-AAAA");
   Services.prefs.clearUserPref("network.trr.excluded-domains");
 
   Services.prefs.clearUserPref("network.http.spdy.enabled");
   Services.prefs.clearUserPref("network.http.spdy.enabled.http2");
   Services.prefs.clearUserPref("network.dns.localDomains");
   Services.prefs.clearUserPref("network.dns.native-is-localhost");
 });
 
@@ -168,19 +169,28 @@ add_task(async function test5b() {
   dump("test5b - resolve push.example.now please\n");
 
   await new DNSListener("push.example.com", "2018::2018");
 });
 
 // verify AAAA entry
 add_task(async function test6() {
   dns.clearCache(true);
+
+  Services.prefs.setBoolPref("network.trr.early-AAAA", true);
   Services.prefs.setIntPref("network.trr.mode", 3); // TRR-only
   Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/doh?responseIP=2020:2020::2020`);
   await new DNSListener("aaaa.example.com", "2020:2020::2020");
+
+  dns.clearCache(true);
+  Services.prefs.setBoolPref("network.trr.early-AAAA", false);
+  Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/doh?responseIP=2020:2020::2030`);
+  await new DNSListener("aaaa.example.com", "2020:2020::2030");
+
+  Services.prefs.clearUserPref("network.trr.early-AAAA");
 });
 
 // verify RFC1918 address from the server is rejected
 add_task(async function test7() {
   dns.clearCache(true);
   Services.prefs.setIntPref("network.trr.mode", 3); // TRR-only
   Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/doh?responseIP=192.168.0.1`);
   let [, , inStatus] = await new DNSListener("rfc1918.example.com", undefined, false);
@@ -215,49 +225,45 @@ add_task(async function test9() {
   Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/doh`);
   Services.prefs.clearUserPref("network.trr.allow-rfc1918");
   Services.prefs.setBoolPref("network.trr.useGET", true);
   Services.prefs.setBoolPref("network.trr.disable-ECS", false);
   await new DNSListener("get.example.com", "5.5.5.5");
 });
 
 // confirmationNS set without confirmed NS yet
-// NOTE: this requires test9 to run before, as the http2 server resets state there
 add_task(async function test10() {
   dns.clearCache(true);
   Services.prefs.setIntPref("network.trr.mode", 3); // TRR-only
   Services.prefs.clearUserPref("network.trr.useGET");
   Services.prefs.clearUserPref("network.trr.disable-ECS");
-  Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/dns-confirm`);
+  Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/doh?responseIP=1::ffff`);
   Services.prefs.setCharPref("network.trr.confirmationNS", "confirm.example.com");
 
   try {
     let [, , inStatus] = await new DNSListener("wrong.example.com", undefined, false);
     Assert.ok(!Components.isSuccessCode(inStatus), `${inStatus} should be an error code`);
   } catch (e) {
     await new Promise(resolve => do_timeout(200, resolve));
   }
-});
 
-// confirmationNS, retry until the confirmed NS works
-add_task(async function test10b() {
-  dns.clearCache(true);
+  // confirmationNS, retry until the confirmed NS works
   let test_loops = 100;
   print("test confirmationNS, retry until the confirmed NS works");
-  Services.prefs.setIntPref("network.trr.mode", 3); // TRR-only
-  // same URI as in test10
 
   // this test needs to resolve new names in every attempt since the DNS
   // will keep the negative resolved info
   while (test_loops > 0) {
-    print(`loops remaining: ${test_loops}`);
+    print(`loops remaining: ${test_loops}\n`);
     try {
       let [, inRecord, inStatus] = await new DNSListener(`10b-${test_loops}.example.com`, undefined, false);
       if (inRecord) {
         Assert.equal(inStatus, Cr.NS_OK);
+        let answer = inRecord.getNextAddrAsString();
+        Assert.equal(answer, "1::ffff");
         break;
       }
     } catch (e) {
       dump(e);
     }
 
     test_loops--;
     await new Promise(resolve => do_timeout(0, resolve));
@@ -271,23 +277,23 @@ add_task(async function test11() {
   Services.prefs.setIntPref("network.trr.mode", 3); // TRR-only
   Services.prefs.setCharPref("network.trr.confirmationNS", "skip");
   Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/dns-750ms`);
   Services.prefs.setIntPref("network.trr.request-timeout", 10);
   let [, , inStatus] = await new DNSListener("test11.example.com", undefined, false);
   Assert.ok(!Components.isSuccessCode(inStatus), `${inStatus} should be an error code`);
 });
 
-// gets an NS back from DOH
+// gets an no answers back from DoH. Falls back to regular DNS
 add_task(async function test12() {
   dns.clearCache(true);
   Services.prefs.setIntPref("network.trr.mode", 2); // TRR-first
-  Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/dns-ns`);
+  Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/doh?responseIP=none`);
   Services.prefs.clearUserPref("network.trr.request-timeout");
-  await new DNSListener("test12.example.com", "127.0.0.1");
+  await new DNSListener("confirm.example.com", "127.0.0.1");
 });
 
 // TRR-first gets a 404 back from DOH
 add_task(async function test13() {
   dns.clearCache(true);
   Services.prefs.setIntPref("network.trr.mode", 2); // TRR-first
   Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/404`);
   await new DNSListener("test13.example.com", "127.0.0.1");
@@ -327,51 +333,51 @@ add_task(async function test17() {
   Services.prefs.clearUserPref("network.trr.request-timeout");
   await new DNSListener("cname.example.com", "99.88.77.66");
 });
 
 // TRR-only and a CNAME loop
 add_task(async function test18() {
   dns.clearCache(true);
   Services.prefs.setIntPref("network.trr.mode", 3); // TRR-only
-  Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/dns-cname-loop`);
+  Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/doh?responseIP=none&cnameloop=true`);
   let [, , inStatus] = await new DNSListener("test18.example.com", undefined, false);
   Assert.ok(!Components.isSuccessCode(inStatus), `${inStatus} should be an error code`);
 });
 
 // TRR-race and a CNAME loop
 add_task(async function test19() {
   dns.clearCache(true);
   Services.prefs.setIntPref("network.trr.mode", 1); // Race them!
-  Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/dns-cname-loop`);
+  Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/doh?responseIP=none&cnameloop=true`);
   await new DNSListener("test19.example.com", "127.0.0.1");
 });
 
 // TRR-first and a CNAME loop
 add_task(async function test20() {
   dns.clearCache(true);
   Services.prefs.setIntPref("network.trr.mode", 2); // TRR-first
-  Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/dns-cname-loop`);
+  Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/doh?responseIP=none&cnameloop=true`);
   await new DNSListener("test20.example.com", "127.0.0.1");
 });
 
 // TRR-shadow and a CNAME loop
 add_task(async function test21() {
   dns.clearCache(true);
   Services.prefs.setIntPref("network.trr.mode", 4); // shadow
-  Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/dns-cname-loop`);
+  Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/doh?responseIP=none&cnameloop=true`);
   await new DNSListener("test21.example.com", "127.0.0.1");
 });
 
 // verify that basic A record name mismatch gets rejected.
 // Gets a response for bar.example.com instead of what it requested
 add_task(async function test22() {
   dns.clearCache(true);
   Services.prefs.setIntPref("network.trr.mode", 3); // TRR-only to avoid native fallback
-  Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/dns`);
+  Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/doh?hostname=bar.example.com`);
   let [, , inStatus] = await new DNSListener("mismatch.example.com", undefined, false);
   Assert.ok(!Components.isSuccessCode(inStatus), `${inStatus} should be an error code`);
 });
 
 // TRR-only, with a CNAME response with a bundled A record for that CNAME!
 add_task(async function test23() {
   dns.clearCache(true);
   Services.prefs.setIntPref("network.trr.mode", 3); // TRR-only
@@ -437,8 +443,15 @@ add_task(async function test25c() {
 add_task(async function test25d() {
   dns.clearCache(true);
   Services.prefs.setIntPref("network.trr.mode", 3); // TRR-only
   Services.prefs.setCharPref("network.trr.excluded-domains", "localhost,local,other");
   Services.prefs.setCharPref("network.trr.uri", `https://foo.example.com:${h2Port}/doh?responseIP=192.192.192.192`);
 
   await new DNSListener("domain.other", "127.0.0.1");
 });
+
+// Check that none of the requests have set any cookies.
+add_task(async function count_cookies() {
+  let cm = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager);
+  Assert.equal(cm.countCookiesFromHost("example.com"), 0);
+  Assert.equal(cm.countCookiesFromHost("foo.example.com."), 0);
+});
--- a/testing/xpcshell/moz-http2/moz-http2.js
+++ b/testing/xpcshell/moz-http2/moz-http2.js
@@ -191,17 +191,16 @@ function insertHardIllegalHpack(headers)
 }
 
 var h11required_conn = null;
 var h11required_header = "yes";
 var didRst = false;
 var rstConnection = null;
 var illegalheader_conn = null;
 
-var ns_confirm = 0;
 var cname_confirm = 0;
 
 function handleRequest(req, res) {
   // We do this first to ensure nothing goes wonky in our tests that don't want
   // the headers to have something illegal in them
   Compressor.prototype.compress = originalCompressHeaders;
 
   var u = url.parse(req.url, true);
@@ -548,17 +547,16 @@ function handleRequest(req, res) {
     res.setHeader('Content-Length', content.length);
     res.writeHead(200);
     res.write(content);
     res.end("");
     return;
 
   }
   else if (u.pathname == "/doh") {
-    ns_confirm = 0; // back to first reply for dns-confirm
     cname_confirm = 0; // back to first reply for dns-cname
 
     let responseIP = u.query["responseIP"];
     if (!responseIP) {
       responseIP = "5.5.5.5";
     }
 
     if (u.query["auth"]) {
@@ -599,28 +597,64 @@ function handleRequest(req, res) {
       push.end(pcontent);
     }
 
     let payload = new Buffer("");
 
     function emitResponse(response, requestPayload) {
       let packet = dnsPacket.decode(requestPayload);
 
+      function responseType() {
+        if (packet.questions.length > 0 &&
+          packet.questions[0].name == "confirm.example.com" &&
+          packet.questions[0].type == "NS") {
+          return "NS";
+        }
+
+        return ip.isV4Format(responseIP) ? "A" : "AAAA";
+      }
+
+      function responseData() {
+        if (packet.questions.length > 0 &&
+          packet.questions[0].name == "confirm.example.com" &&
+          packet.questions[0].type == "NS") {
+          return "ns.example.com";
+        }
+
+        return responseIP;
+      }
+
+      let answers = [];
+      if (responseIP != "none" && responseType() == packet.questions[0].type) {
+        answers.push({
+          name: u.query["hostname"] ? u.query["hostname"] : packet.questions[0].name,
+          ttl: 55,
+          type: responseType(),
+          flush: false,
+          data: responseData(),
+        });
+      }
+
+      if (u.query["cnameloop"]) {
+        answers.push({
+          name: "cname.example.com",
+          type: "CNAME",
+          ttl: 55,
+          class: "IN",
+          flush: false,
+          data: "pointing-elsewhere.example.com",
+        });
+      }
+
       let buf = dnsPacket.encode({
-        type: 'query',
+        type: 'response',
         id: packet.id,
         flags: dnsPacket.RECURSION_DESIRED,
         questions: packet.questions,
-        answers: [{
-          name: packet.questions[0].name,
-          ttl: 55,
-          type: ip.isV4Format(responseIP) ? "A" : "AAAA",
-          flush: false,
-          data: responseIP,
-        }],
+        answers: answers,
       });
 
       response.setHeader('Content-Length', buf.length);
       response.setHeader('Set-Cookie', 'trackyou=yes; path=/; max-age=100000;');
       response.setHeader('Content-Type', 'application/dns-message');
       response.writeHead(200);
       response.write(buf);
       response.end("");
@@ -678,68 +712,20 @@ function handleRequest(req, res) {
     res.setHeader('Content-Type', 'application/dns-message');
     res.setHeader('Content-Length', content.length);
     res.writeHead(200);
     res.write(content);
     res.end("");
     return;
 
   }
-  else if (u.pathname === "/dns-cname-loop") {
-    // asking for cname.example.com
-    var content;
-    // ... this always sends a CNAME back to pointing-elsewhere.example.com. Loop time!
-    content = new Buffer("00000100000100010000000005636E616D65076578616D706C6503636F6D0000050001C00C0005000100000037002012706F696E74696E672D656C73657768657265076578616D706C65C01A00", "hex");
-    res.setHeader('Content-Type', 'application/dns-message');
-    res.setHeader('Content-Length', content.length);
-    res.writeHead(200);
-    res.write(content);
-    res.end("");
-    return;
-
-  }
-  else if (u.pathname === "/dns-ns") {
-    // confirm.example.com has NS entry ns.example.com
-    var content= new Buffer("00000100000100010000000007636F6E6669726D076578616D706C6503636F6D0000020001C00C00020001000000370012026E73076578616D706C6503636F6D010A00", "hex");
-    res.setHeader('Content-Type', 'application/dns-message');
-    res.setHeader('Content-Length', content.length);
-    res.writeHead(200);
-    res.write(content);
-    res.end("");
-    return;
-  }
   else if (u.pathname === '/dns-750ms') {
     // it's just meant to be this slow - the test doesn't care about the actual response
     return;
   }
-  // for use with test_trr.js
-  else if (u.pathname === "/dns-confirm") {
-    if (0 == ns_confirm) {
-      // confirm.example.com has NS entry ns.example.com
-      var content= new Buffer("00000100000100010000000007636F6E6669726D076578616D706C6503636F6D0000020001C00C00020001000000370012026E73076578616D706C6503636F6D010A00", "hex");
-      ns_confirm++;
-    } else if (2 >= ns_confirm) {
-      // next response: 10b-100.example.com has AAAA entry 1::FFFF
-
-      // we expect two requests for this name (A + AAAA), respond identically
-      // for both and expect the client to reject the wrong one
-      var content= new Buffer("000001000001000100000000" + "073130622d313030" +
-                              "076578616D706C6503636F6D00001C0001C00C001C00010000003700100001000000000000000000000000FFFF", "hex");
-      ns_confirm++;
-    } else {
-      // everything else is just wrong
-      return;
-    }
-    res.setHeader('Content-Type', 'application/dns-message');
-    res.setHeader('Content-Length', content.length);
-    res.writeHead(200);
-    res.write(content);
-    res.end("");
-    return;
-  }
   // for use with test_esni_dns_fetch.js
   else if (u.pathname === "/esni-dns") {
     content = new Buffer("0000" +
                          "8180" +
                          "0001" + // QDCOUNT
                          "0001" + // ANCOUNT
                          "00000000" + // NSCOUNT + ARCOUNT
                          "055F65736E69076578616D706C6503636F6D00" + // _esni.example.com