aboutsummaryrefslogtreecommitdiff
path: root/tests/test_models.py
diff options
context:
space:
mode:
authorDennis Fink2026-10-31 16:42:44 +0100
committerDennis Fink2026-10-31 16:42:44 +0100
commit3494eab1208dc18478485e02c61e292556502fa6 (patch)
tree5d9e95d709b119a0245d0294837f9b6a7e38bff1 /tests/test_models.py
parentfdb1762715658eae987dd104a0e6d3cb92a4a8d7 (diff)
downloadwebmentions-ssg-3494eab1208dc18478485e02c61e292556502fa6.tar.gz
webmentions-ssg-3494eab1208dc18478485e02c61e292556502fa6.zip
fix(core): harden session and credential security
Require persistent non-placeholder signing keys outside local development and bind login sessions to the current password hash so password changes revoke existing cookies. Enforce a minimal password policy for user administration while preserving long Unicode passphrases without arbitrary composition limits.
Diffstat (limited to '')
-rw-r--r--tests/test_models.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/test_models.py b/tests/test_models.py
index 2fa2cb8..392b246 100644
--- a/tests/test_models.py
+++ b/tests/test_models.py
@@ -146,3 +146,19 @@ def test_source_repr() -> None:
def test_sent_webmention_repr() -> None:
webmention = SentWebmention(target="https://example.com/post", desired_revision=1)
assert repr(webmention) == "<SentWebmention 'https://example.com/post'>"
+
+
+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