toolkit/devtools/server/tests/unit/test_dbgsocket_connection_drop.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 /**
michael@0 2 * Any copyright is dedicated to the Public Domain.
michael@0 3 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 4 */
michael@0 5
michael@0 6 /**
michael@0 7 * Bug 755412 - checks if the server drops the connection on an improperly
michael@0 8 * framed packet, i.e. when the length header is invalid.
michael@0 9 */
michael@0 10
michael@0 11 Cu.import("resource://gre/modules/devtools/dbg-server.jsm");
michael@0 12 Cu.import("resource://gre/modules/devtools/dbg-client.jsm");
michael@0 13
michael@0 14 let port = 2929;
michael@0 15
michael@0 16 function run_test()
michael@0 17 {
michael@0 18 do_print("Starting test at " + new Date().toTimeString());
michael@0 19 initTestDebuggerServer();
michael@0 20
michael@0 21 add_test(test_socket_conn_drops_after_invalid_header);
michael@0 22 add_test(test_socket_conn_drops_after_invalid_header_2);
michael@0 23 add_test(test_socket_conn_drops_after_too_long_header);
michael@0 24 run_next_test();
michael@0 25 }
michael@0 26
michael@0 27 function test_socket_conn_drops_after_invalid_header() {
michael@0 28 return test_helper('fluff30:27:{"to":"root","type":"echo"}');
michael@0 29 }
michael@0 30
michael@0 31 function test_socket_conn_drops_after_invalid_header_2() {
michael@0 32 return test_helper('27asd:{"to":"root","type":"echo"}');
michael@0 33 }
michael@0 34
michael@0 35 function test_socket_conn_drops_after_too_long_header() {
michael@0 36 return test_helper('4305724038957487634549823475894325');
michael@0 37 }
michael@0 38
michael@0 39
michael@0 40 function test_helper(payload) {
michael@0 41 try_open_listener();
michael@0 42
michael@0 43 let transport = debuggerSocketConnect("127.0.0.1", port);
michael@0 44 transport.hooks = {
michael@0 45 onPacket: function(aPacket) {
michael@0 46 this.onPacket = function(aPacket) {
michael@0 47 do_throw(new Error("This connection should be dropped."));
michael@0 48 transport.close();
michael@0 49 }
michael@0 50
michael@0 51 // Inject the payload directly into the stream.
michael@0 52 transport._outgoing += payload;
michael@0 53 transport._flushOutgoing();
michael@0 54 },
michael@0 55 onClosed: function(aStatus) {
michael@0 56 do_check_true(true);
michael@0 57 run_next_test();
michael@0 58 },
michael@0 59 };
michael@0 60 transport.ready();
michael@0 61 }
michael@0 62
michael@0 63 function try_open_listener()
michael@0 64 {
michael@0 65 try {
michael@0 66 do_check_true(DebuggerServer.openListener(port));
michael@0 67 } catch (e) {
michael@0 68 // In case the port is unavailable, pick a random one between 2000 and 65000.
michael@0 69 port = Math.floor(Math.random() * (65000 - 2000 + 1)) + 2000;
michael@0 70 try_open_listener();
michael@0 71 }
michael@0 72 }

mercurial