mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +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:
|
try:
|
||||||
data = json.loads(body) if body else {}
|
data = json.loads(body) if body else {}
|
||||||
except ValueError:
|
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):
|
if not isinstance(data, dict):
|
||||||
data["webhook_id"] = webhook_id
|
_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)
|
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 len(ifttt_events) == 1
|
||||||
assert ifttt_events[0].data["webhook_id"] == webhook_id
|
assert ifttt_events[0].data["webhook_id"] == webhook_id
|
||||||
assert ifttt_events[0].data["hello"] == "ifttt"
|
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