feat: Use secure random tokens for authentication and password handling in tests
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import secrets
|
||||
from collections.abc import Iterator
|
||||
|
||||
import pytest
|
||||
@@ -32,16 +33,17 @@ def session(engine) -> Iterator[Session]:
|
||||
|
||||
|
||||
def test_user_password_helpers() -> None:
|
||||
new_password = secrets.token_urlsafe(16)
|
||||
user = User(
|
||||
email="user@example.com",
|
||||
username="example",
|
||||
password_hash=User.hash_password("initial"),
|
||||
)
|
||||
|
||||
user.set_password("new-secret")
|
||||
user.set_password(new_password)
|
||||
|
||||
assert user.password_hash != "new-secret"
|
||||
assert user.verify_password("new-secret")
|
||||
assert user.password_hash != new_password
|
||||
assert user.verify_password(new_password)
|
||||
assert not user.verify_password("wrong")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user