netwerk/test/unit/test_dns_proxy_bypass.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 var ioService = Cc["@mozilla.org/network/io-service;1"].
michael@0 6 getService(Ci.nsIIOService);
michael@0 7
michael@0 8 var prefs = Cc["@mozilla.org/preferences-service;1"].
michael@0 9 getService(Ci.nsIPrefBranch);
michael@0 10
michael@0 11 var url = "ws://dnsleak.example.com";
michael@0 12
michael@0 13 var dnsRequestObserver = {
michael@0 14 register: function() {
michael@0 15 this.obs = Cc["@mozilla.org/observer-service;1"].
michael@0 16 getService(Ci.nsIObserverService);
michael@0 17 this.obs.addObserver(this, "dns-resolution-request", false);
michael@0 18 },
michael@0 19
michael@0 20 unregister: function() {
michael@0 21 if (this.obs) {
michael@0 22 this.obs.removeObserver(this, "dns-resolution-request");
michael@0 23 }
michael@0 24 },
michael@0 25
michael@0 26 observe: function(subject, topic, data) {
michael@0 27 if (topic == "dns-resolution-request") {
michael@0 28 do_print(data);
michael@0 29 if (data.indexOf("dnsleak.example.com") > -1) {
michael@0 30 try {
michael@0 31 do_check_true(false);
michael@0 32 } catch (e) {}
michael@0 33 }
michael@0 34 }
michael@0 35 }
michael@0 36 };
michael@0 37
michael@0 38 var listener = {
michael@0 39 onAcknowledge: function(aContext, aSize) {},
michael@0 40 onBinaryMessageAvailable: function(aContext, aMsg) {},
michael@0 41 onMessageAvailable: function(aContext, aMsg) {},
michael@0 42 onServerClose: function(aContext, aCode, aReason) {},
michael@0 43 onStart: function(aContext) {},
michael@0 44 onStop: function(aContext, aStatusCode) {
michael@0 45 prefs.clearUserPref("network.proxy.socks");
michael@0 46 prefs.clearUserPref("network.proxy.socks_port");
michael@0 47 prefs.clearUserPref("network.proxy.type");
michael@0 48 prefs.clearUserPref("network.proxy.socks_remote_dns");
michael@0 49 prefs.clearUserPref("network.dns.notifyResolution");
michael@0 50 dnsRequestObserver.unregister();
michael@0 51 do_test_finished();
michael@0 52 }
michael@0 53 };
michael@0 54
michael@0 55 function run_test() {
michael@0 56 dnsRequestObserver.register();
michael@0 57 prefs.setBoolPref("network.dns.notifyResolution", true);
michael@0 58 prefs.setCharPref("network.proxy.socks", "127.0.0.1");
michael@0 59 prefs.setIntPref("network.proxy.socks_port", 9000);
michael@0 60 prefs.setIntPref("network.proxy.type", 1);
michael@0 61 prefs.setBoolPref("network.proxy.socks_remote_dns", true);
michael@0 62 var chan = Cc["@mozilla.org/network/protocol;1?name=ws"].
michael@0 63 createInstance(Components.interfaces.nsIWebSocketChannel);
michael@0 64 var uri = ioService.newURI(url, null, null);
michael@0 65 chan.asyncOpen(uri, url, listener, null);
michael@0 66 do_test_pending();
michael@0 67 }
michael@0 68

mercurial