Skip to content

Commit 51d004a

Browse files
authored
Require admin for webhook list websocket command (home-assistant#170216)
1 parent 9c9b626 commit 51d004a

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

homeassistant/components/webhook/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ async def _handle(self, request: Request, webhook_id: str) -> Response:
248248
"type": "webhook/list",
249249
}
250250
)
251+
@websocket_api.require_admin
251252
@callback
252253
def websocket_list(
253254
hass: HomeAssistant,

tests/components/webhook/test_init.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,24 @@ async def test_listing_webhook(
353353
]
354354

355355

356+
@pytest.mark.usefixtures("enable_custom_integrations")
357+
async def test_listing_webhook_requires_admin(
358+
hass: HomeAssistant,
359+
hass_ws_client: WebSocketGenerator,
360+
hass_read_only_access_token: str,
361+
) -> None:
362+
"""Test listing webhooks requires an admin user."""
363+
assert await async_setup_component(hass, "webhook", {})
364+
client = await hass_ws_client(hass, hass_read_only_access_token)
365+
366+
await client.send_json({"id": 5, "type": "webhook/list"})
367+
368+
msg = await client.receive_json()
369+
assert msg["id"] == 5
370+
assert not msg["success"]
371+
assert msg["error"]["code"] == "unauthorized"
372+
373+
356374
async def test_ws_webhook(
357375
hass: HomeAssistant,
358376
caplog: pytest.LogCaptureFixture,

0 commit comments

Comments
 (0)