mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +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.util import to_enum
|
||||
import voluptuous as vol
|
||||
from yarl import URL
|
||||
|
||||
from homeassistant.components import cloud
|
||||
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)
|
||||
else:
|
||||
webhook_url = webhook_generate_url(hass, entry.data[CONF_WEBHOOK_ID])
|
||||
|
||||
if not webhook_url.startswith("https://"):
|
||||
url = URL(webhook_url)
|
||||
if url.scheme != "https" or url.port != 443:
|
||||
LOGGER.warning(
|
||||
"Webhook not registered - "
|
||||
"https and port 443 is required to register the webhook"
|
||||
|
@ -51,7 +51,7 @@ async def setup_integration(
|
||||
if enable_webhooks:
|
||||
await async_process_ha_core_config(
|
||||
hass,
|
||||
{"external_url": "https://example.local:8123"},
|
||||
{"external_url": "https://example.com"},
|
||||
)
|
||||
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
@ -8,13 +8,13 @@
|
||||
},
|
||||
{
|
||||
"appli": 50,
|
||||
"callbackurl": "https://example.local:8123/api/webhook/55a7335ea8dee830eed4ef8f84cda8f6d80b83af0847dc74032e86120bffed5e",
|
||||
"callbackurl": "https://example.com/api/webhook/55a7335ea8dee830eed4ef8f84cda8f6d80b83af0847dc74032e86120bffed5e",
|
||||
"expires": 2147483647,
|
||||
"comment": null
|
||||
},
|
||||
{
|
||||
"appli": 51,
|
||||
"callbackurl": "https://example.local:8123/api/webhook/55a7335ea8dee830eed4ef8f84cda8f6d80b83af0847dc74032e86120bffed5e",
|
||||
"callbackurl": "https://example.com/api/webhook/55a7335ea8dee830eed4ef8f84cda8f6d80b83af0847dc74032e86120bffed5e",
|
||||
"expires": 2147483647,
|
||||
"comment": null
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ async def test_data_manager_webhook_subscription(
|
||||
|
||||
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(
|
||||
webhook_url, NotificationCategory.WEIGHT
|
||||
@ -428,12 +428,14 @@ async def test_setup_with_cloud(
|
||||
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,
|
||||
webhook_config_entry: MockConfigEntry,
|
||||
withings: AsyncMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
url: str,
|
||||
) -> None:
|
||||
"""Test if set up with cloud link and without https."""
|
||||
hass.config.components.add("cloud")
|
||||
@ -445,7 +447,7 @@ async def test_setup_without_https(
|
||||
), patch(
|
||||
"homeassistant.components.withings.webhook_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 prepare_webhook_setup(hass, freezer)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user