2011-07-03 Yuta Kitamura <yutak@chromium.org>
authoryutak@chromium.org <yutak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Jul 2011 05:20:03 +0000 (05:20 +0000)
committeryutak@chromium.org <yutak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Jul 2011 05:20:03 +0000 (05:20 +0000)
        Reviewed by Kent Tamura.

        WebSocket: pywebsocket handlers should raise exception to abort the connection
        https://bugs.webkit.org/show_bug.cgi?id=63794

        pywebsocket automatically sends handshake response when web_socket_do_extra_handshake()
        finishes, and starts closing handshake (sends a close frame and waits for client's response)
        after web_socket_transfer_data() exits. To stop this behavior, a handler must raise an
        exception.

        Some of our handlers send broken handshake in web_socket_do_extra_handshake(). If this handler
        function exits without raising an exception, pywebsocket automatically sends another handshake
        response, which is not really necessary. Normally this extra handshake message is not a problem,
        because the client does not read any data beyond the end of the first (broken) handshake if
        the client is working correctly. However, if the client erroneously accepts the first handshake,
        it will be hard to diagnose the problem because of the extra message. The same can happen for
        web_socket_transfer_data().

        Generally, pywebsocket handlers should raise an exception if they do not want to send any more
        data. However, this fact has been overlooked in past changes, and handlers in many tests exit
        normally where they should raise an exception. This change fix these errors.

        * http/tests/websocket/tests/bad-handshake-crash_wsh.py:
        * http/tests/websocket/tests/frame-length-overflow_wsh.py:
        * http/tests/websocket/tests/handshake-fail-by-maxlength_wsh.py:
        Do not need to cycle until disconnection.
        * http/tests/websocket/tests/handshake-fail-by-no-connection-header_wsh.py:
        * http/tests/websocket/tests/handshake-fail-by-no-cr_wsh.py:
        * http/tests/websocket/tests/handshake-fail-by-no-upgrade-header_wsh.py:
        * http/tests/websocket/tests/long-invalid-header_wsh.py:
        Some ports (Chromium) intercept handshake messages and do not pass server's response
        to WebCore until they find the end of handshake response (i.e. "\r\n\r\n" and 16-byte data).
        If the handler aborts the connection without sending this end-of-response marker, entire
        response is ignored, which causes the test to fail.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@90350 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/websocket/tests/bad-handshake-crash_wsh.py
LayoutTests/http/tests/websocket/tests/frame-length-overflow_wsh.py
LayoutTests/http/tests/websocket/tests/handshake-fail-by-maxlength_wsh.py
LayoutTests/http/tests/websocket/tests/handshake-fail-by-no-connection-header_wsh.py
LayoutTests/http/tests/websocket/tests/handshake-fail-by-no-cr_wsh.py
LayoutTests/http/tests/websocket/tests/handshake-fail-by-no-upgrade-header_wsh.py
LayoutTests/http/tests/websocket/tests/long-invalid-header_wsh.py

index d762d5a..d84acae 100644 (file)
@@ -1,3 +1,40 @@
+2011-07-03  Yuta Kitamura  <yutak@chromium.org>
+
+        Reviewed by Kent Tamura.
+
+        WebSocket: pywebsocket handlers should raise exception to abort the connection
+        https://bugs.webkit.org/show_bug.cgi?id=63794
+
+        pywebsocket automatically sends handshake response when web_socket_do_extra_handshake()
+        finishes, and starts closing handshake (sends a close frame and waits for client's response)
+        after web_socket_transfer_data() exits. To stop this behavior, a handler must raise an
+        exception.
+
+        Some of our handlers send broken handshake in web_socket_do_extra_handshake(). If this handler
+        function exits without raising an exception, pywebsocket automatically sends another handshake
+        response, which is not really necessary. Normally this extra handshake message is not a problem,
+        because the client does not read any data beyond the end of the first (broken) handshake if
+        the client is working correctly. However, if the client erroneously accepts the first handshake,
+        it will be hard to diagnose the problem because of the extra message. The same can happen for
+        web_socket_transfer_data().
+
+        Generally, pywebsocket handlers should raise an exception if they do not want to send any more
+        data. However, this fact has been overlooked in past changes, and handlers in many tests exit
+        normally where they should raise an exception. This change fix these errors.
+
+        * http/tests/websocket/tests/bad-handshake-crash_wsh.py:
+        * http/tests/websocket/tests/frame-length-overflow_wsh.py:
+        * http/tests/websocket/tests/handshake-fail-by-maxlength_wsh.py:
+        Do not need to cycle until disconnection.
+        * http/tests/websocket/tests/handshake-fail-by-no-connection-header_wsh.py:
+        * http/tests/websocket/tests/handshake-fail-by-no-cr_wsh.py:
+        * http/tests/websocket/tests/handshake-fail-by-no-upgrade-header_wsh.py:
+        * http/tests/websocket/tests/long-invalid-header_wsh.py:
+        Some ports (Chromium) intercept handshake messages and do not pass server's response
+        to WebCore until they find the end of handshake response (i.e. "\r\n\r\n" and 16-byte data).
+        If the handler aborts the connection without sending this end-of-response marker, entire
+        response is ignored, which causes the test to fail.
+
 2011-07-03  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r90347.
index 74aa92e..7b425bc 100644 (file)
@@ -9,6 +9,7 @@ def web_socket_do_extra_handshake(request):
     msg += request.ws_challenge_md5
     request.connection.write(msg)
     print msg
+    raise Exception("Abort the connection") # Prevents pywebsocket from sending its own handshake message.
 
 
 def web_socket_transfer_data(request):
index 89c0824..1c7c921 100644 (file)
@@ -5,3 +5,4 @@ def web_socket_do_extra_handshake(request):
 def web_socket_transfer_data(request):
     msg = 16 * '\xff'
     request.connection.write(msg)
+    raise Exception('Abort the connection') # Prevents pywebsocket from starting closing handshake.
index 4da1906..c039fb3 100644 (file)
@@ -19,8 +19,6 @@
 # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-import time
-
 
 def web_socket_do_extra_handshake(request):
     # This will cause the handshake to fail because it pushes the length of the
@@ -34,10 +32,7 @@ def web_socket_do_extra_handshake(request):
     msg += '\r\n'
     msg += request.ws_challenge_md5
     request.connection.write(msg)
-    # continue writing data until the client disconnects
-    while True:
-        time.sleep(1)
-        request.connection.write('keepalive\n')
+    raise Exception('abort the connection') # Prevents pywebsocket from sending its own handshake message.
 
 
 def web_socket_transfer_data(request):
index 2ad9273..7efc87a 100644 (file)
@@ -8,6 +8,7 @@ def web_socket_do_extra_handshake(request):
     msg += request.ws_challenge_md5
     request.connection.write(msg)
     print msg
+    raise Exception('Abort the connection') # Prevents pywebsocket from sending its own handshake message.
 
 
 def web_socket_transfer_data(request):
index a26999b..978924a 100644 (file)
@@ -8,6 +8,7 @@ def web_socket_do_extra_handshake(request):
     msg += request.ws_challenge_md5
     request.connection.write(msg)
     print msg
+    raise Exception('Abort the connection') # Prevents pywebsocket from sending its own handshake message.
 
 
 def web_socket_transfer_data(request):
index 4c0c0ee..114de75 100644 (file)
@@ -8,6 +8,7 @@ def web_socket_do_extra_handshake(request):
     msg += request.ws_challenge_md5
     request.connection.write(msg)
     print msg
+    raise Exception('Abort the connection') # Prevents pywebsocket from sending its own handshake message.
 
 
 def web_socket_transfer_data(request):
index 3887ab6..4a169f3 100644 (file)
@@ -1,7 +1,10 @@
 def web_socket_do_extra_handshake(request):
     msg = "HTTP/1.1 101 WebSocket Protocol Handshake\r\n"
     msg += ("p" * 1024) + "\r\n"
+    msg += "\r\n"
+    msg += request.ws_challenge_md5
     request.connection.write(msg)
+    raise Exception("Abort the connection") # Prevents pywebsocket from sending its own handshake message.
 
 
 def web_socket_transfer_data(request):