From 59e9010b653fd7616c6c75801a3edb88ae6df687 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Tue, 6 Feb 2024 23:03:35 +0100 Subject: [PATCH] Show domain in oauth2 error log (#109708) * Show token url in oauth2 error log * Fix tests * Use domain --- homeassistant/helpers/config_entry_oauth2_flow.py | 5 ++++- tests/helpers/test_config_entry_oauth2_flow.py | 10 +++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/homeassistant/helpers/config_entry_oauth2_flow.py b/homeassistant/helpers/config_entry_oauth2_flow.py index f2f3f63b06e..fc740aa8a4b 100644 --- a/homeassistant/helpers/config_entry_oauth2_flow.py +++ b/homeassistant/helpers/config_entry_oauth2_flow.py @@ -209,7 +209,10 @@ class LocalOAuth2Implementation(AbstractOAuth2Implementation): error_code = error_response.get("error", "unknown") error_description = error_response.get("error_description", "unknown error") _LOGGER.error( - "Token request failed (%s): %s", error_code, error_description + "Token request for %s failed (%s): %s", + self.domain, + error_code, + error_description, ) resp.raise_for_status() return cast(dict, await resp.json()) diff --git a/tests/helpers/test_config_entry_oauth2_flow.py b/tests/helpers/test_config_entry_oauth2_flow.py index 5deb88cab43..0f4812082ee 100644 --- a/tests/helpers/test_config_entry_oauth2_flow.py +++ b/tests/helpers/test_config_entry_oauth2_flow.py @@ -395,19 +395,19 @@ async def test_abort_discovered_multiple( HTTPStatus.UNAUTHORIZED, {}, "oauth_unauthorized", - "Token request failed (unknown): unknown", + "Token request for oauth2_test failed (unknown): unknown", ), ( HTTPStatus.NOT_FOUND, {}, "oauth_failed", - "Token request failed (unknown): unknown", + "Token request for oauth2_test failed (unknown): unknown", ), ( HTTPStatus.INTERNAL_SERVER_ERROR, {}, "oauth_failed", - "Token request failed (unknown): unknown", + "Token request for oauth2_test failed (unknown): unknown", ), ( HTTPStatus.BAD_REQUEST, @@ -417,7 +417,7 @@ async def test_abort_discovered_multiple( "error_uri": "See the full API docs at https://authorization-server.com/docs/access_token", }, "oauth_failed", - "Token request failed (invalid_request): Request was missing the", + "Token request for oauth2_test failed (invalid_request): Request was missing the", ), ], ) @@ -540,7 +540,7 @@ async def test_abort_if_oauth_token_closing_error( with caplog.at_level(logging.DEBUG): result = await hass.config_entries.flow.async_configure(result["flow_id"]) - assert "Token request failed (unknown): unknown" in caplog.text + assert "Token request for oauth2_test failed (unknown): unknown" in caplog.text assert result["type"] == data_entry_flow.FlowResultType.ABORT assert result["reason"] == "oauth_unauthorized"