mirror of
https://github.com/django/daphne.git
synced 2025-09-10 17:32:27 +03:00
Merge 3039fb72db
into 032c5608f9
This commit is contained in:
commit
250fb0bccc
|
@ -71,6 +71,8 @@ class WebSocketProtocol(WebSocketServerProtocol):
|
|||
subprotocols = [
|
||||
x.strip() for x in unquote(value.decode("ascii")).split(",")
|
||||
]
|
||||
if not all(isinstance(x, str) for x in subprotocols):
|
||||
raise ValueError("Invalid subprotocol value")
|
||||
# Make new application instance with scope
|
||||
self.path = request.path.encode("ascii")
|
||||
self.application_deferred = defer.maybeDeferred(
|
||||
|
|
|
@ -139,6 +139,15 @@ class TestWebsocket(DaphneTestCase):
|
|||
self.assert_valid_websocket_scope(scope, subprotocols=subprotocols)
|
||||
self.assert_valid_websocket_connect_message(messages[0])
|
||||
|
||||
def test_invalid_subprotocols(self):
|
||||
"""
|
||||
Tests that the server rejects connections with invalid subprotocols.
|
||||
"""
|
||||
with DaphneTestingInstance() as test_app:
|
||||
test_app.add_send_messages([{"type": "websocket.accept"}])
|
||||
with self.assertRaises(TypeError):
|
||||
self.websocket_handshake(test_app, subprotocols=[1, 2])
|
||||
|
||||
def test_xff(self):
|
||||
"""
|
||||
Tests that X-Forwarded-For headers get parsed right
|
||||
|
|
Loading…
Reference in New Issue
Block a user