Files
xiaobaifupan/next/tests/test_passwords.py
T

21 lines
698 B
Python

import pytest
from backend.security import PasswordHasher, PasswordPolicyError
@pytest.mark.parametrize("password", ["onlyletters", "12345678", "short1!"])
def test_password_policy_rejects_weak_values(password: str) -> None:
with pytest.raises(PasswordPolicyError):
PasswordHasher().hash(password)
def test_password_hash_uses_independent_salts_and_verifies() -> None:
hasher = PasswordHasher()
first = hasher.hash("Valid-password-123!")
second = hasher.hash("Valid-password-123!")
assert first != second
assert "Valid-password-123!" not in first
assert hasher.verify("Valid-password-123!", first)
assert not hasher.verify("Wrong-password-123!", first)