mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 01:38:02 +00:00
Check for port in Withings webhook creation (#102026)
Check if port is really 443
This commit is contained in:
parent
5b8da03596
commit
0eb4567364
@ -15,6 +15,7 @@ from aiohttp.web import Request, Response
|
|||||||
from aiowithings import NotificationCategory, WithingsClient
|
from aiowithings import NotificationCategory, WithingsClient
|
||||||
from aiowithings.util import to_enum
|
from aiowithings.util import to_enum
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
from yarl import URL
|
||||||
|
|
||||||
from homeassistant.components import cloud
|
from homeassistant.components import cloud
|
||||||
from homeassistant.components.application_credentials import (
|
from homeassistant.components.application_credentials import (
|
||||||
@ -179,8 +180,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
webhook_url = await _async_cloudhook_generate_url(hass, entry)
|
webhook_url = await _async_cloudhook_generate_url(hass, entry)
|
||||||
else:
|
else:
|
||||||
webhook_url = webhook_generate_url(hass, entry.data[CONF_WEBHOOK_ID])
|
webhook_url = webhook_generate_url(hass, entry.data[CONF_WEBHOOK_ID])
|
||||||
|
url = URL(webhook_url)
|
||||||
if not webhook_url.startswith("https://"):
|
if url.scheme != "https" or url.port != 443:
|
||||||
LOGGER.warning(
|
LOGGER.warning(
|
||||||
"Webhook not registered - "
|
"Webhook not registered - "
|
||||||
"https and port 443 is required to register the webhook"
|
"https and port 443 is required to register the webhook"
|
||||||
|
@ -51,7 +51,7 @@ async def setup_integration(
|
|||||||
if enable_webhooks:
|
if enable_webhooks:
|
||||||
await async_process_ha_core_config(
|
await async_process_ha_core_config(
|
||||||
hass,
|
hass,
|
||||||
{"external_url": "https://example.local:8123"},
|
{"external_url": "https://example.com"},
|
||||||
)
|
)
|
||||||
|
|
||||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
@ -8,13 +8,13 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"appli": 50,
|
"appli": 50,
|
||||||
"callbackurl": "https://example.local:8123/api/webhook/55a7335ea8dee830eed4ef8f84cda8f6d80b83af0847dc74032e86120bffed5e",
|
"callbackurl": "https://example.com/api/webhook/55a7335ea8dee830eed4ef8f84cda8f6d80b83af0847dc74032e86120bffed5e",
|
||||||
"expires": 2147483647,
|
"expires": 2147483647,
|
||||||
"comment": null
|
"comment": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"appli": 51,
|
"appli": 51,
|
||||||
"callbackurl": "https://example.local:8123/api/webhook/55a7335ea8dee830eed4ef8f84cda8f6d80b83af0847dc74032e86120bffed5e",
|
"callbackurl": "https://example.com/api/webhook/55a7335ea8dee830eed4ef8f84cda8f6d80b83af0847dc74032e86120bffed5e",
|
||||||
"expires": 2147483647,
|
"expires": 2147483647,
|
||||||
"comment": null
|
"comment": null
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ async def test_data_manager_webhook_subscription(
|
|||||||
|
|
||||||
assert withings.subscribe_notification.call_count == 6
|
assert withings.subscribe_notification.call_count == 6
|
||||||
|
|
||||||
webhook_url = "https://example.local:8123/api/webhook/55a7335ea8dee830eed4ef8f84cda8f6d80b83af0847dc74032e86120bffed5e"
|
webhook_url = "https://example.com/api/webhook/55a7335ea8dee830eed4ef8f84cda8f6d80b83af0847dc74032e86120bffed5e"
|
||||||
|
|
||||||
withings.subscribe_notification.assert_any_call(
|
withings.subscribe_notification.assert_any_call(
|
||||||
webhook_url, NotificationCategory.WEIGHT
|
webhook_url, NotificationCategory.WEIGHT
|
||||||
@ -428,12 +428,14 @@ async def test_setup_with_cloud(
|
|||||||
assert not hass.config_entries.async_entries(DOMAIN)
|
assert not hass.config_entries.async_entries(DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_without_https(
|
@pytest.mark.parametrize("url", ["http://example.com", "https://example.com:444"])
|
||||||
|
async def test_setup_no_webhook(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
webhook_config_entry: MockConfigEntry,
|
webhook_config_entry: MockConfigEntry,
|
||||||
withings: AsyncMock,
|
withings: AsyncMock,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
freezer: FrozenDateTimeFactory,
|
freezer: FrozenDateTimeFactory,
|
||||||
|
url: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test if set up with cloud link and without https."""
|
"""Test if set up with cloud link and without https."""
|
||||||
hass.config.components.add("cloud")
|
hass.config.components.add("cloud")
|
||||||
@ -445,7 +447,7 @@ async def test_setup_without_https(
|
|||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.withings.webhook_generate_url"
|
"homeassistant.components.withings.webhook_generate_url"
|
||||||
) as mock_async_generate_url:
|
) as mock_async_generate_url:
|
||||||
mock_async_generate_url.return_value = "http://example.com"
|
mock_async_generate_url.return_value = url
|
||||||
await setup_integration(hass, webhook_config_entry)
|
await setup_integration(hass, webhook_config_entry)
|
||||||
await prepare_webhook_setup(hass, freezer)
|
await prepare_webhook_setup(hass, freezer)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user