mirror of
https://github.com/home-assistant/core.git
synced 2025-12-22 03:49:36 +00:00
Expire auth code after 10 minutes (#15381)
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
"""Integration tests for the auth component."""
|
||||
from datetime import timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.util.dt import utcnow
|
||||
from homeassistant.components import auth
|
||||
|
||||
from . import async_setup_auth
|
||||
|
||||
from tests.common import CLIENT_ID, CLIENT_REDIRECT_URI
|
||||
@@ -58,3 +64,25 @@ async def test_login_new_user_and_refresh_token(hass, aiohttp_client):
|
||||
'authorization': 'Bearer {}'.format(tokens['access_token'])
|
||||
})
|
||||
assert resp.status == 200
|
||||
|
||||
|
||||
def test_credential_store_expiration():
|
||||
"""Test that the credential store will not return expired tokens."""
|
||||
store, retrieve = auth._create_cred_store()
|
||||
client_id = 'bla'
|
||||
credentials = 'creds'
|
||||
now = utcnow()
|
||||
|
||||
with patch('homeassistant.util.dt.utcnow', return_value=now):
|
||||
code = store(client_id, credentials)
|
||||
|
||||
with patch('homeassistant.util.dt.utcnow',
|
||||
return_value=now + timedelta(minutes=10)):
|
||||
assert retrieve(client_id, code) is None
|
||||
|
||||
with patch('homeassistant.util.dt.utcnow', return_value=now):
|
||||
code = store(client_id, credentials)
|
||||
|
||||
with patch('homeassistant.util.dt.utcnow',
|
||||
return_value=now + timedelta(minutes=9, seconds=59)):
|
||||
assert retrieve(client_id, code) == credentials
|
||||
|
||||
Reference in New Issue
Block a user