Index auth token ids to avoid linear search (#116583)
* Index auth token ids to avoid linear search * async_remove_refresh_token * coverage
This commit is contained in:
parent
c8e6292cb7
commit
a57f4b8f42
2 changed files with 47 additions and 12 deletions
|
@ -305,3 +305,24 @@ async def test_loading_does_not_write_right_away(
|
|||
# Once for the task
|
||||
await hass.async_block_till_done()
|
||||
assert hass_storage[auth_store.STORAGE_KEY] != {}
|
||||
|
||||
|
||||
async def test_add_remove_user_affects_tokens(
|
||||
hass: HomeAssistant, hass_storage: dict[str, Any]
|
||||
) -> None:
|
||||
"""Test adding and removing a user removes the tokens."""
|
||||
store = auth_store.AuthStore(hass)
|
||||
await store.async_load()
|
||||
user = await store.async_create_user("Test User")
|
||||
assert user.name == "Test User"
|
||||
refresh_token = await store.async_create_refresh_token(
|
||||
user, "client_id", "access_token_expiration"
|
||||
)
|
||||
assert user.refresh_tokens == {refresh_token.id: refresh_token}
|
||||
assert await store.async_get_user(user.id) == user
|
||||
assert store.async_get_refresh_token(refresh_token.id) == refresh_token
|
||||
assert store.async_get_refresh_token_by_token(refresh_token.token) == refresh_token
|
||||
await store.async_remove_user(user)
|
||||
assert store.async_get_refresh_token(refresh_token.id) is None
|
||||
assert store.async_get_refresh_token_by_token(refresh_token.token) is None
|
||||
assert user.refresh_tokens == {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue