mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
add verify_ssl
config flow option to ntfy integration (#143731)
* add verfy_ssl option * changes
This commit is contained in:
parent
eabf88e3c9
commit
34becb541a
@ -13,7 +13,7 @@ from aiontfy.exceptions import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_TOKEN, CONF_URL, Platform
|
from homeassistant.const import CONF_TOKEN, CONF_URL, CONF_VERIFY_SSL, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
@ -30,7 +30,7 @@ type NtfyConfigEntry = ConfigEntry[Ntfy]
|
|||||||
async def async_setup_entry(hass: HomeAssistant, entry: NtfyConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: NtfyConfigEntry) -> bool:
|
||||||
"""Set up ntfy from a config entry."""
|
"""Set up ntfy from a config entry."""
|
||||||
|
|
||||||
session = async_get_clientsession(hass)
|
session = async_get_clientsession(hass, entry.data.get(CONF_VERIFY_SSL, True))
|
||||||
ntfy = Ntfy(entry.data[CONF_URL], session, token=entry.data.get(CONF_TOKEN))
|
ntfy = Ntfy(entry.data[CONF_URL], session, token=entry.data.get(CONF_TOKEN))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -33,6 +33,7 @@ from homeassistant.const import (
|
|||||||
CONF_TOKEN,
|
CONF_TOKEN,
|
||||||
CONF_URL,
|
CONF_URL,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
|
CONF_VERIFY_SSL,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
@ -54,6 +55,7 @@ STEP_USER_DATA_SCHEMA = vol.Schema(
|
|||||||
autocomplete="url",
|
autocomplete="url",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
vol.Required(CONF_VERIFY_SSL, default=True): bool,
|
||||||
vol.Required(SECTION_AUTH): data_entry_flow.section(
|
vol.Required(SECTION_AUTH): data_entry_flow.section(
|
||||||
vol.Schema(
|
vol.Schema(
|
||||||
{
|
{
|
||||||
@ -123,7 +125,7 @@ class NtfyConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
CONF_USERNAME: username,
|
CONF_USERNAME: username,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
session = async_get_clientsession(self.hass)
|
session = async_get_clientsession(self.hass, user_input[CONF_VERIFY_SSL])
|
||||||
if username:
|
if username:
|
||||||
ntfy = Ntfy(
|
ntfy = Ntfy(
|
||||||
user_input[CONF_URL],
|
user_input[CONF_URL],
|
||||||
@ -160,6 +162,7 @@ class NtfyConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
CONF_URL: url.human_repr(),
|
CONF_URL: url.human_repr(),
|
||||||
CONF_USERNAME: username,
|
CONF_USERNAME: username,
|
||||||
CONF_TOKEN: token,
|
CONF_TOKEN: token,
|
||||||
|
CONF_VERIFY_SSL: user_input[CONF_VERIFY_SSL],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -8,10 +8,12 @@
|
|||||||
"user": {
|
"user": {
|
||||||
"description": "Set up **ntfy** push notification service",
|
"description": "Set up **ntfy** push notification service",
|
||||||
"data": {
|
"data": {
|
||||||
"url": "Service URL"
|
"url": "Service URL",
|
||||||
|
"verify_ssl": "[%key:common::config_flow::data::verify_ssl%]"
|
||||||
},
|
},
|
||||||
"data_description": {
|
"data_description": {
|
||||||
"url": "Address of the ntfy service. Modify this if you want to use a different server"
|
"url": "Address of the ntfy service. Modify this if you want to use a different server",
|
||||||
|
"verify_ssl": "Enable SSL certificate verification for secure connections. Disable only if connecting to a ntfy instance using a self-signed certificate"
|
||||||
},
|
},
|
||||||
"sections": {
|
"sections": {
|
||||||
"auth": {
|
"auth": {
|
||||||
|
@ -9,7 +9,7 @@ import pytest
|
|||||||
|
|
||||||
from homeassistant.components.ntfy.const import CONF_TOPIC, DOMAIN
|
from homeassistant.components.ntfy.const import CONF_TOPIC, DOMAIN
|
||||||
from homeassistant.config_entries import ConfigSubentryData
|
from homeassistant.config_entries import ConfigSubentryData
|
||||||
from homeassistant.const import CONF_TOKEN, CONF_URL, CONF_USERNAME
|
from homeassistant.const import CONF_TOKEN, CONF_URL, CONF_USERNAME, CONF_VERIFY_SSL
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, load_fixture
|
from tests.common import MockConfigEntry, load_fixture
|
||||||
|
|
||||||
@ -64,6 +64,7 @@ def mock_config_entry() -> MockConfigEntry:
|
|||||||
CONF_URL: "https://ntfy.sh/",
|
CONF_URL: "https://ntfy.sh/",
|
||||||
CONF_USERNAME: None,
|
CONF_USERNAME: None,
|
||||||
CONF_TOKEN: "token",
|
CONF_TOKEN: "token",
|
||||||
|
CONF_VERIFY_SSL: True,
|
||||||
},
|
},
|
||||||
entry_id="123456789",
|
entry_id="123456789",
|
||||||
subentries_data=[
|
subentries_data=[
|
||||||
|
@ -20,6 +20,7 @@ from homeassistant.const import (
|
|||||||
CONF_TOKEN,
|
CONF_TOKEN,
|
||||||
CONF_URL,
|
CONF_URL,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
|
CONF_VERIFY_SSL,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
@ -33,17 +34,24 @@ from tests.common import MockConfigEntry
|
|||||||
(
|
(
|
||||||
{
|
{
|
||||||
CONF_URL: "https://ntfy.sh",
|
CONF_URL: "https://ntfy.sh",
|
||||||
|
CONF_VERIFY_SSL: True,
|
||||||
SECTION_AUTH: {CONF_USERNAME: "username", CONF_PASSWORD: "password"},
|
SECTION_AUTH: {CONF_USERNAME: "username", CONF_PASSWORD: "password"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
CONF_URL: "https://ntfy.sh/",
|
CONF_URL: "https://ntfy.sh/",
|
||||||
|
CONF_VERIFY_SSL: True,
|
||||||
CONF_USERNAME: "username",
|
CONF_USERNAME: "username",
|
||||||
CONF_TOKEN: "token",
|
CONF_TOKEN: "token",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
{CONF_URL: "https://ntfy.sh", SECTION_AUTH: {}},
|
{CONF_URL: "https://ntfy.sh", CONF_VERIFY_SSL: True, SECTION_AUTH: {}},
|
||||||
{CONF_URL: "https://ntfy.sh/", CONF_USERNAME: None, CONF_TOKEN: "token"},
|
{
|
||||||
|
CONF_URL: "https://ntfy.sh/",
|
||||||
|
CONF_VERIFY_SSL: True,
|
||||||
|
CONF_USERNAME: None,
|
||||||
|
CONF_TOKEN: "token",
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@ -109,6 +117,7 @@ async def test_form_errors(
|
|||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{
|
{
|
||||||
CONF_URL: "https://ntfy.sh",
|
CONF_URL: "https://ntfy.sh",
|
||||||
|
CONF_VERIFY_SSL: True,
|
||||||
SECTION_AUTH: {CONF_USERNAME: "username", CONF_PASSWORD: "password"},
|
SECTION_AUTH: {CONF_USERNAME: "username", CONF_PASSWORD: "password"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -121,6 +130,7 @@ async def test_form_errors(
|
|||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{
|
{
|
||||||
CONF_URL: "https://ntfy.sh",
|
CONF_URL: "https://ntfy.sh",
|
||||||
|
CONF_VERIFY_SSL: True,
|
||||||
SECTION_AUTH: {CONF_USERNAME: "username", CONF_PASSWORD: "password"},
|
SECTION_AUTH: {CONF_USERNAME: "username", CONF_PASSWORD: "password"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -130,6 +140,7 @@ async def test_form_errors(
|
|||||||
assert result["title"] == "ntfy.sh"
|
assert result["title"] == "ntfy.sh"
|
||||||
assert result["data"] == {
|
assert result["data"] == {
|
||||||
CONF_URL: "https://ntfy.sh/",
|
CONF_URL: "https://ntfy.sh/",
|
||||||
|
CONF_VERIFY_SSL: True,
|
||||||
CONF_USERNAME: "username",
|
CONF_USERNAME: "username",
|
||||||
CONF_TOKEN: "token",
|
CONF_TOKEN: "token",
|
||||||
}
|
}
|
||||||
@ -151,7 +162,11 @@ async def test_form_already_configured(
|
|||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
user_input={CONF_URL: "https://ntfy.sh", SECTION_AUTH: {}},
|
user_input={
|
||||||
|
CONF_URL: "https://ntfy.sh",
|
||||||
|
CONF_VERIFY_SSL: True,
|
||||||
|
SECTION_AUTH: {},
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
@ -163,7 +178,7 @@ async def test_add_topic_flow(hass: HomeAssistant) -> None:
|
|||||||
"""Test add topic subentry flow."""
|
"""Test add topic subentry flow."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
data={CONF_URL: "https://ntfy.sh/", CONF_USERNAME: None},
|
data={CONF_URL: "https://ntfy.sh/", CONF_VERIFY_SSL: True, CONF_USERNAME: None},
|
||||||
)
|
)
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
@ -211,7 +226,7 @@ async def test_generated_topic(hass: HomeAssistant, mock_random: AsyncMock) -> N
|
|||||||
"""Test add topic subentry flow with generated topic name."""
|
"""Test add topic subentry flow with generated topic name."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
data={CONF_URL: "https://ntfy.sh/"},
|
data={CONF_URL: "https://ntfy.sh/", CONF_VERIFY_SSL: True},
|
||||||
)
|
)
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
@ -265,7 +280,7 @@ async def test_invalid_topic(hass: HomeAssistant, mock_random: AsyncMock) -> Non
|
|||||||
"""Test add topic subentry flow with invalid topic name."""
|
"""Test add topic subentry flow with invalid topic name."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
data={CONF_URL: "https://ntfy.sh/"},
|
data={CONF_URL: "https://ntfy.sh/", CONF_VERIFY_SSL: True},
|
||||||
)
|
)
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user