diff --git a/litellm/tests/test_proxy_custom_auth.py b/litellm/tests/test_proxy_custom_auth.py index b6b833e173..55ab456245 100644 --- a/litellm/tests/test_proxy_custom_auth.py +++ b/litellm/tests/test_proxy_custom_auth.py @@ -65,3 +65,30 @@ def test_custom_auth(client): assert e.code == 401 assert e.message == "Authentication Error, Failed custom auth" pass + + +def test_custom_auth_bearer(client): + try: + # Your test data + test_data = { + "model": "openai-model", + "messages": [ + {"role": "user", "content": "hi"}, + ], + "max_tokens": 10, + } + # Your bearer token + token = os.getenv("PROXY_MASTER_KEY") + + headers = {"Authorization": f"WITHOUT BEAR Er {token}"} + response = client.post("/chat/completions", json=test_data, headers=headers) + pytest.fail("LiteLLM Proxy test failed. This request should have been rejected") + except Exception as e: + print(vars(e)) + print("got an exception") + assert e.code == 401 + assert ( + e.message + == "Authentication Error, CustomAuth - Malformed API Key passed in. Ensure Key has `Bearer` prefix" + ) + pass