Expire auth code after 10 minutes (#15381)
This commit is contained in:
parent
df8c59406b
commit
dbdd0a1f56
2 changed files with 46 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue