diff --git a/tests/api2/test_audit_rest.py b/tests/api2/test_audit_rest.py index 2c2daaebccdc..5e42faf10d21 100644 --- a/tests/api2/test_audit_rest.py +++ b/tests/api2/test_audit_rest.py @@ -73,7 +73,7 @@ def test_authenticated_call(): "protocol": "REST", "credentials": { "credentials": "LOGIN_PASSWORD", - "credentials_data": {"username": "root", "login_at": ANY}, + "credentials_data": {"username": "root"}, }, }, "event": "AUTHENTICATION", @@ -96,7 +96,7 @@ def test_authenticated_call(): "protocol": "REST", "credentials": { "credentials": "LOGIN_PASSWORD", - "credentials_data": {"username": "root", "login_at": ANY}, + "credentials_data": {"username": "root"}, }, }, "event": "METHOD_CALL", diff --git a/tests/api2/test_job_credentials.py b/tests/api2/test_job_credentials.py index c95984ed91d6..85e1dbc13545 100644 --- a/tests/api2/test_job_credentials.py +++ b/tests/api2/test_job_credentials.py @@ -1,5 +1,6 @@ from middlewared.test.integration.assets.account import unprivileged_user_client from middlewared.test.integration.utils import call, mock +from unittest.mock import ANY def test_job_credentials(): @@ -15,4 +16,4 @@ def mock(self, job, *args): job = call("core.get_jobs", [["id", "=", job_id]], {"get": True}) - assert job["credentials"] == {"type": "LOGIN_PASSWORD", "data": {"username": c.username}} + assert job["credentials"] == {"type": "LOGIN_PASSWORD", "data": {"username": c.username, "login_at": ANY}} diff --git a/tests/api2/test_twofactor_auth.py b/tests/api2/test_twofactor_auth.py index 89b07d77ec3e..84fb81b5da66 100644 --- a/tests/api2/test_twofactor_auth.py +++ b/tests/api2/test_twofactor_auth.py @@ -34,6 +34,11 @@ def user(data: dict): yield user_obj +@pytest.fixture(scope='function') +def clear_ratelimit(): + call('rate.limit.cache_clear') + + def do_login(username, password, otp=None, expected=True): with client(auth=None) as c: resp = c.call('auth.login_ex', { @@ -133,7 +138,7 @@ def test_login_with_otp_for_user_with_2fa(): do_login(TEST_USERNAME_2, TEST_PASSWORD_2, get_2fa_totp_token(get_user_secret(user_obj['id']))) -def test_user_2fa_secret_renewal(): +def test_user_2fa_secret_renewal(clear_ratelimit): with user({ 'username': TEST_USERNAME_2, 'password': TEST_PASSWORD_2, @@ -150,7 +155,7 @@ def test_user_2fa_secret_renewal(): do_login(TEST_USERNAME_2, TEST_PASSWORD_2, get_2fa_totp_token(get_user_secret(user_obj['id']))) -def test_restricted_user_2fa_secret_renewal(): +def test_restricted_user_2fa_secret_renewal(clear_ratelimit): with unprivileged_user( username=TEST_USERNAME, group_name='TEST_2FA_GROUP', @@ -179,7 +184,7 @@ def test_restricted_user_2fa_secret_renewal(): do_login(acct.username, acct.password, get_2fa_totp_token(get_user_secret(user_obj['id']))) -def test_multiple_users_login_with_otp(): +def test_multiple_users_login_with_otp(clear_ratelimit): with user({ 'username': TEST_USERNAME, 'password': TEST_PASSWORD,