MCPcopy Index your code
hub / github.com/python-websockets/websockets / test_truncated_key

Method test_truncated_key

tests/test_server.py:476–491  ·  view source on GitHub ↗

Handshake fails when the Sec-WebSocket-Key header is truncated.

(self)

Source from the content-addressed store, hash-verified

474 )
475
476 def test_truncated_key(self):
477 """Handshake fails when the Sec-WebSocket-Key header is truncated."""
478 server = ServerProtocol()
479 request = make_request()
480 del request.headers["Sec-WebSocket-Key"]
481 # 12 bytes instead of 16, Base64-encoded
482 request.headers["Sec-WebSocket-Key"] = KEY[:16]
483 response = server.accept(request)
484 server.send_response(response)
485
486 self.assertEqual(response.status_code, 400)
487 self.assertHandshakeError(
488 server,
489 InvalidHeader,
490 f"invalid Sec-WebSocket-Key header: {KEY[:16]}",
491 )
492
493 def test_missing_version(self):
494 """Handshake fails when the Sec-WebSocket-Version header is missing."""

Callers

nothing calls this directly

Calls 5

acceptMethod · 0.95
send_responseMethod · 0.95
assertHandshakeErrorMethod · 0.95
ServerProtocolClass · 0.85
make_requestFunction · 0.85

Tested by

no test coverage detected