diff options
| author | Dennis Fink | 2026-11-13 19:22:33 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-13 19:22:33 +0100 |
| commit | 5c1eb15f00e20ece0a4ff8e7e1b4a5ab51e54232 (patch) | |
| tree | 04b442019424db67aa8ca23c5e652d12136f9fe7 /tests/test_auth.py | |
| parent | c421d269313d6623926954935a680fe4acb1dc86 (diff) | |
| download | webmentions-ssg-5c1eb15f00e20ece0a4ff8e7e1b4a5ab51e54232.tar.gz webmentions-ssg-5c1eb15f00e20ece0a4ff8e7e1b4a5ab51e54232.zip | |
refactor(core): simplify login password verification
Replace the module-level dummy user with a lazily cached password hash
so unknown usernames still perform a password check without hashing
during every import.
Use one linear verification path for existing, missing, and empty
passwords.
Diffstat (limited to 'tests/test_auth.py')
| -rw-r--r-- | tests/test_auth.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/tests/test_auth.py b/tests/test_auth.py index 34df8ce..e026e45 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -7,7 +7,7 @@ import pytest from flask import Flask -from webmentions_ssg import db +from webmentions_ssg import auth, db from webmentions_ssg.auth import AUTH, is_safe_next_url, load_user, validate_password from webmentions_ssg.models import User @@ -22,6 +22,27 @@ def test_user_loader_is_registered(app: Flask) -> None: assert AUTH._user_callback is load_user +def test_dummy_password_hash_is_lazily_cached( + monkeypatch: pytest.MonkeyPatch, +) -> None: + generated_passwords: list[str] = [] + + def fake_generate_password_hash(password: str) -> str: + generated_passwords.append(password) + return "dummy-hash" + + auth.dummy_password_hash.cache_clear() + try: + with monkeypatch.context() as patcher: + patcher.setattr(auth, "generate_password_hash", fake_generate_password_hash) + assert generated_passwords == [] + assert auth.dummy_password_hash() == "dummy-hash" + assert auth.dummy_password_hash() == "dummy-hash" + assert len(generated_passwords) == 1 + finally: + auth.dummy_password_hash.cache_clear() + + def test_load_user_returns_matching_user(app: Flask) -> None: with app.app_context(): user = User(username="account", password="secret") |
