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

Method test_invalid_key

tests/test_server.py:456–474  ·  view source on GitHub ↗

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

(self)

Source from the content-addressed store, hash-verified

454 )
455
456 def test_invalid_key(self):
457 """Handshake fails when the Sec-WebSocket-Key header is invalid."""
458 server = ServerProtocol()
459 request = make_request()
460 del request.headers["Sec-WebSocket-Key"]
461 request.headers["Sec-WebSocket-Key"] = "<not Base64 data>"
462 response = server.accept(request)
463 server.send_response(response)
464
465 self.assertEqual(response.status_code, 400)
466 if sys.version_info[:2] >= (3, 11):
467 b64_exc = "Only base64 data is allowed"
468 else: # pragma: no cover
469 b64_exc = "Non-base64 digit found"
470 self.assertHandshakeError(
471 server,
472 InvalidHeader,
473 f"invalid Sec-WebSocket-Key header: <not Base64 data>; {b64_exc}",
474 )
475
476 def test_truncated_key(self):
477 """Handshake fails when the Sec-WebSocket-Key header is truncated."""

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