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/. */
7 ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
11 const dns = Cc["@mozilla.org/network/dns-service;1"].getService(
18 Services.prefs.setBoolPref("network.dns.upgrade_with_https_rr", true);
19 Services.prefs.setBoolPref("network.dns.use_https_rr_as_altsvc", true);
20 Services.prefs.setBoolPref("network.dns.echconfig.enabled", true);
24 registerCleanupFunction(async () => {
26 Services.prefs.clearUserPref("network.dns.upgrade_with_https_rr");
27 Services.prefs.clearUserPref("network.dns.use_https_rr_as_altsvc");
28 Services.prefs.clearUserPref("network.dns.echconfig.enabled");
29 Services.prefs.clearUserPref("network.dns.http3_echconfig.enabled");
30 Services.prefs.clearUserPref("network.http.http3.enable");
31 Services.prefs.clearUserPref("network.http.http2.enabled");
33 await trrServer.stop();
37 function checkResult(inRecord, noHttp2, noHttp3, result) {
42 .QueryInterface(Ci.nsIDNSHTTPSSVCRecord)
43 .GetServiceModeRecord(noHttp2, noHttp3);
45 /NS_ERROR_NOT_AVAILABLE/,
52 .QueryInterface(Ci.nsIDNSHTTPSSVCRecord)
53 .GetServiceModeRecord(noHttp2, noHttp3);
54 Assert.equal(record.priority, result.expectedPriority);
55 Assert.equal(record.name, result.expectedName);
56 Assert.equal(record.selectedAlpn, result.expectedAlpn);
59 // Test configuration:
60 // There are two records: one has a echConfig and the other doesn't.
61 // We want to test if the record with echConfig is preferred.
62 add_task(async function testEchConfigEnabled() {
63 let trrServer = new TRRServer();
64 await trrServer.start();
66 Services.prefs.setIntPref("network.trr.mode", 3);
67 Services.prefs.setCharPref(
69 `https://foo.example.com:${trrServer.port}/dns-query`
71 Services.prefs.setBoolPref("network.dns.echconfig.enabled", false);
73 await trrServer.registerDoHAnswers("test.bar.com", "HTTPS", {
82 name: "test.bar_1.com",
83 values: [{ key: "alpn", value: ["h3-29"] }],
93 name: "test.bar_2.com",
95 { key: "alpn", value: ["h2"] },
96 { key: "echconfig", value: "456..." },
103 let { inRecord } = await new TRRDNSListener("test.bar.com", {
104 type: dns.RESOLVE_TYPE_HTTPSSVC,
107 checkResult(inRecord, false, false, {
109 expectedName: "test.bar_1.com",
110 expectedAlpn: "h3-29",
112 checkResult(inRecord, false, true, {
114 expectedName: "test.bar_2.com",
117 checkResult(inRecord, true, false, {
119 expectedName: "test.bar_1.com",
120 expectedAlpn: "h3-29",
122 checkResult(inRecord, true, true);
124 Services.prefs.setBoolPref("network.dns.echconfig.enabled", true);
125 dns.clearCache(true);
127 ({ inRecord } = await new TRRDNSListener("test.bar.com", {
128 type: dns.RESOLVE_TYPE_HTTPSSVC,
131 checkResult(inRecord, false, false, {
133 expectedName: "test.bar_2.com",
136 checkResult(inRecord, false, true, {
138 expectedName: "test.bar_2.com",
141 checkResult(inRecord, true, false, {
143 expectedName: "test.bar_1.com",
144 expectedAlpn: "h3-29",
146 checkResult(inRecord, true, true);
148 await trrServer.stop();
152 // Test configuration:
153 // There are two records: both have echConfigs, and only one supports h3.
154 // This test is about testing which record should we get when
155 // network.dns.http3_echconfig.enabled is true and false.
156 // When network.dns.http3_echconfig.enabled is false, we should try to
157 // connect with h2 and echConfig.
158 add_task(async function testTwoRecordsHaveEchConfig() {
159 dns.clearCache(true);
161 let trrServer = new TRRServer();
162 await trrServer.start();
164 Services.prefs.setBoolPref("network.dns.echconfig.enabled", true);
165 Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", false);
166 Services.prefs.setIntPref("network.trr.mode", 3);
167 Services.prefs.setCharPref(
169 `https://foo.example.com:${trrServer.port}/dns-query`
172 await trrServer.registerDoHAnswers("test.foo.com", "HTTPS", {
175 name: "test.foo.com",
181 name: "test.foo_h3.com",
183 { key: "alpn", value: ["h3"] },
184 { key: "echconfig", value: "456..." },
189 name: "test.foo.com",
195 name: "test.foo_h2.com",
197 { key: "alpn", value: ["h2"] },
198 { key: "echconfig", value: "456..." },
205 let { inRecord } = await new TRRDNSListener("test.foo.com", {
206 type: dns.RESOLVE_TYPE_HTTPSSVC,
209 checkResult(inRecord, false, false, {
211 expectedName: "test.foo_h2.com",
214 checkResult(inRecord, false, true, {
216 expectedName: "test.foo_h2.com",
219 checkResult(inRecord, true, false, {
221 expectedName: "test.foo_h3.com",
224 checkResult(inRecord, true, true);
226 Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", true);
227 dns.clearCache(true);
228 ({ inRecord } = await new TRRDNSListener("test.foo.com", {
229 type: dns.RESOLVE_TYPE_HTTPSSVC,
232 checkResult(inRecord, false, false, {
234 expectedName: "test.foo_h3.com",
237 checkResult(inRecord, false, true, {
239 expectedName: "test.foo_h2.com",
242 checkResult(inRecord, true, false, {
244 expectedName: "test.foo_h3.com",
247 checkResult(inRecord, true, true);
249 await trrServer.stop();
253 // Test configuration:
254 // There are two records: both have echConfigs, and one supports h3 and h2.
255 // When network.dns.http3_echconfig.enabled is false, we should use the record
256 // that supports h3 and h2 (the alpn is h2).
257 add_task(async function testTwoRecordsHaveEchConfig1() {
258 dns.clearCache(true);
260 let trrServer = new TRRServer();
261 await trrServer.start();
263 Services.prefs.setBoolPref("network.dns.echconfig.enabled", true);
264 Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", false);
265 Services.prefs.setIntPref("network.trr.mode", 3);
266 Services.prefs.setCharPref(
268 `https://foo.example.com:${trrServer.port}/dns-query`
271 await trrServer.registerDoHAnswers("test.foo.com", "HTTPS", {
274 name: "test.foo.com",
280 name: "test.foo_h3.com",
282 { key: "alpn", value: ["h3", "h2"] },
283 { key: "echconfig", value: "456..." },
288 name: "test.foo.com",
294 name: "test.foo_h2.com",
296 { key: "alpn", value: ["h2", "http/1.1"] },
297 { key: "echconfig", value: "456..." },
304 let { inRecord } = await new TRRDNSListener("test.foo.com", {
305 type: dns.RESOLVE_TYPE_HTTPSSVC,
308 checkResult(inRecord, false, false, {
310 expectedName: "test.foo_h3.com",
313 checkResult(inRecord, false, true, {
315 expectedName: "test.foo_h3.com",
318 checkResult(inRecord, true, false, {
320 expectedName: "test.foo_h2.com",
321 expectedAlpn: "http/1.1",
323 checkResult(inRecord, true, true, {
325 expectedName: "test.foo_h2.com",
326 expectedAlpn: "http/1.1",
329 Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", true);
330 dns.clearCache(true);
331 ({ inRecord } = await new TRRDNSListener("test.foo.com", {
332 type: dns.RESOLVE_TYPE_HTTPSSVC,
335 checkResult(inRecord, false, false, {
337 expectedName: "test.foo_h3.com",
340 checkResult(inRecord, false, true, {
342 expectedName: "test.foo_h3.com",
345 checkResult(inRecord, true, false, {
347 expectedName: "test.foo_h3.com",
350 checkResult(inRecord, true, true, {
352 expectedName: "test.foo_h2.com",
353 expectedAlpn: "http/1.1",
356 await trrServer.stop();
360 // Test configuration:
361 // There are two records: only one support h3 and only one has echConfig.
362 // This test is about never usng the record without echConfig.
363 add_task(async function testOneRecordsHasEchConfig() {
364 dns.clearCache(true);
366 let trrServer = new TRRServer();
367 await trrServer.start();
369 Services.prefs.setBoolPref("network.dns.echconfig.enabled", true);
370 Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", false);
371 Services.prefs.setIntPref("network.trr.mode", 3);
372 Services.prefs.setCharPref(
374 `https://foo.example.com:${trrServer.port}/dns-query`
377 await trrServer.registerDoHAnswers("test.foo.com", "HTTPS", {
380 name: "test.foo.com",
386 name: "test.foo_h3.com",
388 { key: "alpn", value: ["h3"] },
389 { key: "echconfig", value: "456..." },
394 name: "test.foo.com",
400 name: "test.foo_h2.com",
401 values: [{ key: "alpn", value: ["h2"] }],
407 let { inRecord } = await new TRRDNSListener("test.foo.com", {
408 type: dns.RESOLVE_TYPE_HTTPSSVC,
411 checkResult(inRecord, false, false, {
413 expectedName: "test.foo_h3.com",
416 checkResult(inRecord, false, true, {
418 expectedName: "test.foo_h2.com",
421 checkResult(inRecord, true, false, {
423 expectedName: "test.foo_h3.com",
426 checkResult(inRecord, true, true);
428 Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", true);
429 dns.clearCache(true);
430 ({ inRecord } = await new TRRDNSListener("test.foo.com", {
431 type: dns.RESOLVE_TYPE_HTTPSSVC,
434 checkResult(inRecord, false, false, {
436 expectedName: "test.foo_h3.com",
439 checkResult(inRecord, false, true, {
441 expectedName: "test.foo_h2.com",
444 checkResult(inRecord, true, false, {
446 expectedName: "test.foo_h3.com",
449 checkResult(inRecord, true, true);
451 await trrServer.stop();
455 // Test the case that "network.http.http3.enable" and
456 // "network.http.http2.enabled" are true/false.
457 add_task(async function testHttp3AndHttp2Pref() {
458 dns.clearCache(true);
460 let trrServer = new TRRServer();
461 await trrServer.start();
463 Services.prefs.setBoolPref("network.http.http3.enable", false);
464 Services.prefs.setBoolPref("network.dns.echconfig.enabled", false);
465 Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", false);
466 Services.prefs.setIntPref("network.trr.mode", 3);
467 Services.prefs.setCharPref(
469 `https://foo.example.com:${trrServer.port}/dns-query`
472 await trrServer.registerDoHAnswers("test.foo.com", "HTTPS", {
475 name: "test.foo.com",
481 name: "test.foo_h3.com",
483 { key: "alpn", value: ["h3", "h2"] },
484 { key: "echconfig", value: "456..." },
489 name: "test.foo.com",
495 name: "test.foo_h2.com",
497 { key: "alpn", value: ["h2"] },
498 { key: "echconfig", value: "456..." },
505 let { inRecord } = await new TRRDNSListener("test.foo.com", {
506 type: dns.RESOLVE_TYPE_HTTPSSVC,
509 checkResult(inRecord, false, false, {
511 expectedName: "test.foo_h3.com",
514 checkResult(inRecord, false, true, {
516 expectedName: "test.foo_h3.com",
519 checkResult(inRecord, true, false);
520 checkResult(inRecord, true, true);
522 Services.prefs.setBoolPref("network.http.http2.enabled", false);
523 checkResult(inRecord, false, false);
525 Services.prefs.setBoolPref("network.http.http3.enable", true);
526 checkResult(inRecord, false, false, {
528 expectedName: "test.foo_h3.com",
531 checkResult(inRecord, false, true);
532 checkResult(inRecord, true, false, {
534 expectedName: "test.foo_h3.com",
537 checkResult(inRecord, true, true);
539 await trrServer.stop();