mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Require IFTTT to send data as dictionary (#32317)
* Require IFTTT to send data as dictionary * Update logging
This commit is contained in:
parent
8e3492d4f5
commit
c6e85cac0b
@ -93,10 +93,19 @@ async def handle_webhook(hass, webhook_id, request):
|
||||
try:
|
||||
data = json.loads(body) if body else {}
|
||||
except ValueError:
|
||||
return None
|
||||
_LOGGER.error(
|
||||
"Received invalid data from IFTTT. Data needs to be formatted as JSON: %s",
|
||||
body,
|
||||
)
|
||||
return
|
||||
|
||||
if isinstance(data, dict):
|
||||
data["webhook_id"] = webhook_id
|
||||
if not isinstance(data, dict):
|
||||
_LOGGER.error(
|
||||
"Received invalid data from IFTTT. Data needs to be a dictionary: %s", data
|
||||
)
|
||||
return
|
||||
|
||||
data["webhook_id"] = webhook_id
|
||||
hass.bus.async_fire(EVENT_RECEIVED, data)
|
||||
|
||||
|
||||
|
@ -33,3 +33,11 @@ async def test_config_flow_registers_webhook(hass, aiohttp_client):
|
||||
assert len(ifttt_events) == 1
|
||||
assert ifttt_events[0].data["webhook_id"] == webhook_id
|
||||
assert ifttt_events[0].data["hello"] == "ifttt"
|
||||
|
||||
# Invalid JSON
|
||||
await client.post("/api/webhook/{}".format(webhook_id), data="not a dict")
|
||||
assert len(ifttt_events) == 1
|
||||
|
||||
# Not a dict
|
||||
await client.post("/api/webhook/{}".format(webhook_id), json="not a dict")
|
||||
assert len(ifttt_events) == 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user