(test) missing Bearer in custom auth

This commit is contained in:
ishaan-jaff 2024-02-01 13:55:50 -08:00
parent 5ee62b25f5
commit e6bc73d131

View file

@ -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