commit 834688be4e8718a10b2732b9b9eb724369cbc235
parent 4f92388465cfeecbd3e1493d2673e260fd258e84
Author: Valentin Gosu <valentin.gosu@gmail.com>
Date: Tue, 16 Dec 2025 08:47:57 +0000
Bug 2005731 - Fix test infra to support DoH with GET method r=necko-reviewers,kershaw
Differential Revision: https://phabricator.services.mozilla.com/D276317
Diffstat:
3 files changed, 64 insertions(+), 43 deletions(-)
diff --git a/netwerk/test/unit/head_trr.js b/netwerk/test/unit/head_trr.js
@@ -249,7 +249,6 @@ class TRRDNSListener {
// This is for reteriiving the raw bytes from a DNS answer.
function answerHandler(req, resp) {
let searchParams = new URL(req.url, "http://example.com").searchParams;
- console.log("req.searchParams:" + searchParams);
if (!searchParams.get("host")) {
resp.writeHead(400);
resp.end("Missing search parameter");
@@ -287,7 +286,7 @@ function answerHandler(req, resp) {
/// This is the default handler for /dns-query
/// It implements basic functionality for parsing the DoH packet, then
/// queries global.dns_query_answers for available answers for the DNS query.
-function trrQueryHandler(req, resp, url) {
+function trrQueryHandler(req, resp) {
let requestBody = Buffer.from("");
let method = req.headers[global.http2.constants.HTTP2_HEADER_METHOD];
let contentLength = req.headers["content-length"];
@@ -300,13 +299,14 @@ function trrQueryHandler(req, resp, url) {
}
});
} else if (method == "GET") {
- if (!url.query.dns) {
+ let searchParams = new URL(req.url, "http://example.com").searchParams;
+ if (!searchParams.get("dns")) {
resp.writeHead(400);
resp.end("Missing dns parameter");
return;
}
- requestBody = Buffer.from(url.query.dns, "base64");
+ requestBody = Buffer.from(searchParams.get("dns"), "base64");
processRequest(req, resp, requestBody);
} else {
// unexpected method.
diff --git a/netwerk/test/unit/trr_common.js b/netwerk/test/unit/trr_common.js
@@ -469,6 +469,8 @@ async function test_mode_1_and_4() {
async function test_CNAME() {
info("Checking that we follow a CNAME correctly");
+ // cnameHandler for dns-cname in head_trr doesn't currently suppport GET
+ Services.prefs.setBoolPref("network.trr.useGET", false);
Services.dns.clearCache(true);
// The dns-cname path alternates between sending us a CNAME pointing to
// another domain, and an A record. If we follow the cname correctly, doing
@@ -504,6 +506,7 @@ async function test_CNAME() {
setModeAndURI(3, "dns-cname-a");
await new TRRDNSListener("cname-a.example.com", "9.8.7.6");
+ Services.prefs.clearUserPref("network.trr.useGET");
}
async function test_name_mismatch() {
diff --git a/testing/mochitest/DoHServer/doh_server.js b/testing/mochitest/DoHServer/doh_server.js
@@ -34,6 +34,20 @@ let alpn = process.argv[4].split("=")[1];
let server = http2.createSecureServer(
options,
function handleRequest(req, res) {
+ let method = req.headers[http2.constants.HTTP2_HEADER_METHOD];
+ if (method == "GET") {
+ let searchParams = new URL(req.url, "http://example.com").searchParams;
+ if (!searchParams.get("dns")) {
+ res.writeHead(400);
+ res.end("Missing dns parameter");
+ return;
+ }
+
+ let requestBody = Buffer.from(searchParams.get("dns"), "base64");
+ processRequest(req, res, requestBody);
+ return;
+ }
+
let u = "";
if (req.url != undefined) {
u = url.parse(req.url, true);
@@ -45,49 +59,53 @@ let server = http2.createSecureServer(
payload = Buffer.concat([payload, chunk]);
});
req.on("end", function finishedData() {
- let packet = dnsPacket.decode(payload);
- let answers = [];
- // Return the HTTPS RR to let Firefox connect to the HTTP/3 server
- if (packet.questions[0].type === "HTTPS") {
- answers.push({
- name: packet.questions[0].name,
- type: "HTTPS",
- ttl: 55,
- class: "IN",
- flush: false,
- data: {
- priority: 1,
- name: packet.questions[0].name,
- values: [
- { key: "alpn", value: [alpn] },
- { key: "port", value: serverPort },
- ],
- },
- });
- } else if (packet.questions[0].type === "A") {
- answers.push({
- name: packet.questions[0].name,
- type: "A",
- ttl: 55,
- flush: false,
- data: "127.0.0.1",
- });
- }
+ processRequest(req, res, payload);
+ });
+ }
- let buf = dnsPacket.encode({
- type: "response",
- id: packet.id,
- flags: dnsPacket.RECURSION_DESIRED,
- questions: packet.questions,
- answers,
+ function processRequest(req, res, payload) {
+ let packet = dnsPacket.decode(payload);
+ let answers = [];
+ // Return the HTTPS RR to let Firefox connect to the HTTP/3 server
+ if (packet.questions[0].type === "HTTPS") {
+ answers.push({
+ name: packet.questions[0].name,
+ type: "HTTPS",
+ ttl: 55,
+ class: "IN",
+ flush: false,
+ data: {
+ priority: 1,
+ name: packet.questions[0].name,
+ values: [
+ { key: "alpn", value: [alpn] },
+ { key: "port", value: serverPort },
+ ],
+ },
});
+ } else if (packet.questions[0].type === "A") {
+ answers.push({
+ name: packet.questions[0].name,
+ type: "A",
+ ttl: 55,
+ flush: false,
+ data: "127.0.0.1",
+ });
+ }
- res.setHeader("Content-Type", "application/dns-message");
- res.setHeader("Content-Length", buf.length);
- res.writeHead(200);
- res.write(buf);
- res.end("");
+ let buf = dnsPacket.encode({
+ type: "response",
+ id: packet.id,
+ flags: dnsPacket.RECURSION_DESIRED,
+ questions: packet.questions,
+ answers,
});
+
+ res.setHeader("Content-Type", "application/dns-message");
+ res.setHeader("Content-Length", buf.length);
+ res.writeHead(200);
+ res.write(buf);
+ res.end("");
}
}
);