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

Fix alexa flash briefings after removal of api_password auth (#36789)

This commit is contained in:
Thomas Hollstegge
2020-06-23 17:58:25 +02:00
committed by GitHub
parent 835f433cf7
commit 2c7876fa66
4 changed files with 55 additions and 6 deletions

View File

@@ -6,7 +6,7 @@ import pytest
from homeassistant.components import alexa
from homeassistant.components.alexa import const
from homeassistant.const import HTTP_NOT_FOUND
from homeassistant.const import HTTP_NOT_FOUND, HTTP_UNAUTHORIZED
from homeassistant.core import callback
from homeassistant.setup import async_setup_component
@@ -39,6 +39,7 @@ def alexa_client(loop, hass, hass_client):
"homeassistant": {},
"alexa": {
"flash_briefings": {
"password": "pass/abc",
"weather": [
{
"title": "Weekly forecast",
@@ -63,8 +64,11 @@ def alexa_client(loop, hass, hass_client):
return loop.run_until_complete(hass_client())
def _flash_briefing_req(client, briefing_id):
return client.get(f"/api/alexa/flash_briefings/{briefing_id}")
def _flash_briefing_req(client, briefing_id, password="pass%2Fabc"):
if password is None:
return client.get(f"/api/alexa/flash_briefings/{briefing_id}")
return client.get(f"/api/alexa/flash_briefings/{briefing_id}?password={password}")
async def test_flash_briefing_invalid_id(alexa_client):
@@ -75,6 +79,30 @@ async def test_flash_briefing_invalid_id(alexa_client):
assert text == ""
async def test_flash_briefing_no_password(alexa_client):
"""Test for no Flash Briefing password."""
req = await _flash_briefing_req(alexa_client, "weather", password=None)
assert req.status == HTTP_UNAUTHORIZED
text = await req.text()
assert text == ""
async def test_flash_briefing_invalid_password(alexa_client):
"""Test an invalid Flash Briefing password."""
req = await _flash_briefing_req(alexa_client, "weather", password="wrongpass")
assert req.status == HTTP_UNAUTHORIZED
text = await req.text()
assert text == ""
async def test_flash_briefing_request_for_password(alexa_client):
"""Test for "password" Flash Briefing."""
req = await _flash_briefing_req(alexa_client, "password")
assert req.status == HTTP_NOT_FOUND
text = await req.text()
assert text == ""
async def test_flash_briefing_date_from_str(alexa_client):
"""Test the response has a valid date parsed from string."""
req = await _flash_briefing_req(alexa_client, "weather")