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 const gOverride = Cc["@mozilla.org/network/native-dns-override;1"].getService(
8 Ci.nsINativeDNSResolverOverride
12 registerCleanupFunction(async () => {
17 add_task(async function start_trr_server() {
18 trrServer = new TRRServer();
19 registerCleanupFunction(async () => {
20 await trrServer.stop();
22 await trrServer.start();
23 dump(`port = ${trrServer.port()}\n`);
24 Services.prefs.setBoolPref("network.trr.skip-AAAA-when-not-supported", false);
25 Services.prefs.setCharPref(
27 `https://foo.example.com:${trrServer.port()}/dns-query`
29 Services.prefs.setIntPref("network.trr.mode", Ci.nsIDNSService.MODE_TRRFIRST);
32 add_task(async function unspec_first() {
33 gOverride.clearOverrides();
34 Services.dns.clearCache(true);
36 gOverride.addIPOverride("example.org", "1.1.1.1");
37 gOverride.addIPOverride("example.org", "::1");
39 await trrServer.registerDoHAnswers("example.org", "A", {
50 // This first request gets cached. IPv6 response gets served from the cache
51 await new TRRDNSListener("example.org", { expectedAnswer: "1.2.3.4" });
52 await new TRRDNSListener("example.org", {
53 flags: Ci.nsIDNSService.RESOLVE_DISABLE_IPV6,
54 expectedAnswer: "1.2.3.4",
56 let { inStatus } = await new TRRDNSListener("example.org", {
57 flags: Ci.nsIDNSService.RESOLVE_DISABLE_IPV4,
58 expectedSuccess: false,
60 equal(inStatus, Cr.NS_ERROR_UNKNOWN_HOST);
63 add_task(async function A_then_AAAA_fails() {
64 gOverride.clearOverrides();
65 Services.dns.clearCache(true);
67 gOverride.addIPOverride("example.org", "1.1.1.1");
68 gOverride.addIPOverride("example.org", "::1");
70 await trrServer.registerDoHAnswers("example.org", "A", {
81 // We do individual IPv4/IPv6 requests - we expect IPv6 not to fallback to Do53 because we have an IPv4 record
82 await new TRRDNSListener("example.org", {
83 flags: Ci.nsIDNSService.RESOLVE_DISABLE_IPV6,
84 expectedAnswer: "1.2.3.4",
86 let { inStatus } = await new TRRDNSListener("example.org", {
87 flags: Ci.nsIDNSService.RESOLVE_DISABLE_IPV4,
88 expectedSuccess: false,
90 equal(inStatus, Cr.NS_ERROR_UNKNOWN_HOST);
93 add_task(async function just_AAAA_fails() {
94 gOverride.clearOverrides();
95 Services.dns.clearCache(true);
97 gOverride.addIPOverride("example.org", "1.1.1.1");
98 gOverride.addIPOverride("example.org", "::1");
100 await trrServer.registerDoHAnswers("example.org", "A", {
111 // We only do an IPv6 req - we expect IPv6 not to fallback to Do53 because we have an IPv4 record
112 let { inStatus } = await new TRRDNSListener("example.org", {
113 flags: Ci.nsIDNSService.RESOLVE_DISABLE_IPV4,
114 expectedSuccess: false,
116 equal(inStatus, Cr.NS_ERROR_UNKNOWN_HOST);