mirror of https://github.com/home-assistant/core
Add exception for NoURLAvailableError in OAuth2FlowHandler (#39845)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
162c39258e
commit
0cce35b23e
|
@ -10,7 +10,8 @@
|
|||
"abort": {
|
||||
"already_setup": "You can only configure one Almond account.",
|
||||
"cannot_connect": "Unable to connect to the Almond server.",
|
||||
"missing_configuration": "Please check the documentation on how to set up Almond."
|
||||
"missing_configuration": "Please check the documentation on how to set up Almond.",
|
||||
"no_url_available": "[%key:common::config_flow::abort::oauth2_no_url_available%]"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
}
|
||||
},
|
||||
"abort": {
|
||||
"missing_configuration": "The Home Connect component is not configured. Please follow the documentation."
|
||||
"missing_configuration": "The Home Connect component is not configured. Please follow the documentation.",
|
||||
"no_url_available": "[%key:common::config_flow::abort::oauth2_no_url_available%]"
|
||||
},
|
||||
"create_entry": {
|
||||
"default": "Successfully authenticated with Home Connect."
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
"abort": {
|
||||
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]",
|
||||
"authorize_url_timeout": "[%key:common::config_flow::abort::oauth2_authorize_url_timeout%]",
|
||||
"missing_configuration": "[%key:common::config_flow::abort::oauth2_missing_configuration%]"
|
||||
"missing_configuration": "[%key:common::config_flow::abort::oauth2_missing_configuration%]",
|
||||
"no_url_available": "[%key:common::config_flow::abort::oauth2_no_url_available%]"
|
||||
},
|
||||
"create_entry": {
|
||||
"default": "[%key:common::config_flow::create_entry::authenticated%]"
|
||||
|
@ -39,4 +40,4 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +1,35 @@
|
|||
{
|
||||
"config": {
|
||||
"flow_title": "Smappee: {name}",
|
||||
"step": {
|
||||
"environment": {
|
||||
"description": "Set up your Smappee to integrate with Home Assistant.",
|
||||
"data": {
|
||||
"environment": "Environment"
|
||||
}
|
||||
},
|
||||
"local": {
|
||||
"description": "Enter the host to initiate the Smappee local integration",
|
||||
"data": {
|
||||
"host": "[%key:common::config_flow::data::host%]"
|
||||
}
|
||||
},
|
||||
"zeroconf_confirm": {
|
||||
"description": "Do you want to add the Smappee device with serialnumber `{serialnumber}` to Home Assistant?",
|
||||
"title": "Discovered Smappee device"
|
||||
},
|
||||
"pick_implementation": {
|
||||
"title": "Pick Authentication Method"
|
||||
}
|
||||
},
|
||||
"abort": {
|
||||
"already_configured_device": "[%key:common::config_flow::abort::already_configured_device%]",
|
||||
"already_configured_local_device": "Local device(s) is already configured. Please remove those first before configuring a cloud device.",
|
||||
"authorize_url_timeout": "Timeout generating authorize url.",
|
||||
"connection_error": "Failed to connect to Smappee device.",
|
||||
"missing_configuration": "The component is not configured. Please follow the documentation.",
|
||||
"invalid_mdns": "Unsupported device for the Smappee integration."
|
||||
"config": {
|
||||
"flow_title": "Smappee: {name}",
|
||||
"step": {
|
||||
"environment": {
|
||||
"description": "Set up your Smappee to integrate with Home Assistant.",
|
||||
"data": {
|
||||
"environment": "Environment"
|
||||
}
|
||||
},
|
||||
"local": {
|
||||
"description": "Enter the host to initiate the Smappee local integration",
|
||||
"data": {
|
||||
"host": "[%key:common::config_flow::data::host%]"
|
||||
}
|
||||
},
|
||||
"zeroconf_confirm": {
|
||||
"description": "Do you want to add the Smappee device with serialnumber `{serialnumber}` to Home Assistant?",
|
||||
"title": "Discovered Smappee device"
|
||||
},
|
||||
"pick_implementation": {
|
||||
"title": "Pick Authentication Method"
|
||||
}
|
||||
},
|
||||
"abort": {
|
||||
"already_configured_device": "[%key:common::config_flow::abort::already_configured_device%]",
|
||||
"already_configured_local_device": "Local device(s) is already configured. Please remove those first before configuring a cloud device.",
|
||||
"authorize_url_timeout": "Timeout generating authorize url.",
|
||||
"connection_error": "Failed to connect to Smappee device.",
|
||||
"missing_configuration": "The component is not configured. Please follow the documentation.",
|
||||
"invalid_mdns": "Unsupported device for the Smappee integration.",
|
||||
"no_url_available": "[%key:common::config_flow::abort::oauth2_no_url_available%]"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
"abort": {
|
||||
"already_setup": "You can only configure one Somfy account.",
|
||||
"authorize_url_timeout": "Timeout generating authorize url.",
|
||||
"missing_configuration": "The Somfy component is not configured. Please follow the documentation."
|
||||
"missing_configuration": "The Somfy component is not configured. Please follow the documentation.",
|
||||
"no_url_available": "[%key:common::config_flow::abort::oauth2_no_url_available%]"
|
||||
},
|
||||
"create_entry": { "default": "Successfully authenticated with Somfy." }
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
"abort": {
|
||||
"already_setup": "You can only configure one Spotify account.",
|
||||
"authorize_url_timeout": "Timeout generating authorize url.",
|
||||
"no_url_available": "[%key:common::config_flow::abort::oauth2_no_url_available%]",
|
||||
"missing_configuration": "The Spotify integration is not configured. Please follow the documentation.",
|
||||
"reauth_account_mismatch": "The Spotify account authenticated with, does not match the account needed re-authentication."
|
||||
},
|
||||
|
|
|
@ -17,7 +17,8 @@
|
|||
"authorize_url_fail": "Unknown error generating an authorize url.",
|
||||
"authorize_url_timeout": "[%key:common::config_flow::abort::oauth2_authorize_url_timeout%]",
|
||||
"missing_configuration": "[%key:common::config_flow::abort::oauth2_missing_configuration%]",
|
||||
"no_agreements": "This account has no Toon displays."
|
||||
"no_agreements": "This account has no Toon displays.",
|
||||
"no_url_available": "[%key:common::config_flow::abort::oauth2_no_url_available%]"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
"abort": {
|
||||
"authorize_url_timeout": "Timeout generating authorize url.",
|
||||
"missing_configuration": "The Withings integration is not configured. Please follow the documentation.",
|
||||
"already_configured": "Configuration updated for profile."
|
||||
"already_configured": "Configuration updated for profile.",
|
||||
"no_url_available": "[%key:common::config_flow::abort::oauth2_no_url_available%]"
|
||||
},
|
||||
"create_entry": { "default": "Successfully authenticated with Withings." }
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ from yarl import URL
|
|||
from homeassistant import config_entries
|
||||
from homeassistant.components.http import HomeAssistantView
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.network import get_url
|
||||
from homeassistant.helpers.network import NoURLAvailableError, get_url
|
||||
|
||||
from .aiohttp_client import async_get_clientsession
|
||||
|
||||
|
@ -251,6 +251,13 @@ class AbstractOAuth2FlowHandler(config_entries.ConfigFlow, metaclass=ABCMeta):
|
|||
url = await self.flow_impl.async_generate_authorize_url(self.flow_id)
|
||||
except asyncio.TimeoutError:
|
||||
return self.async_abort(reason="authorize_url_timeout")
|
||||
except NoURLAvailableError:
|
||||
return self.async_abort(
|
||||
reason="no_url_available",
|
||||
description_placeholders={
|
||||
"docs_url": "https://www.home-assistant.io/more-info/no-url-available"
|
||||
},
|
||||
)
|
||||
|
||||
url = str(URL(url).update_query(self.extra_authorize_data))
|
||||
|
||||
|
|
|
@ -53,7 +53,8 @@
|
|||
"already_configured_device": "Device is already configured",
|
||||
"no_devices_found": "No devices found on the network",
|
||||
"oauth2_missing_configuration": "The component is not configured. Please follow the documentation.",
|
||||
"oauth2_authorize_url_timeout": "Timeout generating authorize URL."
|
||||
"oauth2_authorize_url_timeout": "Timeout generating authorize URL.",
|
||||
"oauth2_no_url_available": "No URL available. For information about this error, [check the help section]({docs_url})"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import pytest
|
|||
from homeassistant import config_entries, data_entry_flow, setup
|
||||
from homeassistant.config import async_process_ha_core_config
|
||||
from homeassistant.helpers import config_entry_oauth2_flow
|
||||
from homeassistant.helpers.network import NoURLAvailableError
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry, mock_platform
|
||||
|
@ -128,6 +129,22 @@ async def test_abort_if_authorization_timeout(hass, flow_handler, local_impl):
|
|||
assert result["reason"] == "authorize_url_timeout"
|
||||
|
||||
|
||||
async def test_abort_if_no_url_available(hass, flow_handler, local_impl):
|
||||
"""Check no_url_available generating authorization url."""
|
||||
flow_handler.async_register_implementation(hass, local_impl)
|
||||
|
||||
flow = flow_handler()
|
||||
flow.hass = hass
|
||||
|
||||
with patch.object(
|
||||
local_impl, "async_generate_authorize_url", side_effect=NoURLAvailableError
|
||||
):
|
||||
result = await flow.async_step_user()
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "no_url_available"
|
||||
|
||||
|
||||
async def test_abort_if_oauth_error(
|
||||
hass, flow_handler, local_impl, aiohttp_client, aioclient_mock, current_request
|
||||
):
|
||||
|
|
Loading…
Reference in New Issue