fix(auth): reject excess login concurrency before Argon2 work

This commit is contained in:
2026-11-20 20:49:27 +03:00
parent 8326754831
commit eb90f9239b
5 changed files with 138 additions and 8 deletions
+25
View File
@@ -216,3 +216,28 @@ def test_operator_token_cache_is_invalidated_when_client_certificate_changes(
assert len(calls) == 1
finally:
second.close()
def test_busy_login_is_rejected_before_password_verification(monkeypatch):
from src.password import Passwords
passwords = Passwords()
calls = []
from types import SimpleNamespace
monkeypatch.setattr(
passwords,
"hasher",
SimpleNamespace(verify=lambda *args: calls.append(args)),
)
assert passwords.slots.acquire(blocking=False)
assert passwords.slots.acquire(blocking=False)
try:
with pytest.raises(DomainError) as rejected:
passwords.verify(password="Synthetic-password", encoded=None)
assert rejected.value.status == 429
assert rejected.value.headers["Retry-After"] == "1"
assert not calls
finally:
passwords.slots.release()
passwords.slots.release()