From 9f4d6be7fc6918bdf371f25adfbb870526c95596 Mon Sep 17 00:00:00 2001 From: Valentin Gosu Date: Tue, 9 Nov 2021 16:41:45 +0000 Subject: [PATCH] Bug 1566998 - Make test_trr/test_odoh::test_CNAME not be dependent on A/AAAA order r=necko-reviewers,kershaw The order in which we send A/AAAA requests is unspecified. This test assumed the A request is always first. If we change that logic, then the variable ends up != 0 on the second request, so we don't get the proper response anymore. This patch changes the server handler so it returns the proper response after decoding the request packet. Differential Revision: https://phabricator.services.mozilla.com/D130043 --- netwerk/test/unit/trr_common.js | 6 -- testing/xpcshell/moz-http2/moz-http2.js | 108 ++++++++++++++++-------- 2 files changed, 73 insertions(+), 41 deletions(-) diff --git a/netwerk/test/unit/trr_common.js b/netwerk/test/unit/trr_common.js index 5abd4a07f17e..2760437422f7 100644 --- a/netwerk/test/unit/trr_common.js +++ b/netwerk/test/unit/trr_common.js @@ -389,12 +389,6 @@ async function test_CNAME() { dns.clearCache(true); // First mode 3. if (runningODoHTests) { - let chan = makeChan( - `https://foo.example.com:${h2Port}/reset_cname_confirm`, - Ci.nsIRequest.TRR_DISABLED_MODE - ); - await new Promise(resolve => chan.asyncOpen(new ChannelListener(resolve))); - setModeAndURI(3, "odoh?responseIP=none&cnameloop=true"); } else { setModeAndURI(3, "doh?responseIP=none&cnameloop=true"); diff --git a/testing/xpcshell/moz-http2/moz-http2.js b/testing/xpcshell/moz-http2/moz-http2.js index 2a7f270dd690..3535bbaa42a5 100644 --- a/testing/xpcshell/moz-http2/moz-http2.js +++ b/testing/xpcshell/moz-http2/moz-http2.js @@ -234,8 +234,6 @@ var didRst = false; var rstConnection = null; var illegalheader_conn = null; -var cname_confirm = 0; - // eslint-disable-next-line complexity function handleRequest(req, res) { // We do this first to ensure nothing goes wonky in our tests that don't want @@ -249,23 +247,62 @@ function handleRequest(req, res) { // PushService tests. var pushPushServer1, pushPushServer2, pushPushServer3, pushPushServer4; - function createCNameContent() { - let rContent; - if (0 == cname_confirm) { - // ... this sends a CNAME back to pointing-elsewhere.example.com - rContent = Buffer.from( - "00000100000100010000000005636E616D65076578616D706C6503636F6D0000050001C00C0005000100000037002012706F696E74696E672D656C73657768657265076578616D706C6503636F6D00", - "hex" - ); - cname_confirm++; - } else { - // ... this sends an A 99.88.77.66 entry back for pointing-elsewhere.example.com - rContent = Buffer.from( - "00000100000100010000000012706F696E74696E672D656C73657768657265076578616D706C6503636F6D0000010001C00C0001000100000037000463584D42", - "hex" - ); + function createCNameContent(payload) { + let packet = dnsPacket.decode(payload); + if ( + packet.questions[0].name == "cname.example.com" && + packet.questions[0].type == "A" + ) { + return dnsPacket.encode({ + id: 0, + type: "response", + flags: dnsPacket.RECURSION_DESIRED, + questions: [{ name: packet.questions[0].name, type: "A", class: "IN" }], + answers: [ + { + name: packet.questions[0].name, + ttl: 55, + type: "CNAME", + flush: false, + data: "pointing-elsewhere.example.com", + }, + ], + }); } - return rContent; + if ( + packet.questions[0].name == "pointing-elsewhere.example.com" && + packet.questions[0].type == "A" + ) { + return dnsPacket.encode({ + id: 0, + type: "response", + flags: dnsPacket.RECURSION_DESIRED, + questions: [{ name: packet.questions[0].name, type: "A", class: "IN" }], + answers: [ + { + name: packet.questions[0].name, + ttl: 55, + type: "A", + flush: false, + data: "99.88.77.66", + }, + ], + }); + } + + return dnsPacket.encode({ + id: 0, + type: "response", + flags: dnsPacket.RECURSION_DESIRED | dnsPacket.rcodes.toRcode("NXDOMAIN"), + questions: [ + { + name: packet.questions[0].name, + type: packet.questions[0].type, + class: "IN", + }, + ], + answers: [], + }); } function createCNameARecord() { @@ -828,17 +865,25 @@ function handleRequest(req, res) { // for use with test_trr.js else if (u.pathname === "/dns-cname") { // asking for cname.example.com - let rContent = createCNameContent(); - res.setHeader("Content-Type", "application/dns-message"); - res.setHeader("Content-Length", rContent.length); - res.writeHead(200); - res.write(rContent); - res.end(""); + function emitResponse(res, payload) { + let content = createCNameContent(payload); + res.setHeader("Content-Type", "application/dns-message"); + res.setHeader("Content-Length", content.length); + res.writeHead(200); + res.write(content); + res.end(""); + } + + let payload = Buffer.from(""); + req.on("data", function receiveData(chunk) { + payload = Buffer.concat([payload, chunk]); + }); + req.on("end", function finishedData() { + emitResponse(res, payload); + }); return; } else if (u.pathname == "/doh") { - cname_confirm = 0; // back to first reply for dns-cname - let responseIP = u.query.responseIP; if (!responseIP) { responseIP = "5.5.5.5"; @@ -1173,12 +1218,12 @@ function handleRequest(req, res) { } if (u.query.cname) { - odoh.decrypt_query(payload); + let decryptedQuery = odoh.decrypt_query(payload); let rContent; if (u.query.cname === "ARecord") { rContent = createCNameARecord(); } else { - rContent = createCNameContent(); + rContent = createCNameContent(Buffer.from(decryptedQuery.buffer)); } let encryptedResponse = odoh.create_response(rContent); res.setHeader("Content-Type", "application/oblivious-dns-message"); @@ -1194,13 +1239,6 @@ function handleRequest(req, res) { } }); return; - } else if (u.pathname === "/reset_cname_confirm") { - cname_confirm = 0; - res.setHeader("Content-Length", 4); - res.writeHead(200); - res.write("done"); - res.end(); - return; } else if (u.pathname === "/httpssvc_as_altsvc") { let payload = Buffer.from(""); req.on("data", function receiveData(chunk) {