- Revision
- 90350
- Author
- [email protected]
- Date
- 2011-07-03 22:20:03 -0700 (Sun, 03 Jul 2011)
Log Message
2011-07-03 Yuta Kitamura <[email protected]>
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.
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (90349 => 90350)
--- trunk/LayoutTests/ChangeLog 2011-07-04 03:54:36 UTC (rev 90349)
+++ trunk/LayoutTests/ChangeLog 2011-07-04 05:20:03 UTC (rev 90350)
@@ -1,3 +1,40 @@
+2011-07-03 Yuta Kitamura <[email protected]>
+
+ 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 <[email protected]>
Unreviewed, rolling out r90347.
Modified: trunk/LayoutTests/http/tests/websocket/tests/bad-handshake-crash_wsh.py (90349 => 90350)
--- trunk/LayoutTests/http/tests/websocket/tests/bad-handshake-crash_wsh.py 2011-07-04 03:54:36 UTC (rev 90349)
+++ trunk/LayoutTests/http/tests/websocket/tests/bad-handshake-crash_wsh.py 2011-07-04 05:20:03 UTC (rev 90350)
@@ -9,6 +9,7 @@
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):
Modified: trunk/LayoutTests/http/tests/websocket/tests/frame-length-overflow_wsh.py (90349 => 90350)
--- trunk/LayoutTests/http/tests/websocket/tests/frame-length-overflow_wsh.py 2011-07-04 03:54:36 UTC (rev 90349)
+++ trunk/LayoutTests/http/tests/websocket/tests/frame-length-overflow_wsh.py 2011-07-04 05:20:03 UTC (rev 90350)
@@ -5,3 +5,4 @@
def web_socket_transfer_data(request):
msg = 16 * '\xff'
request.connection.write(msg)
+ raise Exception('Abort the connection') # Prevents pywebsocket from starting closing handshake.
Modified: trunk/LayoutTests/http/tests/websocket/tests/handshake-fail-by-maxlength_wsh.py (90349 => 90350)
--- trunk/LayoutTests/http/tests/websocket/tests/handshake-fail-by-maxlength_wsh.py 2011-07-04 03:54:36 UTC (rev 90349)
+++ trunk/LayoutTests/http/tests/websocket/tests/handshake-fail-by-maxlength_wsh.py 2011-07-04 05:20:03 UTC (rev 90350)
@@ -19,9 +19,7 @@
# 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
# status line past 1024 characters
@@ -34,10 +32,7 @@
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):
Modified: trunk/LayoutTests/http/tests/websocket/tests/handshake-fail-by-no-connection-header_wsh.py (90349 => 90350)
--- trunk/LayoutTests/http/tests/websocket/tests/handshake-fail-by-no-connection-header_wsh.py 2011-07-04 03:54:36 UTC (rev 90349)
+++ trunk/LayoutTests/http/tests/websocket/tests/handshake-fail-by-no-connection-header_wsh.py 2011-07-04 05:20:03 UTC (rev 90350)
@@ -8,6 +8,7 @@
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):
Modified: trunk/LayoutTests/http/tests/websocket/tests/handshake-fail-by-no-cr_wsh.py (90349 => 90350)
--- trunk/LayoutTests/http/tests/websocket/tests/handshake-fail-by-no-cr_wsh.py 2011-07-04 03:54:36 UTC (rev 90349)
+++ trunk/LayoutTests/http/tests/websocket/tests/handshake-fail-by-no-cr_wsh.py 2011-07-04 05:20:03 UTC (rev 90350)
@@ -8,6 +8,7 @@
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):
Modified: trunk/LayoutTests/http/tests/websocket/tests/handshake-fail-by-no-upgrade-header_wsh.py (90349 => 90350)
--- trunk/LayoutTests/http/tests/websocket/tests/handshake-fail-by-no-upgrade-header_wsh.py 2011-07-04 03:54:36 UTC (rev 90349)
+++ trunk/LayoutTests/http/tests/websocket/tests/handshake-fail-by-no-upgrade-header_wsh.py 2011-07-04 05:20:03 UTC (rev 90350)
@@ -8,6 +8,7 @@
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):
Modified: trunk/LayoutTests/http/tests/websocket/tests/long-invalid-header_wsh.py (90349 => 90350)
--- trunk/LayoutTests/http/tests/websocket/tests/long-invalid-header_wsh.py 2011-07-04 03:54:36 UTC (rev 90349)
+++ trunk/LayoutTests/http/tests/websocket/tests/long-invalid-header_wsh.py 2011-07-04 05:20:03 UTC (rev 90350)
@@ -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):