1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

If registration supports encryption then return encrypted payloads (#21853)

This commit is contained in:
Robbie Trencheny
2019-03-11 05:34:58 -07:00
committed by Charles Garwood
parent c401f35a43
commit 785fd273e3
7 changed files with 91 additions and 24 deletions

View File

@@ -10,14 +10,14 @@ from tests.common import async_mock_service
from . import authed_api_client, webhook_client # noqa: F401
from .const import (CALL_SERVICE, FIRE_EVENT, REGISTER, RENDER_TEMPLATE,
UPDATE)
from .const import (CALL_SERVICE, FIRE_EVENT, REGISTER_CLEARTEXT,
RENDER_TEMPLATE, UPDATE)
async def test_webhook_handle_render_template(webhook_client): # noqa: F811
"""Test that we render templates properly."""
resp = await webhook_client.post(
'/api/webhook/mobile_app_test',
'/api/webhook/mobile_app_test_cleartext',
json=RENDER_TEMPLATE
)
@@ -32,7 +32,7 @@ async def test_webhook_handle_call_services(hass, webhook_client): # noqa: E501
calls = async_mock_service(hass, 'test', 'mobile_app')
resp = await webhook_client.post(
'/api/webhook/mobile_app_test',
'/api/webhook/mobile_app_test_cleartext',
json=CALL_SERVICE
)
@@ -53,7 +53,7 @@ async def test_webhook_handle_fire_event(hass, webhook_client): # noqa: F811
hass.bus.async_listen('test_event', store_event)
resp = await webhook_client.post(
'/api/webhook/mobile_app_test',
'/api/webhook/mobile_app_test_cleartext',
json=FIRE_EVENT
)
@@ -69,7 +69,7 @@ async def test_webhook_update_registration(webhook_client, hass_client): # noqa
"""Test that a we can update an existing registration via webhook."""
authed_api_client = await hass_client() # noqa: F811
register_resp = await authed_api_client.post(
'/api/mobile_app/registrations', json=REGISTER
'/api/mobile_app/registrations', json=REGISTER_CLEARTEXT
)
assert register_resp.status == 201
@@ -96,7 +96,7 @@ async def test_webhook_update_registration(webhook_client, hass_client): # noqa
async def test_webhook_returns_error_incorrect_json(webhook_client, caplog): # noqa: E501 F811
"""Test that an error is returned when JSON is invalid."""
resp = await webhook_client.post(
'/api/webhook/mobile_app_test',
'/api/webhook/mobile_app_test_cleartext',
data='not json'
)
@@ -141,5 +141,11 @@ async def test_webhook_handle_decryption(webhook_client): # noqa: F811
assert resp.status == 200
json = await resp.json()
assert json == {'rendered': 'Hello world'}
webhook_json = await resp.json()
assert 'encrypted_data' in webhook_json
decrypted_data = SecretBox(key).decrypt(webhook_json['encrypted_data'],
encoder=Base64Encoder)
decrypted_data = decrypted_data.decode("utf-8")
assert json.loads(decrypted_data) == {'rendered': 'Hello world'}