toolkit/devtools/server/tests/unit/test_dbgsocket_connection_drop.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial