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/. */
12 Services.prefs.setBoolPref("network.dns.upgrade_with_https_rr", true);
13 Services.prefs.setBoolPref("network.dns.use_https_rr_as_altsvc", true);
14 Services.prefs.setBoolPref("network.dns.echconfig.enabled", true);
18 registerCleanupFunction(async () => {
20 Services.prefs.clearUserPref("network.dns.upgrade_with_https_rr");
21 Services.prefs.clearUserPref("network.dns.use_https_rr_as_altsvc");
22 Services.prefs.clearUserPref("network.dns.echconfig.enabled");
23 Services.prefs.clearUserPref("network.dns.http3_echconfig.enabled");
24 Services.prefs.clearUserPref("network.http.http3.enable");
25 Services.prefs.clearUserPref("network.http.http2.enabled");
27 await trrServer.stop();
31 function checkResult(inRecord, noHttp2, noHttp3, result) {
36 .QueryInterface(Ci.nsIDNSHTTPSSVCRecord)
37 .GetServiceModeRecord(noHttp2, noHttp3);
39 /NS_ERROR_NOT_AVAILABLE/,
46 .QueryInterface(Ci.nsIDNSHTTPSSVCRecord)
47 .GetServiceModeRecord(noHttp2, noHttp3);
48 Assert.equal(record.priority, result.expectedPriority);
49 Assert.equal(record.name, result.expectedName);
50 Assert.equal(record.selectedAlpn, result.expectedAlpn);
53 // Test configuration:
54 // There are two records: one has a echConfig and the other doesn't.
55 // We want to test if the record with echConfig is preferred.
56 add_task(async function testEchConfigEnabled() {
57 trrServer = new TRRServer();
58 await trrServer.start();
60 Services.prefs.setIntPref("network.trr.mode", 3);
61 Services.prefs.setCharPref(
63 `https://foo.example.com:${trrServer.port()}/dns-query`
65 Services.prefs.setBoolPref("network.dns.echconfig.enabled", false);
67 await trrServer.registerDoHAnswers("test.bar.com", "HTTPS", {
76 name: "test.bar_1.com",
77 values: [{ key: "alpn", value: ["h3-29"] }],
87 name: "test.bar_2.com",
89 { key: "alpn", value: ["h2"] },
90 { key: "echconfig", value: "456..." },
97 let { inRecord } = await new TRRDNSListener("test.bar.com", {
98 type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC,
101 checkResult(inRecord, false, false, {
103 expectedName: "test.bar_1.com",
104 expectedAlpn: "h3-29",
106 checkResult(inRecord, false, true, {
108 expectedName: "test.bar_2.com",
111 checkResult(inRecord, true, false, {
113 expectedName: "test.bar_1.com",
114 expectedAlpn: "h3-29",
116 checkResult(inRecord, true, true);
118 Services.prefs.setBoolPref("network.dns.echconfig.enabled", true);
119 Services.dns.clearCache(true);
121 ({ inRecord } = await new TRRDNSListener("test.bar.com", {
122 type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC,
125 checkResult(inRecord, false, false, {
127 expectedName: "test.bar_2.com",
130 checkResult(inRecord, false, true, {
132 expectedName: "test.bar_2.com",
135 checkResult(inRecord, true, false, {
137 expectedName: "test.bar_1.com",
138 expectedAlpn: "h3-29",
140 checkResult(inRecord, true, true);
142 await trrServer.stop();
146 // Test configuration:
147 // There are two records: both have echConfigs, and only one supports h3.
148 // This test is about testing which record should we get when
149 // network.dns.http3_echconfig.enabled is true and false.
150 // When network.dns.http3_echconfig.enabled is false, we should try to
151 // connect with h2 and echConfig.
152 add_task(async function testTwoRecordsHaveEchConfig() {
153 Services.dns.clearCache(true);
155 trrServer = new TRRServer();
156 await trrServer.start();
158 Services.prefs.setBoolPref("network.dns.echconfig.enabled", true);
159 Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", false);
160 Services.prefs.setIntPref("network.trr.mode", 3);
161 Services.prefs.setCharPref(
163 `https://foo.example.com:${trrServer.port()}/dns-query`
166 await trrServer.registerDoHAnswers("test.foo.com", "HTTPS", {
169 name: "test.foo.com",
175 name: "test.foo_h3.com",
177 { key: "alpn", value: ["h3"] },
178 { key: "echconfig", value: "456..." },
183 name: "test.foo.com",
189 name: "test.foo_h2.com",
191 { key: "alpn", value: ["h2"] },
192 { key: "echconfig", value: "456..." },
199 let { inRecord } = await new TRRDNSListener("test.foo.com", {
200 type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC,
203 checkResult(inRecord, false, false, {
205 expectedName: "test.foo_h2.com",
208 checkResult(inRecord, false, true, {
210 expectedName: "test.foo_h2.com",
213 checkResult(inRecord, true, false, {
215 expectedName: "test.foo_h3.com",
218 checkResult(inRecord, true, true);
220 Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", true);
221 Services.dns.clearCache(true);
222 ({ inRecord } = await new TRRDNSListener("test.foo.com", {
223 type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC,
226 checkResult(inRecord, false, false, {
228 expectedName: "test.foo_h3.com",
231 checkResult(inRecord, false, true, {
233 expectedName: "test.foo_h2.com",
236 checkResult(inRecord, true, false, {
238 expectedName: "test.foo_h3.com",
241 checkResult(inRecord, true, true);
243 await trrServer.stop();
247 // Test configuration:
248 // There are two records: both have echConfigs, and one supports h3 and h2.
249 // When network.dns.http3_echconfig.enabled is false, we should use the record
250 // that supports h3 and h2 (the alpn is h2).
251 add_task(async function testTwoRecordsHaveEchConfig1() {
252 Services.dns.clearCache(true);
254 trrServer = new TRRServer();
255 await trrServer.start();
257 Services.prefs.setBoolPref("network.dns.echconfig.enabled", true);
258 Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", false);
259 Services.prefs.setIntPref("network.trr.mode", 3);
260 Services.prefs.setCharPref(
262 `https://foo.example.com:${trrServer.port()}/dns-query`
265 await trrServer.registerDoHAnswers("test.foo.com", "HTTPS", {
268 name: "test.foo.com",
274 name: "test.foo_h3.com",
276 { key: "alpn", value: ["h3", "h2"] },
277 { key: "echconfig", value: "456..." },
282 name: "test.foo.com",
288 name: "test.foo_h2.com",
290 { key: "alpn", value: ["h2", "http/1.1"] },
291 { key: "echconfig", value: "456..." },
298 let { inRecord } = await new TRRDNSListener("test.foo.com", {
299 type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC,
302 checkResult(inRecord, false, false, {
304 expectedName: "test.foo_h3.com",
307 checkResult(inRecord, false, true, {
309 expectedName: "test.foo_h3.com",
312 checkResult(inRecord, true, false, {
314 expectedName: "test.foo_h2.com",
315 expectedAlpn: "http/1.1",
317 checkResult(inRecord, true, true, {
319 expectedName: "test.foo_h2.com",
320 expectedAlpn: "http/1.1",
323 Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", true);
324 Services.dns.clearCache(true);
325 ({ inRecord } = await new TRRDNSListener("test.foo.com", {
326 type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC,
329 checkResult(inRecord, false, false, {
331 expectedName: "test.foo_h3.com",
334 checkResult(inRecord, false, true, {
336 expectedName: "test.foo_h3.com",
339 checkResult(inRecord, true, false, {
341 expectedName: "test.foo_h3.com",
344 checkResult(inRecord, true, true, {
346 expectedName: "test.foo_h2.com",
347 expectedAlpn: "http/1.1",
350 await trrServer.stop();
354 // Test configuration:
355 // There are two records: only one support h3 and only one has echConfig.
356 // This test is about never usng the record without echConfig.
357 add_task(async function testOneRecordsHasEchConfig() {
358 Services.dns.clearCache(true);
360 trrServer = new TRRServer();
361 await trrServer.start();
363 Services.prefs.setBoolPref("network.dns.echconfig.enabled", true);
364 Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", false);
365 Services.prefs.setIntPref("network.trr.mode", 3);
366 Services.prefs.setCharPref(
368 `https://foo.example.com:${trrServer.port()}/dns-query`
371 await trrServer.registerDoHAnswers("test.foo.com", "HTTPS", {
374 name: "test.foo.com",
380 name: "test.foo_h3.com",
382 { key: "alpn", value: ["h3"] },
383 { key: "echconfig", value: "456..." },
388 name: "test.foo.com",
394 name: "test.foo_h2.com",
395 values: [{ key: "alpn", value: ["h2"] }],
401 let { inRecord } = await new TRRDNSListener("test.foo.com", {
402 type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC,
405 checkResult(inRecord, false, false, {
407 expectedName: "test.foo_h3.com",
410 checkResult(inRecord, false, true, {
412 expectedName: "test.foo_h2.com",
415 checkResult(inRecord, true, false, {
417 expectedName: "test.foo_h3.com",
420 checkResult(inRecord, true, true);
422 Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", true);
423 Services.dns.clearCache(true);
424 ({ inRecord } = await new TRRDNSListener("test.foo.com", {
425 type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC,
428 checkResult(inRecord, false, false, {
430 expectedName: "test.foo_h3.com",
433 checkResult(inRecord, false, true, {
435 expectedName: "test.foo_h2.com",
438 checkResult(inRecord, true, false, {
440 expectedName: "test.foo_h3.com",
443 checkResult(inRecord, true, true);
445 await trrServer.stop();
449 // Test the case that "network.http.http3.enable" and
450 // "network.http.http2.enabled" are true/false.
451 add_task(async function testHttp3AndHttp2Pref() {
452 Services.dns.clearCache(true);
454 trrServer = new TRRServer();
455 await trrServer.start();
457 Services.prefs.setBoolPref("network.http.http3.enable", false);
458 Services.prefs.setBoolPref("network.dns.echconfig.enabled", false);
459 Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", false);
460 Services.prefs.setIntPref("network.trr.mode", 3);
461 Services.prefs.setCharPref(
463 `https://foo.example.com:${trrServer.port()}/dns-query`
466 await trrServer.registerDoHAnswers("test.foo.com", "HTTPS", {
469 name: "test.foo.com",
475 name: "test.foo_h3.com",
477 { key: "alpn", value: ["h3", "h2"] },
478 { key: "echconfig", value: "456..." },
483 name: "test.foo.com",
489 name: "test.foo_h2.com",
491 { key: "alpn", value: ["h2"] },
492 { key: "echconfig", value: "456..." },
499 let { inRecord } = await new TRRDNSListener("test.foo.com", {
500 type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC,
503 checkResult(inRecord, false, false, {
505 expectedName: "test.foo_h3.com",
508 checkResult(inRecord, false, true, {
510 expectedName: "test.foo_h3.com",
513 checkResult(inRecord, true, false);
514 checkResult(inRecord, true, true);
516 Services.prefs.setBoolPref("network.http.http2.enabled", false);
517 checkResult(inRecord, false, false);
519 Services.prefs.setBoolPref("network.http.http3.enable", true);
520 checkResult(inRecord, false, false, {
522 expectedName: "test.foo_h3.com",
525 checkResult(inRecord, false, true);
526 checkResult(inRecord, true, false, {
528 expectedName: "test.foo_h3.com",
531 checkResult(inRecord, true, true);
533 await trrServer.stop();