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 var prefs
= Services
.prefs
;
10 prefs
.setBoolPref("network.dns.notifyResolution", true);
11 prefs
.setCharPref("network.proxy.socks", "127.0.0.1");
12 prefs
.setIntPref("network.proxy.socks_port", 9000);
13 prefs
.setIntPref("network.proxy.type", 1);
17 registerCleanupFunction(async () => {
18 prefs
.clearUserPref("network.proxy.socks");
19 prefs
.clearUserPref("network.proxy.socks_port");
20 prefs
.clearUserPref("network.proxy.type");
21 prefs
.clearUserPref("network.dns.notifyResolution");
24 var url
= "ws://dnsleak.example.com";
26 var dnsRequestObserver
= {
28 this.obs
= Services
.obs
;
29 this.obs
.addObserver(this, "dns-resolution-request");
34 this.obs
.removeObserver(this, "dns-resolution-request");
38 observe(subject
, topic
, data
) {
39 if (topic
== "dns-resolution-request") {
40 Assert
.ok(!data
.includes("dnsleak.example.com"), `no dnsleak: ${data}`);
45 function WSListener(closure
) {
46 this._closure
= closure
;
48 WSListener
.prototype = {
50 onBinaryMessageAvailable() {},
51 onMessageAvailable() {},
55 dnsRequestObserver
.unregister();
60 add_task(async
function test_dns_websocket_channel() {
61 dnsRequestObserver
.register();
63 var chan
= Cc
["@mozilla.org/network/protocol;1?name=ws"].createInstance(
64 Ci
.nsIWebSocketChannel
67 var uri
= Services
.io
.newURI(url
);
70 Services
.scriptSecurityManager
.createContentPrincipal(uri
, {}),
71 null, // aTriggeringPrincipal
72 Ci
.nsILoadInfo
.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL
,
73 Ci
.nsIContentPolicy
.TYPE_WEBSOCKET
76 await
new Promise(resolve
=>
77 chan
.asyncOpen(uri
, url
, {}, 0, new WSListener(resolve
), null)
81 add_task(async
function test_dns_resolve_proxy() {
82 dnsRequestObserver
.register();
84 let { error
} = await
new TRRDNSListener("dnsleak.example.com", {
85 expectEarlyFail
: true,
89 Cr
.NS_ERROR_UNKNOWN_PROXY_HOST
,
90 "error is NS_ERROR_UNKNOWN_PROXY_HOST"
92 dnsRequestObserver
.unregister();