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/. */
9 const { TestUtils } = ChromeUtils.importESModule(
10 "resource://testing-common/TestUtils.sys.mjs"
13 add_setup(async function setup() {
14 h2Port = Services.env.get("MOZHTTP2_PORT");
15 Assert.notEqual(h2Port, null);
16 Assert.notEqual(h2Port, "");
19 registerCleanupFunction(() => {
23 if (mozinfo.socketprocess_networking) {
24 Services.dns; // Needed to trigger socket process.
25 await TestUtils.waitForCondition(() => Services.io.socketProcessLaunched);
28 Services.prefs.setIntPref("network.trr.mode", Ci.nsIDNSService.MODE_TRRFIRST);
31 let test_answer = "bXkgdm9pY2UgaXMgbXkgcGFzc3dvcmQ=";
32 let test_answer_addr = "127.0.0.1";
34 add_task(async function testTXTResolve() {
35 // use the h2 server as DOH provider
36 Services.prefs.setCharPref(
38 "https://foo.example.com:" + h2Port + "/doh"
41 let { inRecord } = await new TRRDNSListener("_esni.example.com", {
42 type: Ci.nsIDNSService.RESOLVE_TYPE_TXT,
46 .QueryInterface(Ci.nsIDNSTXTRecord)
47 .getRecordsAsOneString();
48 Assert.equal(answer, test_answer, "got correct answer");
51 // verify TXT record pushed on a A record request
52 add_task(async function testTXTRecordPushPart1() {
53 Services.prefs.setCharPref(
55 "https://foo.example.com:" + h2Port + "/txt-dns-push"
57 let { inRecord } = await new TRRDNSListener("_esni_push.example.com", {
58 type: Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
59 expectedAnswer: "127.0.0.1",
62 inRecord.QueryInterface(Ci.nsIDNSAddrRecord);
63 let answer = inRecord.getNextAddrAsString();
64 Assert.equal(answer, test_answer_addr, "got correct answer");
67 // verify the TXT pushed record
68 add_task(async function testTXTRecordPushPart2() {
69 // At this point the second host name should've been pushed and we can resolve it using
70 // cache only. Set back the URI to a path that fails.
71 Services.prefs.setCharPref(
73 "https://foo.example.com:" + h2Port + "/404"
75 let { inRecord } = await new TRRDNSListener("_esni_push.example.com", {
76 type: Ci.nsIDNSService.RESOLVE_TYPE_TXT,
80 .QueryInterface(Ci.nsIDNSTXTRecord)
81 .getRecordsAsOneString();
82 Assert.equal(answer, test_answer, "got correct answer");