mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 04:08:19 -04:00
Handle unknown group in config/auth/update websocket command (#192896)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
765f1f71a8
commit
7c78cc7c2e
@@ -155,7 +155,11 @@ async def websocket_update(
|
||||
msg.pop("type")
|
||||
msg_id = msg.pop("id")
|
||||
|
||||
await hass.auth.async_update_user(user, **msg)
|
||||
try:
|
||||
await hass.auth.async_update_user(user, **msg)
|
||||
except ValueError as err:
|
||||
connection.send_error(msg_id, websocket_api.ERR_INVALID_FORMAT, str(err))
|
||||
return
|
||||
|
||||
connection.send_message(
|
||||
websocket_api.result_message(msg_id, {"user": _user_info(user)})
|
||||
|
||||
@@ -353,6 +353,31 @@ async def test_update_system_generated(
|
||||
assert user.name == "Test user"
|
||||
|
||||
|
||||
async def test_update_invalid_group(
|
||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||
) -> None:
|
||||
"""Test update command with a group that does not exist."""
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
user = await hass.auth.async_create_user("Test user")
|
||||
|
||||
await client.send_json(
|
||||
{
|
||||
"id": 5,
|
||||
"type": "config/auth/update",
|
||||
"user_id": user.id,
|
||||
"name": "Updated name",
|
||||
"group_ids": ["does-not-exist"],
|
||||
}
|
||||
)
|
||||
|
||||
result = await client.receive_json()
|
||||
assert not result["success"], result
|
||||
assert result["error"]["code"] == "invalid_format"
|
||||
assert user.name == "Test user"
|
||||
assert user.groups == []
|
||||
|
||||
|
||||
async def test_deactivate(
|
||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user