litellm/tests/unit/proxy/realtime_endpoints
yucheng-berri 8d4d3dccfc
fix(proxy): accept any case of the bearer scheme on realtime auth (#53259)
* fix(proxy): accept any case of the bearer scheme on realtime auth

The WebSocket front door and the WebRTC calls handler only accepted the
exact "Bearer " prefix, so clients behind proxies that forward
"bearer <key>" got 403 on realtime while the same key worked on HTTP.
RFC 7235 makes the scheme case-insensitive.

Add one shared bearer_credential parse and use it in the WebSocket
handshake, proxy_realtime_calls, and as a fallback in the HTTP key
extractors, so every header value accepted today keeps the same key.

* test(proxy): assert the websocket auth result for any bearer casing

Check what the caller gets back from the WebSocket front door, against a
key store double that accepts only the issued key, instead of the
argument the mock received.

* fix(proxy): keep a raw master key that starts with a bearer scheme on x-litellm-api-key

A master key whose text begins with a non-canonical casing of Bearer, such as
BEARER, authenticated when sent raw in x-litellm-api-key, but the
case-insensitive scheme parse now strips that prefix. Skip the parse when the
raw value is the configured master key.

* test(proxy): drive real auth in the bearer scheme websocket tests

Present the master key on a real WebSocket instead of replacing
user_api_key_auth, type the new test parameters, and mint the realtime
calls token without an expiry so the test reads no clock.
2026-11-21 16:32:32 -08:00
..
__init__.py
test_realtime_webrtc_endpoints.py fix(proxy): accept any case of the bearer scheme on realtime auth (#53259) 2026-11-21 16:32:32 -08:00