Skip to content

Commit

Permalink
Strip the NYT Games token (#127548)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored Oct 4, 2024
1 parent ae8219d commit ebfa2fb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions homeassistant/components/nyt_games/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ async def async_step_user(
errors: dict[str, str] = {}
if user_input:
session = async_create_clientsession(self.hass)
client = NYTGamesClient(user_input[CONF_TOKEN], session=session)
token = user_input[CONF_TOKEN].strip()
client = NYTGamesClient(token, session=session)
try:
user_id = await client.get_user_id()
except NYTGamesAuthenticationError:
Expand All @@ -35,7 +36,9 @@ async def async_step_user(
else:
await self.async_set_unique_id(str(user_id))
self._abort_if_unique_id_configured()
return self.async_create_entry(title="NYT Games", data=user_input)
return self.async_create_entry(
title="NYT Games", data={CONF_TOKEN: token}
)
return self.async_show_form(
step_id="user",
data_schema=vol.Schema({vol.Required(CONF_TOKEN): str}),
Expand Down
21 changes: 21 additions & 0 deletions tests/components/nyt_games/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@ async def test_full_flow(
assert result["result"].unique_id == "218886794"


async def test_stripping_token(
hass: HomeAssistant,
mock_nyt_games_client: AsyncMock,
mock_setup_entry: AsyncMock,
) -> None:
"""Test stripping token."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"

result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_TOKEN: " token "},
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["data"] == {CONF_TOKEN: "token"}


@pytest.mark.parametrize(
("exception", "error"),
[
Expand Down

0 comments on commit ebfa2fb

Please sign in to comment.