Strip the NYT Games token (#127548)
This commit is contained in:
parent
ae8219dc97
commit
ebfa2fb1d0
2 changed files with 26 additions and 2 deletions
|
@ -22,7 +22,8 @@ class NYTGamesConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
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:
|
||||
|
@ -35,7 +36,9 @@ class NYTGamesConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
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}),
|
||||
|
|
|
@ -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"),
|
||||
[
|
||||
|
|
Loading…
Add table
Reference in a new issue