diff options
| author | Dennis Fink | 2026-11-17 17:09:59 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-17 17:09:59 +0100 |
| commit | 6d6d079a3a99d3d3a922a640b6925eb2adf044de (patch) | |
| tree | 33cc19241f4ce86ea43b2f194087c58e3fdc8a4d /tests/models/test_user.py | |
| parent | 227092b57acc886469e16bcc4c0d3256e86d3d1e (diff) | |
| download | webmentions-ssg-6d6d079a3a99d3d3a922a640b6925eb2adf044de.tar.gz webmentions-ssg-6d6d079a3a99d3d3a922a640b6925eb2adf044de.zip | |
refactor(core)!: split forms and models by feature
Replace monolithic form and model modules with focused packages for
receiver, moderation, source, user, and shared validation concerns.
Rename source policy concepts to domain moderation, including routes,
models, tables, configuration, templates, and tests.
BREAKING CHANGE: form and model import paths, moderation routes, and
`SOURCE_ALLOWLIST_ENABLED` have changed; use `ALLOWLIST_ENABLED` and the
new feature-specific modules.
Diffstat (limited to '')
| -rw-r--r-- | tests/models/test_user.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/models/test_user.py b/tests/models/test_user.py new file mode 100644 index 0000000..a3f95ae --- /dev/null +++ b/tests/models/test_user.py @@ -0,0 +1,41 @@ +# SPDX-FileCopyrightText: 2026 Dennis Fink <me+coding@dennisfink.me> +# +# 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) == "<User admin>" + + +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 |
