# SPDX-FileCopyrightText: 2026 Dennis Fink # # SPDX-License-Identifier: BSD-3-Clause import pytest from webmentions_ssg.models.user import User def test_user_repr() -> None: user = User(username="admin", password="secret") assert repr(user) == "" def test_user_password_is_write_only() -> None: user = User(username="admin", password="secret") with pytest.raises(AttributeError, match="Password is write-only"): _ = user.password def test_user_password_is_hashed_and_can_be_checked() -> None: user = User(username="admin", password="secret") assert user.password_hash != "secret" assert user.check_password("secret") assert not user.check_password("wrong") def test_user_session_id_changes_when_password_hash_changes() -> None: user = User(username="admin", password="a strong passphrase", id=42) original_hash = user.password_hash original_id = user.get_id() assert original_id.startswith("42:") assert original_hash not in original_id assert len(original_id.split(":", 1)[1]) == 64 # Even a reset to the same password rehashes with a new salt, revoking # any old session token. user.password = "a strong passphrase" assert user.password_hash != original_hash assert user.get_id() != original_id