Migrate auth tests to use freezegun (#105243)
This commit is contained in:
parent
2daa94b600
commit
6666b796f2
2 changed files with 13 additions and 18 deletions
|
@ -894,10 +894,7 @@ async def test_auth_module_expired_session(mock_hass) -> None:
|
|||
assert step["type"] == data_entry_flow.FlowResultType.FORM
|
||||
assert step["step_id"] == "mfa"
|
||||
|
||||
with patch(
|
||||
"homeassistant.util.dt.utcnow",
|
||||
return_value=dt_util.utcnow() + MFA_SESSION_EXPIRATION,
|
||||
):
|
||||
with freeze_time(dt_util.utcnow() + MFA_SESSION_EXPIRATION):
|
||||
step = await manager.login_flow.async_configure(
|
||||
step["flow_id"], {"pin": "test-pin"}
|
||||
)
|
||||
|
|
|
@ -4,6 +4,7 @@ from http import HTTPStatus
|
|||
import logging
|
||||
from unittest.mock import patch
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
|
||||
from homeassistant.auth import InvalidAuthError
|
||||
|
@ -167,27 +168,24 @@ async def test_auth_code_checks_local_only_user(
|
|||
assert error["error"] == "access_denied"
|
||||
|
||||
|
||||
def test_auth_code_store_expiration(mock_credential) -> None:
|
||||
def test_auth_code_store_expiration(
|
||||
mock_credential, freezer: FrozenDateTimeFactory
|
||||
) -> None:
|
||||
"""Test that the auth code store will not return expired tokens."""
|
||||
store, retrieve = auth._create_auth_code_store()
|
||||
client_id = "bla"
|
||||
now = utcnow()
|
||||
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
freezer.move_to(now)
|
||||
code = store(client_id, mock_credential)
|
||||
|
||||
with patch(
|
||||
"homeassistant.util.dt.utcnow", return_value=now + timedelta(minutes=10)
|
||||
):
|
||||
freezer.move_to(now + timedelta(minutes=10))
|
||||
assert retrieve(client_id, code) is None
|
||||
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
freezer.move_to(now)
|
||||
code = store(client_id, mock_credential)
|
||||
|
||||
with patch(
|
||||
"homeassistant.util.dt.utcnow",
|
||||
return_value=now + timedelta(minutes=9, seconds=59),
|
||||
):
|
||||
freezer.move_to(now + timedelta(minutes=9, seconds=59))
|
||||
assert retrieve(client_id, code) == mock_credential
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue