diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/websockets/handlers | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/websockets/handlers')
22 files changed, 359 insertions, 0 deletions
diff --git a/testing/web-platform/tests/websockets/handlers/echo-cookie_wsh.py b/testing/web-platform/tests/websockets/handlers/echo-cookie_wsh.py new file mode 100755 index 000000000..367d03190 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/echo-cookie_wsh.py @@ -0,0 +1,12 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil + +def web_socket_do_extra_handshake(request): + request.ws_cookie = request.headers_in.get('Cookie') + +def web_socket_transfer_data(request): + if request.ws_cookie is not None: + msgutil.send_message(request, request.ws_cookie) + else: + msgutil.send_message(request, '(none)') diff --git a/testing/web-platform/tests/websockets/handlers/echo-query_v13_wsh.py b/testing/web-platform/tests/websockets/handlers/echo-query_v13_wsh.py new file mode 100755 index 000000000..4083c49bc --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/echo-query_v13_wsh.py @@ -0,0 +1,11 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil, util + +def web_socket_do_extra_handshake(request): + pass + +def web_socket_transfer_data(request): + while True: + msgutil.send_message(request, request.unparsed_uri.split('?')[1] or '') + return diff --git a/testing/web-platform/tests/websockets/handlers/echo-query_wsh.py b/testing/web-platform/tests/websockets/handlers/echo-query_wsh.py new file mode 100755 index 000000000..8fd7ac36b --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/echo-query_wsh.py @@ -0,0 +1,9 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil, util + +def web_socket_do_extra_handshake(request): + pass # Always accept. + +def web_socket_transfer_data(request): + msgutil.send_message(request, request.unparsed_uri.split('?', 1)[1] or '') diff --git a/testing/web-platform/tests/websockets/handlers/echo_close_data_wsh.py b/testing/web-platform/tests/websockets/handlers/echo_close_data_wsh.py new file mode 100755 index 000000000..4da4ce61f --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/echo_close_data_wsh.py @@ -0,0 +1,22 @@ +#!/usr/bin/python +from mod_pywebsocket import msgutil + +_GOODBYE_MESSAGE = u'Goodbye' + +def web_socket_do_extra_handshake(request): + # This example handler accepts any request. See origin_check_wsh.py for how + # to reject access from untrusted scripts based on origin value. + + pass # Always accept. + + +def web_socket_transfer_data(request): + while True: + line = request.ws_stream.receive_message() + if line is None: + return + if isinstance(line, unicode): + if line == _GOODBYE_MESSAGE: + return + request.ws_stream.send_message(line, binary=False) + diff --git a/testing/web-platform/tests/websockets/handlers/echo_exit_wsh.py b/testing/web-platform/tests/websockets/handlers/echo_exit_wsh.py new file mode 100755 index 000000000..200b92e58 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/echo_exit_wsh.py @@ -0,0 +1,21 @@ +#!/usr/bin/python +from mod_pywebsocket import msgutil + +_GOODBYE_MESSAGE = u'Goodbye' + +def web_socket_do_extra_handshake(request): + # This example handler accepts any request. See origin_check_wsh.py for how + # to reject access from untrusted scripts based on origin value. + + pass # Always accept. + + +def web_socket_transfer_data(request): + while True: + line = request.ws_stream.receive_message() + if line is None: + return + if isinstance(line, unicode): + if line == _GOODBYE_MESSAGE: + return + diff --git a/testing/web-platform/tests/websockets/handlers/echo_raw_wsh.py b/testing/web-platform/tests/websockets/handlers/echo_raw_wsh.py new file mode 100755 index 000000000..c3a030c96 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/echo_raw_wsh.py @@ -0,0 +1,15 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil +import urllib + + +def web_socket_do_extra_handshake(request): + pass # Always accept. + +def web_socket_transfer_data(request): + while True: + line = msgutil.receive_message(request) + if line == 'exit': + return + request.connection.write(line.decode("string-escape")) diff --git a/testing/web-platform/tests/websockets/handlers/echo_wsh.py b/testing/web-platform/tests/websockets/handlers/echo_wsh.py new file mode 100755 index 000000000..41bcd1694 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/echo_wsh.py @@ -0,0 +1,36 @@ +#!/usr/bin/python +from mod_pywebsocket import msgutil +from mod_pywebsocket import common + +_GOODBYE_MESSAGE = u'Goodbye' + +def web_socket_do_extra_handshake(request): + # This example handler accepts any request. See origin_check_wsh.py for how + # to reject access from untrusted scripts based on origin value. + if request.ws_requested_protocols: + if "echo" in request.ws_requested_protocols: + request.ws_protocol = "echo" + + +def web_socket_transfer_data(request): + while True: + line = request.ws_stream.receive_message() + if line is None: + return + if isinstance(line, unicode): + request.ws_stream.send_message(line, binary=False) + if line == _GOODBYE_MESSAGE: + return + else: + request.ws_stream.send_message(line, binary=True) + +def web_socket_passive_closing_handshake(request): + # Echo close status code and reason + code, reason = request.ws_close_code, request.ws_close_reason + + # No status received is a reserved pseudo code representing an empty code, + # so echo back an empty code in this case. + if code == common.STATUS_NO_STATUS_RECEIVED: + code = None + + return code, reason diff --git a/testing/web-platform/tests/websockets/handlers/empty-message_wsh.py b/testing/web-platform/tests/websockets/handlers/empty-message_wsh.py new file mode 100755 index 000000000..0eb107f0b --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/empty-message_wsh.py @@ -0,0 +1,13 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil + +def web_socket_do_extra_handshake(request): + pass # Always accept. + +def web_socket_transfer_data(request): + line = msgutil.receive_message(request) + if line == "": + msgutil.send_message(request, 'pass') + else: + msgutil.send_message(request, 'fail') diff --git a/testing/web-platform/tests/websockets/handlers/handshake_no_protocol_wsh.py b/testing/web-platform/tests/websockets/handlers/handshake_no_protocol_wsh.py new file mode 100755 index 000000000..3e6b8e664 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/handshake_no_protocol_wsh.py @@ -0,0 +1,12 @@ +#!/usr/bin/python + +from mod_pywebsocket import common, msgutil, util +from mod_pywebsocket.handshake import hybi + +def web_socket_do_extra_handshake(request): + request.connection.write('HTTP/1.1 101 Switching Protocols:\x0D\x0AConnection: Upgrade\x0D\x0AUpgrade: WebSocket\x0D\x0ASec-WebSocket-Origin: '+request.ws_origin+'\x0D\x0ASec-WebSocket-Accept: '+hybi.compute_accept(request.headers_in.get(common.SEC_WEBSOCKET_KEY_HEADER))[0]+'\x0D\x0A\x0D\x0A') + return + +def web_socket_transfer_data(request): + while True: + return diff --git a/testing/web-platform/tests/websockets/handlers/handshake_protocol_wsh.py b/testing/web-platform/tests/websockets/handlers/handshake_protocol_wsh.py new file mode 100755 index 000000000..d3ebb273d --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/handshake_protocol_wsh.py @@ -0,0 +1,12 @@ +#!/usr/bin/python + +from mod_pywebsocket import common, msgutil, util +from mod_pywebsocket.handshake import hybi + +def web_socket_do_extra_handshake(request): + request.connection.write('HTTP/1.1 101 Switching Protocols:\x0D\x0AConnection: Upgrade\x0D\x0AUpgrade: WebSocket\x0D\x0ASec-WebSocket-Protocol: foobar\x0D\x0ASec-WebSocket-Origin: '+request.ws_origin+'\x0D\x0ASec-WebSocket-Accept: '+hybi.compute_accept(request.headers_in.get(common.SEC_WEBSOCKET_KEY_HEADER))[0]+'\x0D\x0A\x0D\x0A') + return + +def web_socket_transfer_data(request): + while True: + return
\ No newline at end of file diff --git a/testing/web-platform/tests/websockets/handlers/handshake_sleep_2_wsh.py b/testing/web-platform/tests/websockets/handlers/handshake_sleep_2_wsh.py new file mode 100755 index 000000000..3367ed8f8 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/handshake_sleep_2_wsh.py @@ -0,0 +1,10 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil +import time + +def web_socket_do_extra_handshake(request): + time.sleep(2) + +def web_socket_transfer_data(request): + pass diff --git a/testing/web-platform/tests/websockets/handlers/invalid_wsh.py b/testing/web-platform/tests/websockets/handlers/invalid_wsh.py new file mode 100755 index 000000000..886e970b8 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/invalid_wsh.py @@ -0,0 +1,9 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil + +def web_socket_do_extra_handshake(request): + request.connection.write("FOO BAR BAZ\r\n\r\n") + +def web_socket_transfer_data(request): + pass diff --git a/testing/web-platform/tests/websockets/handlers/origin_wsh.py b/testing/web-platform/tests/websockets/handlers/origin_wsh.py new file mode 100755 index 000000000..ce5f3a7f6 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/origin_wsh.py @@ -0,0 +1,11 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil + + +def web_socket_do_extra_handshake(request): + pass # Always accept. + + +def web_socket_transfer_data(request): + msgutil.send_message(request, request.ws_origin) diff --git a/testing/web-platform/tests/websockets/handlers/protocol_array_wsh.py b/testing/web-platform/tests/websockets/handlers/protocol_array_wsh.py new file mode 100755 index 000000000..5d46c588c --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/protocol_array_wsh.py @@ -0,0 +1,14 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil, util + +def web_socket_do_extra_handshake(request): + line = request.headers_in.get('Sec-WebSocket-Protocol') + request.ws_protocol = line.split(',', 1)[0] + +#pass + +def web_socket_transfer_data(request): + while True: + msgutil.send_message(request, request.ws_protocol) + return diff --git a/testing/web-platform/tests/websockets/handlers/protocol_wsh.py b/testing/web-platform/tests/websockets/handlers/protocol_wsh.py new file mode 100755 index 000000000..96a452584 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/protocol_wsh.py @@ -0,0 +1,12 @@ +#!/usr/bin/python + +from mod_pywebsocket import msgutil, util + +def web_socket_do_extra_handshake(request): + request.ws_protocol = request.headers_in.get('Sec-WebSocket-Protocol') +#pass + +def web_socket_transfer_data(request): + while True: + msgutil.send_message(request, request.ws_protocol) + return diff --git a/testing/web-platform/tests/websockets/handlers/set-cookie-secure_wsh.py b/testing/web-platform/tests/websockets/handlers/set-cookie-secure_wsh.py new file mode 100755 index 000000000..0daf72856 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/set-cookie-secure_wsh.py @@ -0,0 +1,15 @@ +#!/usr/bin/python +import urlparse + +from mod_pywebsocket import common, msgutil, util +from mod_pywebsocket.handshake import hybi + + +def web_socket_do_extra_handshake(request): + url_parts = urlparse.urlsplit(request.uri) + request.connection.write('HTTP/1.1 101 Switching Protocols:\x0D\x0AConnection: Upgrade\x0D\x0AUpgrade: WebSocket\x0D\x0ASet-Cookie: ws_test_'+(url_parts.query or '')+'=test; Secure; Path=/\x0D\x0ASec-WebSocket-Origin: '+request.ws_origin+'\x0D\x0ASec-WebSocket-Accept: '+hybi.compute_accept(request.headers_in.get(common.SEC_WEBSOCKET_KEY_HEADER))[0]+'\x0D\x0A\x0D\x0A') + return + +def web_socket_transfer_data(request): + while True: + return diff --git a/testing/web-platform/tests/websockets/handlers/set-cookie_http_wsh.py b/testing/web-platform/tests/websockets/handlers/set-cookie_http_wsh.py new file mode 100755 index 000000000..147842457 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/set-cookie_http_wsh.py @@ -0,0 +1,14 @@ +#!/usr/bin/python + +from mod_pywebsocket import common, msgutil, util +from mod_pywebsocket.handshake import hybi +import urlparse + +def web_socket_do_extra_handshake(request): + url_parts = urlparse.urlsplit(request.uri) + request.connection.write('HTTP/1.1 101 Switching Protocols:\x0D\x0AConnection: Upgrade\x0D\x0AUpgrade: WebSocket\x0D\x0ASet-Cookie: ws_test_'+(url_parts.query or '')+'=test; Path=/; HttpOnly\x0D\x0ASec-WebSocket-Origin: '+request.ws_origin+'\x0D\x0ASec-WebSocket-Accept: '+hybi.compute_accept(request.headers_in.get(common.SEC_WEBSOCKET_KEY_HEADER))[0]+'\x0D\x0A\x0D\x0A') + return + +def web_socket_transfer_data(request): + while True: + return diff --git a/testing/web-platform/tests/websockets/handlers/set-cookie_wsh.py b/testing/web-platform/tests/websockets/handlers/set-cookie_wsh.py new file mode 100755 index 000000000..b0e650476 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/set-cookie_wsh.py @@ -0,0 +1,15 @@ +#!/usr/bin/python +import urlparse + +from mod_pywebsocket import common, msgutil, util +from mod_pywebsocket.handshake import hybi + + +def web_socket_do_extra_handshake(request): + url_parts = urlparse.urlsplit(request.uri) + request.connection.write('HTTP/1.1 101 Switching Protocols:\x0D\x0AConnection: Upgrade\x0D\x0AUpgrade: WebSocket\x0D\x0ASet-Cookie: ws_test_'+(url_parts.query or '')+'=test; Path=/\x0D\x0ASec-WebSocket-Origin: '+request.ws_origin+'\x0D\x0ASec-WebSocket-Accept: '+hybi.compute_accept(request.headers_in.get(common.SEC_WEBSOCKET_KEY_HEADER))[0]+'\x0D\x0A\x0D\x0A') + return + +def web_socket_transfer_data(request): + while True: + return diff --git a/testing/web-platform/tests/websockets/handlers/simple_handshake_wsh.py b/testing/web-platform/tests/websockets/handlers/simple_handshake_wsh.py new file mode 100755 index 000000000..075009907 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/simple_handshake_wsh.py @@ -0,0 +1,13 @@ +#!/usr/bin/python + +from mod_pywebsocket import common, msgutil, util +from mod_pywebsocket.handshake import hybi + + +def web_socket_do_extra_handshake(request): + request.connection.write('HTTP/1.1 101 Switching Protocols:\x0D\x0AConnection: Upgrade\x0D\x0AUpgrade: WebSocket\x0D\x0ASet-Cookie: ws_test=test\x0D\x0ASec-WebSocket-Origin: '+request.ws_origin+'\x0D\x0ASec-WebSocket-Accept: '+hybi.compute_accept(request.headers_in.get(common.SEC_WEBSOCKET_KEY_HEADER))[0]+'\x0D\x0A\x0D\x0A') + return + +def web_socket_transfer_data(request): + while True: + return diff --git a/testing/web-platform/tests/websockets/handlers/sleep_10_v13_wsh.py b/testing/web-platform/tests/websockets/handlers/sleep_10_v13_wsh.py new file mode 100755 index 000000000..e1a6d9640 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/sleep_10_v13_wsh.py @@ -0,0 +1,25 @@ +#!/usr/bin/python + +import sys, urllib, time +from mod_pywebsocket import common, msgutil, util + +def web_socket_do_extra_handshake(request): + request.connection.write('x') + time.sleep(2) + request.connection.write('x') + time.sleep(2) + request.connection.write('x') + time.sleep(2) + request.connection.write('x') + time.sleep(2) + request.connection.write('x') + time.sleep(2) + return + +def web_socket_transfer_data(request): + while True: + line = msgutil.receive_message(request) + if line == 'Goodbye': + return + request.ws_stream.send_message(line, binary=False) + diff --git a/testing/web-platform/tests/websockets/handlers/stash_responder_wsh.py b/testing/web-platform/tests/websockets/handlers/stash_responder_wsh.py new file mode 100644 index 000000000..bc6f4fd6e --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/stash_responder_wsh.py @@ -0,0 +1,45 @@ +#!/usr/bin/python +import urlparse, json +from mod_pywebsocket import common, msgutil, util +from mod_pywebsocket.handshake import hybi +from wptserve import stash + +address, authkey = stash.load_env_config() +stash = stash.Stash("/stash_responder", address=address, authkey=authkey) + +def web_socket_do_extra_handshake(request): + return + +def web_socket_transfer_data(request): + while True: + line = request.ws_stream.receive_message() + if line == "echo": + query = request.unparsed_uri.split('?')[1] + GET = dict(urlparse.parse_qsl(query)) + + # TODO(kristijanburnik): This code should be reused from + # /mixed-content/generic/expect.py or implemented more generally + # for other tests. + path = GET.get("path", request.unparsed_uri.split('?')[0]) + key = GET["key"] + action = GET["action"] + + if action == "put": + value = GET["value"] + stash.take(key=key, path=path) + stash.put(key=key, value=value, path=path) + response_data = json.dumps({"status": "success", "result": key}) + elif action == "purge": + value = stash.take(key=key, path=path) + response_data = json.dumps({"status": "success", "result": value}) + elif action == "take": + value = stash.take(key=key, path=path) + if value is None: + status = "allowed" + else: + status = "blocked" + response_data = json.dumps({"status": status, "result": value}) + + msgutil.send_message(request, response_data) + + return diff --git a/testing/web-platform/tests/websockets/handlers/wrong_accept_key_wsh.py b/testing/web-platform/tests/websockets/handlers/wrong_accept_key_wsh.py new file mode 100755 index 000000000..f504a81f4 --- /dev/null +++ b/testing/web-platform/tests/websockets/handlers/wrong_accept_key_wsh.py @@ -0,0 +1,13 @@ +#!/usr/bin/python + +import sys, urllib, time +from mod_pywebsocket import common, msgutil, util + +def web_socket_do_extra_handshake(request): + request.connection.write('HTTP/1.1 101 Switching Protocols:\x0D\x0AConnection: Upgrade\x0D\x0AUpgrade: WebSocket\x0D\x0ASec-WebSocket-Origin: '+request.ws_origin+'\x0D\x0ASec-WebSocket-Accept: thisisawrongacceptkey\x0D\x0A\x0D\x0A') + return + +def web_socket_transfer_data(request): + while True: + request.ws_stream.send_message('test', binary=False) + return |