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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
/* 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";
let trrServer;
function makeChan(url) {
let chan = NetUtil.newChannel({
uri: url,
loadUsingSystemPrincipal: true,
}).QueryInterface(Ci.nsIHttpChannel);
return chan;
}
function channelOpenPromise(chan) {
return new Promise(resolve => {
function finish(req, buffer) {
resolve([req, buffer]);
}
chan.asyncOpen(new ChannelListener(finish));
});
}
add_setup(async function setup() {
trr_test_setup();
registerCleanupFunction(async () => {
trr_clear_prefs();
});
trrServer = new TRRServer();
registerCleanupFunction(async () => {
await trrServer.stop();
});
await trrServer.start();
dump(`port = ${trrServer.port()}\n`);
let chan = makeChan(`https://localhost:${trrServer.port()}/test?bla=some`);
let [, resp] = await channelOpenPromise(chan);
equal(resp, "<h1> 404 Path not found: /test</h1>");
Services.dns.clearCache(true);
Services.prefs.setIntPref("network.trr.mode", 3);
Services.prefs.setCharPref(
"network.trr.uri",
`https://foo.example.com:${trrServer.port()}/dns-query`
);
});
add_task(async function test_follow_cnames_same_response() {
await trrServer.registerDoHAnswers("something.foo", "A", {
answers: [
{
name: "something.foo",
ttl: 55,
type: "CNAME",
flush: false,
data: "other.foo",
},
{
name: "other.foo",
ttl: 55,
type: "CNAME",
flush: false,
data: "bla.foo",
},
{
name: "bla.foo",
ttl: 55,
type: "CNAME",
flush: false,
data: "xyz.foo",
},
{
name: "xyz.foo",
ttl: 55,
type: "A",
flush: false,
data: "1.2.3.4",
},
],
});
let { inRecord } = await new TRRDNSListener("something.foo", {
expectedAnswer: "1.2.3.4",
flags: Ci.nsIDNSService.RESOLVE_CANONICAL_NAME,
});
equal(inRecord.QueryInterface(Ci.nsIDNSAddrRecord).canonicalName, "xyz.foo");
await trrServer.registerDoHAnswers("a.foo", "A", {
answers: [
{
name: "a.foo",
ttl: 55,
type: "CNAME",
flush: false,
data: "b.foo",
},
],
});
await trrServer.registerDoHAnswers("b.foo", "A", {
answers: [
{
name: "b.foo",
ttl: 55,
type: "A",
flush: false,
data: "2.3.4.5",
},
],
});
await new TRRDNSListener("a.foo", { expectedAnswer: "2.3.4.5" });
});
add_task(async function test_cname_nodata() {
// Test that we don't needlessly follow cname chains when the RA flag is set
// on the response.
await trrServer.registerDoHAnswers("first.foo", "A", {
flags: 0x80,
answers: [
{
name: "first.foo",
ttl: 55,
type: "CNAME",
flush: false,
data: "second.foo",
},
{
name: "second.foo",
ttl: 55,
type: "A",
flush: false,
data: "1.2.3.4",
},
],
});
await trrServer.registerDoHAnswers("first.foo", "AAAA", {
flags: 0x80,
answers: [
{
name: "first.foo",
ttl: 55,
type: "CNAME",
flush: false,
data: "second.foo",
},
],
});
await new TRRDNSListener("first.foo", { expectedAnswer: "1.2.3.4" });
equal(await trrServer.requestCount("first.foo", "A"), 1);
equal(await trrServer.requestCount("first.foo", "AAAA"), 1);
equal(await trrServer.requestCount("second.foo", "A"), 0);
equal(await trrServer.requestCount("second.foo", "AAAA"), 0);
await trrServer.registerDoHAnswers("first.bar", "A", {
answers: [
{
name: "first.bar",
ttl: 55,
type: "CNAME",
flush: false,
data: "second.bar",
},
{
name: "second.bar",
ttl: 55,
type: "A",
flush: false,
data: "1.2.3.4",
},
],
});
await trrServer.registerDoHAnswers("first.bar", "AAAA", {
answers: [
{
name: "first.bar",
ttl: 55,
type: "CNAME",
flush: false,
data: "second.bar",
},
],
});
await new TRRDNSListener("first.bar", { expectedAnswer: "1.2.3.4" });
equal(await trrServer.requestCount("first.bar", "A"), 1);
equal(await trrServer.requestCount("first.bar", "AAAA"), 1);
equal(await trrServer.requestCount("second.bar", "A"), 0); // addr included in first response
equal(await trrServer.requestCount("second.bar", "AAAA"), 1); // will follow cname because no flag is set
// Check that it also works for HTTPS records
await trrServer.registerDoHAnswers("first.bar", "HTTPS", {
flags: 0x80,
answers: [
{
name: "second.bar",
ttl: 55,
type: "HTTPS",
flush: false,
data: {
priority: 1,
name: "h3pool",
values: [
{ key: "alpn", value: ["h2", "h3"] },
{ key: "no-default-alpn" },
{ key: "port", value: 8888 },
{ key: "ipv4hint", value: "1.2.3.4" },
{ key: "echconfig", value: "123..." },
{ key: "ipv6hint", value: "::1" },
],
},
},
{
name: "first.bar",
ttl: 55,
type: "CNAME",
flush: false,
data: "second.bar",
},
],
});
let { inStatus } = await new TRRDNSListener("first.bar", {
type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC,
});
Assert.ok(Components.isSuccessCode(inStatus), `${inStatus} should work`);
equal(await trrServer.requestCount("first.bar", "HTTPS"), 1);
equal(await trrServer.requestCount("second.bar", "HTTPS"), 0);
});
|