michael@0: /** michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: /** michael@0: * Bug 755412 - checks if the server drops the connection on an improperly michael@0: * framed packet, i.e. when the length header is invalid. michael@0: */ michael@0: michael@0: Cu.import("resource://gre/modules/devtools/dbg-server.jsm"); michael@0: Cu.import("resource://gre/modules/devtools/dbg-client.jsm"); michael@0: michael@0: let port = 2929; michael@0: michael@0: function run_test() michael@0: { michael@0: do_print("Starting test at " + new Date().toTimeString()); michael@0: initTestDebuggerServer(); michael@0: michael@0: add_test(test_socket_conn_drops_after_invalid_header); michael@0: add_test(test_socket_conn_drops_after_invalid_header_2); michael@0: add_test(test_socket_conn_drops_after_too_long_header); michael@0: run_next_test(); michael@0: } michael@0: michael@0: function test_socket_conn_drops_after_invalid_header() { michael@0: return test_helper('fluff30:27:{"to":"root","type":"echo"}'); michael@0: } michael@0: michael@0: function test_socket_conn_drops_after_invalid_header_2() { michael@0: return test_helper('27asd:{"to":"root","type":"echo"}'); michael@0: } michael@0: michael@0: function test_socket_conn_drops_after_too_long_header() { michael@0: return test_helper('4305724038957487634549823475894325'); michael@0: } michael@0: michael@0: michael@0: function test_helper(payload) { michael@0: try_open_listener(); michael@0: michael@0: let transport = debuggerSocketConnect("127.0.0.1", port); michael@0: transport.hooks = { michael@0: onPacket: function(aPacket) { michael@0: this.onPacket = function(aPacket) { michael@0: do_throw(new Error("This connection should be dropped.")); michael@0: transport.close(); michael@0: } michael@0: michael@0: // Inject the payload directly into the stream. michael@0: transport._outgoing += payload; michael@0: transport._flushOutgoing(); michael@0: }, michael@0: onClosed: function(aStatus) { michael@0: do_check_true(true); michael@0: run_next_test(); michael@0: }, michael@0: }; michael@0: transport.ready(); michael@0: } michael@0: michael@0: function try_open_listener() michael@0: { michael@0: try { michael@0: do_check_true(DebuggerServer.openListener(port)); michael@0: } catch (e) { michael@0: // In case the port is unavailable, pick a random one between 2000 and 65000. michael@0: port = Math.floor(Math.random() * (65000 - 2000 + 1)) + 2000; michael@0: try_open_listener(); michael@0: } michael@0: }