mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-02 00:22:06 +00:00
fix(ui_sso.py): maintain backwards compatibility for older user id va… (#11106)
* fix(ui_sso.py): maintain backwards compatibility for older user id variations Fixes issue in later SSO checks which only checked id from result * fix(internal_user_endpoints.py): handle trailing whitespace in new user email * fix(internal_user_endpoints.py): apply default_internal_user_settings on all new user calls (even when role not set) allows role undefined users to be assigned the correct role on sign up * feat(proxy_server.py): load default user settings from db - update litellm correctly updates the litellm module with default internal user settings ensures updated settings actually apply * test: add unit test * fix(internal_user_endpoints.py): fix internal user default param role * fix(ui_sso.py): fix linting error
This commit is contained in:
@@ -547,6 +547,53 @@ def test_update_internal_user_params():
|
||||
)
|
||||
|
||||
|
||||
def test_update_internal_new_user_params_with_no_initial_role_set():
|
||||
from litellm.proxy.management_endpoints.internal_user_endpoints import (
|
||||
_update_internal_new_user_params,
|
||||
)
|
||||
from litellm.proxy._types import NewUserRequest
|
||||
|
||||
litellm.default_internal_user_params = {
|
||||
"max_budget": 100,
|
||||
"budget_duration": "30d",
|
||||
"models": ["gpt-3.5-turbo"],
|
||||
}
|
||||
|
||||
data = NewUserRequest(user_email="krrish3@berri.ai")
|
||||
data_json = data.model_dump()
|
||||
updated_data_json = _update_internal_new_user_params(data_json, data)
|
||||
assert updated_data_json["models"] == litellm.default_internal_user_params["models"]
|
||||
assert (
|
||||
updated_data_json["max_budget"]
|
||||
== litellm.default_internal_user_params["max_budget"]
|
||||
)
|
||||
assert (
|
||||
updated_data_json["budget_duration"]
|
||||
== litellm.default_internal_user_params["budget_duration"]
|
||||
)
|
||||
|
||||
def test_update_internal_new_user_params_with_user_defined_values():
|
||||
from litellm.proxy.management_endpoints.internal_user_endpoints import (
|
||||
_update_internal_new_user_params,
|
||||
)
|
||||
from litellm.proxy._types import NewUserRequest
|
||||
|
||||
litellm.default_internal_user_params = {
|
||||
"max_budget": 100,
|
||||
"budget_duration": "30d",
|
||||
"models": ["gpt-3.5-turbo"],
|
||||
"user_role": "proxy_admin",
|
||||
}
|
||||
|
||||
data = NewUserRequest(user_email="krrish3@berri.ai", max_budget=1000, budget_duration="1mo")
|
||||
data_json = data.model_dump()
|
||||
updated_data_json = _update_internal_new_user_params(data_json, data)
|
||||
assert updated_data_json["user_email"] == "krrish3@berri.ai"
|
||||
assert updated_data_json["user_role"] == "proxy_admin"
|
||||
assert updated_data_json["max_budget"] == 1000
|
||||
assert updated_data_json["budget_duration"] == "1mo"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_proxy_config_update_from_db():
|
||||
from litellm.proxy.proxy_server import ProxyConfig
|
||||
@@ -956,6 +1003,35 @@ def test_update_config_fields():
|
||||
assert team_config["langfuse_public_key"] == "my-fake-key"
|
||||
assert team_config["langfuse_secret"] == "my-fake-secret"
|
||||
|
||||
def test_update_config_fields_default_internal_user_params(monkeypatch):
|
||||
from litellm.proxy.proxy_server import ProxyConfig
|
||||
|
||||
proxy_config = ProxyConfig()
|
||||
|
||||
monkeypatch.setattr(litellm, "default_internal_user_params", None)
|
||||
|
||||
|
||||
args = {
|
||||
"current_config": {},
|
||||
"param_name": "litellm_settings",
|
||||
"db_param_value": {
|
||||
"default_internal_user_params": {
|
||||
"user_role": "proxy_admin",
|
||||
"max_budget": 1000,
|
||||
"budget_duration": "1mo",
|
||||
},
|
||||
},
|
||||
}
|
||||
updated_config = proxy_config._update_config_fields(**args)
|
||||
|
||||
assert litellm.default_internal_user_params == {
|
||||
"user_role": "proxy_admin",
|
||||
"max_budget": 1000,
|
||||
"budget_duration": "1mo",
|
||||
}
|
||||
|
||||
monkeypatch.setattr(litellm, "default_internal_user_params", None) # reset to default
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"proxy_model_list,provider",
|
||||
|
||||
Reference in New Issue
Block a user