Require admin for the script/config websocket command (#182046)

This commit is contained in:
Franck Nijhof
2026-09-13 09:58:48 +02:00
committed by GitHub
parent db80968d8f
commit 36bde370bf
2 changed files with 34 additions and 0 deletions
@@ -782,6 +782,7 @@ class ScriptEntity(BaseScriptEntity, RestoreEntity):
@websocket_api.websocket_command({"type": "script/config", "entity_id": str})
@websocket_api.require_admin
def websocket_config(
hass: HomeAssistant,
connection: websocket_api.ActiveConnection,
+33
View File
@@ -1611,6 +1611,39 @@ async def test_websocket_config(
assert msg["error"]["code"] == "not_found"
async def test_websocket_config_requires_admin(
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
hass_read_only_access_token: str,
) -> None:
"""Test config command requires admin."""
config = {
"alias": "hello",
"sequence": [{"action": "light.turn_on"}],
}
assert await async_setup_component(
hass,
DOMAIN,
{
"script": {
"hello": config,
},
},
)
client = await hass_ws_client(hass, hass_read_only_access_token)
await client.send_json(
{
"id": 5,
"type": "script/config",
"entity_id": "script.hello",
}
)
msg = await client.receive_json()
assert not msg["success"]
assert msg["error"]["code"] == "unauthorized"
async def test_script_service_changed_entity_id(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None: