summaryrefslogtreecommitdiffstats
path: root/netwerk/test/unit/test_trr_domain.js
blob: f1540607066a5a920aec4e6bcf5a95ab1f245b33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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();
});