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/. */
7 const override = Cc["@mozilla.org/network/native-dns-override;1"].getService(
8 Ci.nsINativeDNSResolverOverride
12 registerCleanupFunction(async () => {
13 Services.prefs.clearUserPref("network.connectivity-service.nat64-prefix");
14 override.clearOverrides();
19 * Waits for an observer notification to fire.
21 * @param {String} topic The notification topic.
22 * @returns {Promise} A promise that fulfills when the notification is fired.
24 function promiseObserverNotification(topic, matchFunc) {
25 return new Promise((resolve, reject) => {
26 Services.obs.addObserver(function observe(subject, topic, data) {
27 let matches = typeof matchFunc != "function" || matchFunc(subject, data);
31 Services.obs.removeObserver(observe, topic);
32 resolve({ subject, data });
37 function makeChan(url) {
38 let chan = NetUtil.newChannel({
40 loadUsingSystemPrincipal: true,
41 }).QueryInterface(Ci.nsIHttpChannel);
45 function channelOpenPromise(chan) {
46 return new Promise(resolve => {
47 function finish(req, buffer) {
48 resolve([req, buffer]);
50 chan.asyncOpen(new ChannelListener(finish));
54 add_task(async function test_add_nat64_prefix_to_trr() {
55 let trrServer = new TRRServer();
56 registerCleanupFunction(async () => {
57 await trrServer.stop();
59 await trrServer.start();
60 dump(`port = ${trrServer.port}\n`);
61 let chan = makeChan(`https://localhost:${trrServer.port}/test?bla=some`);
62 let [, resp] = await channelOpenPromise(chan);
63 equal(resp, "<h1> 404 Path not found: /test?bla=some</h1>");
64 Services.dns.clearCache(true);
65 override.addIPOverride("ipv4only.arpa", "fe80::9b2b:c000:00aa");
66 Services.prefs.setCharPref(
67 "network.connectivity-service.nat64-prefix",
68 "ae80::3b1b:c343:1133"
71 let topic = "network:connectivity-service:dns-checks-complete";
72 if (mozinfo.socketprocess_networking) {
73 topic += "-from-socket-process";
75 let notification = promiseObserverNotification(topic);
76 Services.obs.notifyObservers(null, "network:captive-portal-connectivity");
79 Services.prefs.setIntPref("network.trr.mode", 2);
80 Services.prefs.setCharPref(
82 `https://foo.example.com:${trrServer.port}/dns-query`
85 await trrServer.registerDoHAnswers("xyz.foo", "A", {
96 let { inRecord } = await new TRRDNSListener("xyz.foo", {
97 expectedSuccess: false,
100 inRecord.QueryInterface(Ci.nsIDNSAddrRecord);
102 inRecord.getNextAddrAsString(),
104 `Checking that native IPv4 addresses have higher priority.`
108 inRecord.getNextAddrAsString(),
109 "ae80::3b1b:102:304",
110 `Checking the manually entered NAT64-prefixed address is in the middle.`
114 inRecord.getNextAddrAsString(),
115 "fe80::9b2b:102:304",
116 `Checking that the NAT64-prefixed address is appended at the back.`
119 await trrServer.stop();