summaryrefslogtreecommitdiffstats
path: root/netwerk/test/unit/test_trr_domain.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:44:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:44:51 +0000
commit9e3c08db40b8916968b9f30096c7be3f00ce9647 (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /netwerk/test/unit/test_trr_domain.js
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/unit/test_trr_domain.js')
-rw-r--r--netwerk/test/unit/test_trr_domain.js123
1 files changed, 123 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_trr_domain.js b/netwerk/test/unit/test_trr_domain.js
new file mode 100644
index 0000000000..f154060706
--- /dev/null
+++ b/netwerk/test/unit/test_trr_domain.js
@@ -0,0 +1,123 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+// This test simmulates intermittent native DNS functionality.
+// We verify that we don't use the negative DNS record for the DoH server.
+// The first resolve of foo.example.com fails, so we expect TRR not to work.
+// Immediately after the native DNS starts working, it should connect to the
+// TRR server and start working.
+
+const override = Cc["@mozilla.org/network/native-dns-override;1"].getService(
+ Ci.nsINativeDNSResolverOverride
+);
+
+function setup() {
+ trr_test_setup();
+ Services.prefs.clearUserPref("network.trr.bootstrapAddr");
+ Services.prefs.clearUserPref("network.dns.native-is-localhost");
+}
+setup();
+
+registerCleanupFunction(async () => {
+ trr_clear_prefs();
+ override.clearOverrides();
+});
+
+add_task(async function intermittent_dns_mode3() {
+ override.addIPOverride("foo.example.com", "N/A");
+ let trrServer = new TRRServer();
+ registerCleanupFunction(async () => {
+ await trrServer.stop();
+ });
+ await trrServer.start();
+ info(`port = ${trrServer.port}\n`);
+ Services.dns.clearCache(true);
+ Services.prefs.setCharPref(
+ "network.trr.uri",
+ `https://foo.example.com:${trrServer.port}/dns-query`
+ );
+ Services.prefs.setIntPref("network.trr.mode", Ci.nsIDNSService.MODE_TRRONLY);
+ await trrServer.registerDoHAnswers("example.com", "A", {
+ answers: [
+ {
+ name: "example.com",
+ ttl: 55,
+ type: "A",
+ flush: false,
+ data: "1.2.3.4",
+ },
+ ],
+ });
+ let { inStatus } = await new TRRDNSListener("example.com", {
+ expectedSuccess: false,
+ });
+ equal(inStatus, Cr.NS_ERROR_UNKNOWN_HOST);
+ await trrServer.registerDoHAnswers("example.org", "A", {
+ answers: [
+ {
+ name: "example.org",
+ ttl: 55,
+ type: "A",
+ flush: false,
+ data: "1.2.3.4",
+ },
+ ],
+ });
+ override.addIPOverride("foo.example.com", "127.0.0.1");
+ await new TRRDNSListener("example.org", { expectedAnswer: "1.2.3.4" });
+ await trrServer.stop();
+});
+
+add_task(async function intermittent_dns_mode2() {
+ override.addIPOverride("foo.example.com", "N/A");
+ let trrServer = new TRRServer();
+ registerCleanupFunction(async () => {
+ await trrServer.stop();
+ });
+ await trrServer.start();
+ info(`port = ${trrServer.port}\n`);
+
+ Services.dns.clearCache(true);
+ Services.prefs.setIntPref(
+ "network.trr.mode",
+ Ci.nsIDNSService.MODE_NATIVEONLY
+ );
+ Services.prefs.setCharPref(
+ "network.trr.uri",
+ `https://foo.example.com:${trrServer.port}/dns-query`
+ );
+ Services.prefs.setIntPref("network.trr.mode", Ci.nsIDNSService.MODE_TRRFIRST);
+ await trrServer.registerDoHAnswers("example.com", "A", {
+ answers: [
+ {
+ name: "example.com",
+ ttl: 55,
+ type: "A",
+ flush: false,
+ data: "1.1.1.1",
+ },
+ ],
+ });
+ override.addIPOverride("example.com", "2.2.2.2");
+ await new TRRDNSListener("example.com", {
+ expectedAnswer: "2.2.2.2",
+ });
+ await trrServer.registerDoHAnswers("example.org", "A", {
+ answers: [
+ {
+ name: "example.org",
+ ttl: 55,
+ type: "A",
+ flush: false,
+ data: "1.2.3.4",
+ },
+ ],
+ });
+ override.addIPOverride("example.org", "3.3.3.3");
+ override.addIPOverride("foo.example.com", "127.0.0.1");
+ await new TRRDNSListener("example.org", { expectedAnswer: "1.2.3.4" });
+ await trrServer.stop();
+});