mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Test that mobile app requires empty object for encrypted webhooks without data (#70718)
This commit is contained in:
parent
f2bd4131eb
commit
4a53121b58
@ -298,12 +298,24 @@ async def test_webhook_returns_error_incorrect_json(
|
|||||||
assert "invalid JSON" in caplog.text
|
assert "invalid JSON" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_webhook_handle_decryption(webhook_client, create_registrations):
|
@pytest.mark.parametrize(
|
||||||
|
"msg,generate_response",
|
||||||
|
(
|
||||||
|
(RENDER_TEMPLATE, lambda hass: {"one": "Hello world"}),
|
||||||
|
(
|
||||||
|
{"type": "get_zones", "data": {}},
|
||||||
|
lambda hass: [hass.states.get("zone.home").as_dict()],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
async def test_webhook_handle_decryption(
|
||||||
|
hass, webhook_client, create_registrations, msg, generate_response
|
||||||
|
):
|
||||||
"""Test that we can encrypt/decrypt properly."""
|
"""Test that we can encrypt/decrypt properly."""
|
||||||
key = create_registrations[0]["secret"]
|
key = create_registrations[0]["secret"]
|
||||||
data = encrypt_payload(key, RENDER_TEMPLATE["data"])
|
data = encrypt_payload(key, msg["data"])
|
||||||
|
|
||||||
container = {"type": "render_template", "encrypted": True, "encrypted_data": data}
|
container = {"type": msg["type"], "encrypted": True, "encrypted_data": data}
|
||||||
|
|
||||||
resp = await webhook_client.post(
|
resp = await webhook_client.post(
|
||||||
"/api/webhook/{}".format(create_registrations[0]["webhook_id"]), json=container
|
"/api/webhook/{}".format(create_registrations[0]["webhook_id"]), json=container
|
||||||
@ -316,7 +328,7 @@ async def test_webhook_handle_decryption(webhook_client, create_registrations):
|
|||||||
|
|
||||||
decrypted_data = decrypt_payload(key, webhook_json["encrypted_data"])
|
decrypted_data = decrypt_payload(key, webhook_json["encrypted_data"])
|
||||||
|
|
||||||
assert decrypted_data == {"one": "Hello world"}
|
assert decrypted_data == generate_response(hass)
|
||||||
|
|
||||||
|
|
||||||
async def test_webhook_handle_decryption_legacy(webhook_client, create_registrations):
|
async def test_webhook_handle_decryption_legacy(webhook_client, create_registrations):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user