From 60d0a52884fb5dbca8eb4ff18ec157617471d855 Mon Sep 17 00:00:00 2001 From: Agzamus Date: Mon, 12 Oct 2026 16:22:39 +0300 Subject: [PATCH] =?UTF-8?q?feat:=205.4=20=D0=9F=D0=BE=D0=BA=D1=80=D1=8B?= =?UTF-8?q?=D1=82=D1=8C=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_passwords.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/test_passwords.py diff --git a/tests/test_passwords.py b/tests/test_passwords.py new file mode 100644 index 0000000..ab16371 --- /dev/null +++ b/tests/test_passwords.py @@ -0,0 +1,35 @@ +import pytest + +from app.core.passwords import ( + WeakPasswordError, + hash_password, + validate_policy, + verify_password, +) + +STRONG_PASSWORD = "Kz8#Fj2!Lm9@Qw4$xR" + + +# слабый пароль должен отклоняться +def test_short_password_rejected(): + with pytest.raises(WeakPasswordError): + validate_policy("short") + + +# слабый пароль должен отклоняться +@pytest.mark.parametrize("weak", ["password", "12345678", "aaaaaaaaaaaa"]) +def test_known_weak_passwords_rejected(weak): + with pytest.raises(WeakPasswordError): + validate_policy(weak) + + +# корректный – приниматься +def test_strong_password_accepted(): + validate_policy(STRONG_PASSWORD) + + +# хэш должен успешно проверяться +def test_hash_roundtrip(): + hashed = hash_password(STRONG_PASSWORD) + assert verify_password(STRONG_PASSWORD, hashed) is True + assert verify_password("definitely-wrong", hashed) is False