1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 function makeChan(url
) {
10 let chan
= NetUtil
.newChannel({
12 loadUsingSystemPrincipal
: true,
13 }).QueryInterface(Ci
.nsIHttpChannel
);
17 function channelOpenPromise(chan
) {
18 return new Promise(resolve
=> {
19 function finish(req
, buffer
) {
20 resolve([req
, buffer
]);
22 chan
.asyncOpen(new ChannelListener(finish
));
26 add_setup(async
function setup() {
28 registerCleanupFunction(async () => {
32 trrServer
= new TRRServer();
33 registerCleanupFunction(async () => {
34 await trrServer
.stop();
36 await trrServer
.start();
37 dump(`port = ${trrServer.port()}\n`);
38 let chan
= makeChan(`https://localhost:${trrServer.port()}/test?bla=some`);
39 let [, resp
] = await
channelOpenPromise(chan
);
40 equal(resp
, "<h1> 404 Path not found: /test</h1>");
42 Services
.dns
.clearCache(true);
43 Services
.prefs
.setIntPref("network.trr.mode", 3);
44 Services
.prefs
.setCharPref(
46 `https://foo.example.com:${trrServer.port()}/dns-query`
50 add_task(async
function test_follow_cnames_same_response() {
51 await trrServer
.registerDoHAnswers("something.foo", "A", {
54 name
: "something.foo",
83 let { inRecord
} = await
new TRRDNSListener("something.foo", {
84 expectedAnswer
: "1.2.3.4",
85 flags
: Ci
.nsIDNSService
.RESOLVE_CANONICAL_NAME
,
87 equal(inRecord
.QueryInterface(Ci
.nsIDNSAddrRecord
).canonicalName
, "xyz.foo");
89 await trrServer
.registerDoHAnswers("a.foo", "A", {
100 await trrServer
.registerDoHAnswers("b.foo", "A", {
111 await
new TRRDNSListener("a.foo", { expectedAnswer
: "2.3.4.5" });
114 add_task(async
function test_cname_nodata() {
115 // Test that we don't needlessly follow cname chains when the RA flag is set
118 await trrServer
.registerDoHAnswers("first.foo", "A", {
137 await trrServer
.registerDoHAnswers("first.foo", "AAAA", {
150 await
new TRRDNSListener("first.foo", { expectedAnswer
: "1.2.3.4" });
151 equal(await trrServer
.requestCount("first.foo", "A"), 1);
152 equal(await trrServer
.requestCount("first.foo", "AAAA"), 1);
153 equal(await trrServer
.requestCount("second.foo", "A"), 0);
154 equal(await trrServer
.requestCount("second.foo", "AAAA"), 0);
156 await trrServer
.registerDoHAnswers("first.bar", "A", {
174 await trrServer
.registerDoHAnswers("first.bar", "AAAA", {
186 await
new TRRDNSListener("first.bar", { expectedAnswer
: "1.2.3.4" });
187 equal(await trrServer
.requestCount("first.bar", "A"), 1);
188 equal(await trrServer
.requestCount("first.bar", "AAAA"), 1);
189 equal(await trrServer
.requestCount("second.bar", "A"), 0); // addr included in first response
190 equal(await trrServer
.requestCount("second.bar", "AAAA"), 1); // will follow cname because no flag is set
192 // Check that it also works for HTTPS records
194 await trrServer
.registerDoHAnswers("first.bar", "HTTPS", {
206 { key
: "alpn", value
: ["h2", "h3"] },
207 { key
: "no-default-alpn" },
208 { key
: "port", value
: 8888 },
209 { key
: "ipv4hint", value
: "1.2.3.4" },
210 { key
: "echconfig", value
: "123..." },
211 { key
: "ipv6hint", value
: "::1" },
225 let { inStatus
} = await
new TRRDNSListener("first.bar", {
226 type
: Ci
.nsIDNSService
.RESOLVE_TYPE_HTTPSSVC
,
228 Assert
.ok(Components
.isSuccessCode(inStatus
), `${inStatus} should work`);
229 equal(await trrServer
.requestCount("first.bar", "HTTPS"), 1);
230 equal(await trrServer
.requestCount("second.bar", "HTTPS"), 0);