Skip to content

Commit

Permalink
Fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anodos325 committed Sep 27, 2024
1 parent 9df5d11 commit 344f44a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tests/api2/test_audit_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion tests/api2/test_job_credentials.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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}}
11 changes: 8 additions & 3 deletions tests/api2/test_twofactor_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down Expand Up @@ -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,
Expand All @@ -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',
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 344f44a

Please sign in to comment.