mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Exclude access token from host info updates in Konnected config flow (#33912)
* black updates * test that host update doesn't impact access token
This commit is contained in:
parent
127cc744a4
commit
c2d1db61b6
@ -283,11 +283,6 @@ class KonnectedFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
# build config info and wait for user confirmation
|
# build config info and wait for user confirmation
|
||||||
self.data[CONF_HOST] = user_input[CONF_HOST]
|
self.data[CONF_HOST] = user_input[CONF_HOST]
|
||||||
self.data[CONF_PORT] = user_input[CONF_PORT]
|
self.data[CONF_PORT] = user_input[CONF_PORT]
|
||||||
self.data[CONF_ACCESS_TOKEN] = self.hass.data.get(DOMAIN, {}).get(
|
|
||||||
CONF_ACCESS_TOKEN
|
|
||||||
) or "".join(
|
|
||||||
random.choices(f"{string.ascii_uppercase}{string.digits}", k=20)
|
|
||||||
)
|
|
||||||
|
|
||||||
# brief delay to allow processing of recent status req
|
# brief delay to allow processing of recent status req
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
@ -343,8 +338,12 @@ class KonnectedFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
# Attach default options and create entry
|
# Create access token, attach default options and create entry
|
||||||
self.data[CONF_DEFAULT_OPTIONS] = self.options
|
self.data[CONF_DEFAULT_OPTIONS] = self.options
|
||||||
|
self.data[CONF_ACCESS_TOKEN] = self.hass.data.get(DOMAIN, {}).get(
|
||||||
|
CONF_ACCESS_TOKEN
|
||||||
|
) or "".join(random.choices(f"{string.ascii_uppercase}{string.digits}", k=20))
|
||||||
|
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=KONN_PANEL_MODEL_NAMES[self.data[CONF_MODEL]], data=self.data,
|
title=KONN_PANEL_MODEL_NAMES[self.data[CONF_MODEL]], data=self.data,
|
||||||
)
|
)
|
||||||
|
@ -362,10 +362,11 @@ async def test_ssdp_host_update(hass, mock_panel):
|
|||||||
)
|
)
|
||||||
assert result["type"] == "abort"
|
assert result["type"] == "abort"
|
||||||
|
|
||||||
# confirm the host value was updated
|
# confirm the host value was updated, access_token was not
|
||||||
entry = hass.config_entries.async_entries(config_flow.DOMAIN)[0]
|
entry = hass.config_entries.async_entries(config_flow.DOMAIN)[0]
|
||||||
assert entry.data["host"] == "1.1.1.1"
|
assert entry.data["host"] == "1.1.1.1"
|
||||||
assert entry.data["port"] == 1234
|
assert entry.data["port"] == 1234
|
||||||
|
assert entry.data["access_token"] == "11223344556677889900"
|
||||||
|
|
||||||
|
|
||||||
async def test_import_existing_config(hass, mock_panel):
|
async def test_import_existing_config(hass, mock_panel):
|
||||||
@ -494,6 +495,7 @@ async def test_import_existing_config_entry(hass, mock_panel):
|
|||||||
data={
|
data={
|
||||||
"host": "0.0.0.0",
|
"host": "0.0.0.0",
|
||||||
"port": 1111,
|
"port": 1111,
|
||||||
|
"access_token": "ORIGINALTOKEN",
|
||||||
"id": "112233445566",
|
"id": "112233445566",
|
||||||
"extra": "something",
|
"extra": "something",
|
||||||
},
|
},
|
||||||
@ -546,14 +548,14 @@ async def test_import_existing_config_entry(hass, mock_panel):
|
|||||||
|
|
||||||
assert result["type"] == "abort"
|
assert result["type"] == "abort"
|
||||||
|
|
||||||
# We should have updated the entry
|
# We should have updated the host info but not the access token
|
||||||
assert len(hass.config_entries.async_entries("konnected")) == 1
|
assert len(hass.config_entries.async_entries("konnected")) == 1
|
||||||
assert hass.config_entries.async_entries("konnected")[0].data == {
|
assert hass.config_entries.async_entries("konnected")[0].data == {
|
||||||
"host": "1.2.3.4",
|
"host": "1.2.3.4",
|
||||||
"port": 1234,
|
"port": 1234,
|
||||||
|
"access_token": "ORIGINALTOKEN",
|
||||||
"id": "112233445566",
|
"id": "112233445566",
|
||||||
"model": "Konnected Pro",
|
"model": "Konnected Pro",
|
||||||
"access_token": "SUPERSECRETTOKEN",
|
|
||||||
"extra": "something",
|
"extra": "something",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user