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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
/* 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/. */
/*
* Most of tests in this file are reused from test_trr.js, except tests listed
* below. Since ODoH doesn't support push and customerized DNS resolver, some
* related tests are skipped.
*
* test_trr_flags
* test_push
* test_clearCacheOnURIChange // TODO: Clear DNS cache when ODoH prefs changed.
* test_dnsSuffix
* test_async_resolve_with_trr_server
* test_content_encoding_gzip
* test_redirect
* test_confirmation
* test_detected_uri
* test_pref_changes
* test_dohrollout_mode
* test_purge_trr_cache_on_mode_change
* test_old_bootstrap_pref
*/
"use strict";
/* import-globals-from trr_common.js */
ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
const certOverrideService = Cc[
"@mozilla.org/security/certoverride;1"
].getService(Ci.nsICertOverrideService);
add_setup(async function setup() {
h2Port = trr_test_setup();
runningODoHTests = true;
// This is for skiping the security check for the odoh host.
certOverrideService.setDisableAllSecurityChecksAndLetAttackersInterceptMyData(
true
);
registerCleanupFunction(() => {
trr_clear_prefs();
Services.prefs.clearUserPref("network.trr.odoh.enabled");
Services.prefs.clearUserPref("network.trr.odoh.target_path");
Services.prefs.clearUserPref("network.trr.odoh.configs_uri");
certOverrideService.setDisableAllSecurityChecksAndLetAttackersInterceptMyData(
false
);
});
if (mozinfo.socketprocess_networking) {
Services.dns; // Needed to trigger socket process.
await TestUtils.waitForCondition(() => Services.io.socketProcessLaunched);
}
Services.prefs.setIntPref("network.trr.mode", Ci.nsIDNSService.MODE_TRRONLY);
});
add_task(async function testODoHConfig() {
// use the h2 server as DOH provider
Services.prefs.setCharPref(
"network.trr.uri",
"https://foo.example.com:" + h2Port + "/odohconfig"
);
let { inRecord } = await new TRRDNSListener("odoh_host.example.com", {
type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC,
});
let answer = inRecord.QueryInterface(Ci.nsIDNSHTTPSSVCRecord).records;
Assert.equal(answer[0].priority, 1);
Assert.equal(answer[0].name, "odoh_host.example.com");
Assert.equal(answer[0].values.length, 1);
let odohconfig = answer[0].values[0].QueryInterface(Ci.nsISVCParamODoHConfig)
.ODoHConfig;
Assert.equal(odohconfig.length, 46);
});
let testIndex = 0;
async function ODoHConfigTest(query, ODoHHost, expectedResult = false) {
Services.prefs.setCharPref(
"network.trr.uri",
"https://foo.example.com:" + h2Port + "/odohconfig?" + query
);
// Setting the pref "network.trr.odoh.target_host" will trigger the reload of
// the ODoHConfigs.
if (ODoHHost != undefined) {
Services.prefs.setCharPref("network.trr.odoh.target_host", ODoHHost);
} else {
Services.prefs.setCharPref(
"network.trr.odoh.target_host",
`https://odoh_host_${testIndex++}.com`
);
}
await topicObserved("odoh-service-activated");
Assert.equal(Services.dns.ODoHActivated, expectedResult);
}
add_task(async function testODoHConfig1() {
await ODoHConfigTest("invalid=empty");
});
add_task(async function testODoHConfig2() {
await ODoHConfigTest("invalid=version");
});
add_task(async function testODoHConfig3() {
await ODoHConfigTest("invalid=configLength");
});
add_task(async function testODoHConfig4() {
await ODoHConfigTest("invalid=totalLength");
});
add_task(async function testODoHConfig5() {
await ODoHConfigTest("invalid=kemId");
});
add_task(async function testODoHConfig6() {
// Use a very short TTL.
Services.prefs.setIntPref("network.trr.odoh.min_ttl", 1);
await ODoHConfigTest("invalid=kemId&ttl=1");
// This is triggered by the expiration of the TTL.
await topicObserved("odoh-service-activated");
Assert.ok(!Services.dns.ODoHActivated);
Services.prefs.clearUserPref("network.trr.odoh.min_ttl");
});
add_task(async function testODoHConfig7() {
Services.dns.clearCache(true);
Services.prefs.setIntPref("network.trr.mode", 2); // TRR-first
Services.prefs.setBoolPref("network.trr.odoh.enabled", true);
// At this point, we've queried the ODoHConfig, but there is no usable config
// (kemId is not supported). So, we should see the DNS result is from the
// native resolver.
await new TRRDNSListener("bar.example.com", "127.0.0.1");
});
async function ODoHConfigTestHTTP(configUri, expectedResult) {
// Setting the pref "network.trr.odoh.configs_uri" will trigger the reload of
// the ODoHConfigs.
Services.prefs.setCharPref("network.trr.odoh.configs_uri", configUri);
await topicObserved("odoh-service-activated");
Assert.equal(Services.dns.ODoHActivated, expectedResult);
}
add_task(async function testODoHConfig8() {
Services.dns.clearCache(true);
Services.prefs.setCharPref("network.trr.uri", "");
await ODoHConfigTestHTTP(
`https://foo.example.com:${h2Port}/odohconfig?downloadFrom=http`,
true
);
});
add_task(async function testODoHConfig9() {
// Reset the prefs back to the correct values, so we will get valid
// ODoHConfigs when "network.trr.odoh.configs_uri" is cleared below.
Services.prefs.setCharPref(
"network.trr.uri",
`https://foo.example.com:${h2Port}/odohconfig`
);
Services.prefs.setCharPref(
"network.trr.odoh.target_host",
`https://odoh_host.example.com:${h2Port}`
);
// Use a very short TTL.
Services.prefs.setIntPref("network.trr.odoh.min_ttl", 1);
// This will trigger to download ODoHConfigs from HTTPS RR.
Services.prefs.clearUserPref("network.trr.odoh.configs_uri");
await topicObserved("odoh-service-activated");
Assert.ok(Services.dns.ODoHActivated);
await ODoHConfigTestHTTP(
`https://foo.example.com:${h2Port}/odohconfig?downloadFrom=http`,
true
);
// This is triggered by the expiration of the TTL.
await topicObserved("odoh-service-activated");
Assert.ok(Services.dns.ODoHActivated);
Services.prefs.clearUserPref("network.trr.odoh.min_ttl");
});
add_task(async function testODoHConfig10() {
// We can still get ODoHConfigs from HTTPS RR.
await ODoHConfigTestHTTP("http://invalid_odoh_config.com", true);
});
add_task(async function ensureODoHConfig() {
Services.prefs.setBoolPref("network.trr.odoh.enabled", true);
// Make sure we can connect to ODOH target successfully.
Services.prefs.setCharPref(
"network.dns.localDomains",
"odoh_host.example.com"
);
// Make sure we have an usable ODoHConfig to use.
await ODoHConfigTestHTTP(
`https://foo.example.com:${h2Port}/odohconfig?downloadFrom=http`,
true
);
});
add_task(test_A_record);
add_task(test_AAAA_records);
add_task(test_RFC1918);
add_task(test_GET_ECS);
add_task(test_timeout_mode3);
add_task(test_strict_native_fallback);
add_task(test_no_answers_fallback);
add_task(test_404_fallback);
add_task(test_mode_1_and_4);
add_task(test_CNAME);
add_task(test_name_mismatch);
add_task(test_mode_2);
add_task(test_excluded_domains);
add_task(test_captiveportal_canonicalURL);
add_task(test_parentalcontrols);
// TRR-first check that DNS result is used if domain is part of the builtin-excluded-domains pref
add_task(test_builtin_excluded_domains);
add_task(test_excluded_domains_mode3);
add_task(test25e);
add_task(test_parentalcontrols_mode3);
add_task(test_builtin_excluded_domains_mode3);
add_task(count_cookies);
add_task(test_connection_closed);
add_task(test_fetch_time);
add_task(test_fqdn);
add_task(test_ipv6_trr_fallback);
add_task(test_ipv4_trr_fallback);
add_task(test_no_retry_without_doh);
add_task(test_connection_reuse_and_cycling).skip(); // Bug 1742743
add_task(async function testODoHConfigNotAvailableInMode3() {
Services.dns.clearCache(true);
Services.prefs.setIntPref("network.trr.mode", 3);
Services.prefs.setCharPref("network.trr.uri", "");
await ODoHConfigTestHTTP("https://failed_odoh_config.com", false);
// In mode 3, the DNS lookup should fail.
let { inStatus } = await new TRRDNSListener("test.example.com", {
expectedSuccess: false,
});
Assert.equal(inStatus, Cr.NS_ERROR_UNKNOWN_HOST);
});
add_task(async function testODoHConfigNotAvailableInMode2() {
Services.dns.clearCache(true);
Services.prefs.setIntPref("network.trr.mode", 2);
Services.prefs.setCharPref("network.trr.uri", "");
await ODoHConfigTestHTTP("https://failed_odoh_config_1.com", false);
// In mode 2, we fallback to native.
await new TRRDNSListener("test.example.com", "127.0.0.1");
});
|