1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/unit/test_dns_proxy_bypass.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,68 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +var ioService = Cc["@mozilla.org/network/io-service;1"]. 1.9 + getService(Ci.nsIIOService); 1.10 + 1.11 +var prefs = Cc["@mozilla.org/preferences-service;1"]. 1.12 + getService(Ci.nsIPrefBranch); 1.13 + 1.14 +var url = "ws://dnsleak.example.com"; 1.15 + 1.16 +var dnsRequestObserver = { 1.17 + register: function() { 1.18 + this.obs = Cc["@mozilla.org/observer-service;1"]. 1.19 + getService(Ci.nsIObserverService); 1.20 + this.obs.addObserver(this, "dns-resolution-request", false); 1.21 + }, 1.22 + 1.23 + unregister: function() { 1.24 + if (this.obs) { 1.25 + this.obs.removeObserver(this, "dns-resolution-request"); 1.26 + } 1.27 + }, 1.28 + 1.29 + observe: function(subject, topic, data) { 1.30 + if (topic == "dns-resolution-request") { 1.31 + do_print(data); 1.32 + if (data.indexOf("dnsleak.example.com") > -1) { 1.33 + try { 1.34 + do_check_true(false); 1.35 + } catch (e) {} 1.36 + } 1.37 + } 1.38 + } 1.39 +}; 1.40 + 1.41 +var listener = { 1.42 + onAcknowledge: function(aContext, aSize) {}, 1.43 + onBinaryMessageAvailable: function(aContext, aMsg) {}, 1.44 + onMessageAvailable: function(aContext, aMsg) {}, 1.45 + onServerClose: function(aContext, aCode, aReason) {}, 1.46 + onStart: function(aContext) {}, 1.47 + onStop: function(aContext, aStatusCode) { 1.48 + prefs.clearUserPref("network.proxy.socks"); 1.49 + prefs.clearUserPref("network.proxy.socks_port"); 1.50 + prefs.clearUserPref("network.proxy.type"); 1.51 + prefs.clearUserPref("network.proxy.socks_remote_dns"); 1.52 + prefs.clearUserPref("network.dns.notifyResolution"); 1.53 + dnsRequestObserver.unregister(); 1.54 + do_test_finished(); 1.55 + } 1.56 +}; 1.57 + 1.58 +function run_test() { 1.59 + dnsRequestObserver.register(); 1.60 + prefs.setBoolPref("network.dns.notifyResolution", true); 1.61 + prefs.setCharPref("network.proxy.socks", "127.0.0.1"); 1.62 + prefs.setIntPref("network.proxy.socks_port", 9000); 1.63 + prefs.setIntPref("network.proxy.type", 1); 1.64 + prefs.setBoolPref("network.proxy.socks_remote_dns", true); 1.65 + var chan = Cc["@mozilla.org/network/protocol;1?name=ws"]. 1.66 + createInstance(Components.interfaces.nsIWebSocketChannel); 1.67 + var uri = ioService.newURI(url, null, null); 1.68 + chan.asyncOpen(uri, url, listener, null); 1.69 + do_test_pending(); 1.70 +} 1.71 +