Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions homeassistant/components/withings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,16 @@ async def register_webhook(
self.hass, self.entry.data[CONF_WEBHOOK_ID]
)
url = URL(webhook_url)
if url.scheme != "https" or url.port != 443:
if url.scheme != "https":
LOGGER.warning(
"Webhook not registered - "
"https and port 443 is required to register the webhook"
"Webhook not registered - HTTPS is required. "
"See https://www.home-assistant.io/integrations/withings/#webhook-requirements"
)
return
if url.port != 443:
LOGGER.warning(
"Webhook not registered - port 443 is required. "
"See https://www.home-assistant.io/integrations/withings/#webhook-requirements"
)
return

Expand Down
11 changes: 9 additions & 2 deletions tests/components/withings/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,21 @@ async def test_setup_with_cloud(
assert not hass.config_entries.async_entries(DOMAIN)


@pytest.mark.parametrize("url", ["http://example.com", "https://example.com:444"])
@pytest.mark.parametrize(
("url", "expected_message"),
[
("http://example.com", "HTTPS is required"),
("https://example.com:444", "port 443 is required"),
],
)
async def test_setup_no_webhook(
hass: HomeAssistant,
webhook_config_entry: MockConfigEntry,
withings: AsyncMock,
caplog: pytest.LogCaptureFixture,
freezer: FrozenDateTimeFactory,
url: str,
expected_message: str,
) -> None:
"""Test if set up with cloud link and without https."""
hass.config.components.add("cloud")
Expand All @@ -378,7 +385,7 @@ async def test_setup_no_webhook(
await hass.async_block_till_done()
mock_async_generate_url.assert_called_once()

assert "https and port 443 is required to register the webhook" in caplog.text
assert expected_message in caplog.text


async def test_cloud_disconnect(
Expand Down
Loading