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:
XU Pengfei
2026-11-17 08:34:37 +01:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 765f1f71a8
commit 7c78cc7c2e
2 changed files with 30 additions and 1 deletions
+5 -1
View File
@@ -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)})
+25
View File
@@ -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: