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:
J. Nick Koston 2024-05-05 15:47:26 -05:00 committed by GitHub
parent c8e6292cb7
commit a57f4b8f42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 47 additions and 12 deletions

View file

@ -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 == {}