fix: correct misleading password length validation message (#37796)

This commit is contained in:
ToughGuysDeservePink 2026-06-23 17:00:16 +08:00 committed by GitHub
parent 04d226384f
commit b98ba99b23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -13,7 +13,7 @@ def valid_password(password):
if re.match(pattern, password) is not None:
return password
raise ValueError("Password must contain letters and numbers, and the length must be greater than 8.")
raise ValueError("Password must contain letters and numbers, and the length must be at least 8 characters.")
def hash_password(password_str, salt_byte):

View File

@ -35,6 +35,13 @@ class TestValidPassword:
with pytest.raises(ValueError):
valid_password("")
def test_should_reject_password_shorter_than_minimum_length(self):
"""A 7-character password with letters and numbers is rejected for length."""
with pytest.raises(ValueError) as exc_info:
valid_password("abc1234")
assert "at least 8" in str(exc_info.value)
class TestPasswordHashing:
"""Test password hashing and comparison"""