aboutsummaryrefslogtreecommitdiff
path: root/tests/test_auth.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_auth.py')
-rw-r--r--tests/test_auth.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/tests/test_auth.py b/tests/test_auth.py
index 3b05b6f..8219a07 100644
--- a/tests/test_auth.py
+++ b/tests/test_auth.py
@@ -10,18 +10,23 @@ import pytest
from flask import Flask
from webmentions_ssg import auth, db
-from webmentions_ssg.auth import AUTH, is_safe_next_url, load_user, validate_password
+from webmentions_ssg.auth import (
+ is_safe_next_url,
+ load_user_from_session_id,
+ login_manager,
+ validate_new_password,
+)
from webmentions_ssg.models import User
@pytest.mark.parametrize("character", ["\x00", "\x1f", "\x7f", "\x80", "\x9f"])
def test_validate_password_rejects_unicode_controls(character: str) -> None:
with pytest.raises(ValueError, match="control characters"):
- validate_password(f"valid passphrase{character}")
+ validate_new_password(f"valid passphrase{character}")
def test_user_loader_is_registered(app: Flask) -> None:
- assert AUTH._user_callback is load_user
+ assert login_manager._user_callback is load_user_from_session_id
def test_dummy_password_hash_is_lazily_cached(monkeypatch: pytest.MonkeyPatch) -> None:
@@ -48,18 +53,18 @@ def test_load_user_returns_matching_user(app: Flask) -> None:
user = User(username="account", password="secret")
db.session.add(user)
db.session.commit()
- assert load_user(user.get_id()) is user
+ assert load_user_from_session_id(user.get_id()) is user
def test_load_user_returns_none_for_unknown_id(app: Flask) -> None:
with app.app_context():
- assert load_user("99999:" + "a" * 64) is None
+ assert load_user_from_session_id("99999:" + "a" * 64) is None
@pytest.mark.parametrize("identifier", [None, 123, b"1:" + b"a" * 64])
def test_load_user_rejects_non_string_sessions(app: Flask, identifier: object) -> None:
with app.app_context():
- assert load_user(identifier) is None
+ assert load_user_from_session_id(identifier) is None
def test_load_user_rejects_legacy_and_malformed_sessions(app: Flask) -> None:
@@ -79,7 +84,7 @@ def test_load_user_rejects_legacy_and_malformed_sessions(app: Flask) -> None:
f"{user.id}:" + "0" * 64 + ":trailing",
"-1:" + "0" * 64,
):
- assert load_user(identifier) is None
+ assert load_user_from_session_id(identifier) is None
def test_password_change_invalidates_existing_session(app: Flask) -> None:
@@ -111,8 +116,8 @@ def test_password_change_invalidates_existing_session(app: Flask) -> None:
user = db.session.get(User, int(old_identifier.split(":", 1)[0]))
assert user is not None
assert user.get_id() != old_identifier
- assert load_user(old_identifier) is None
- assert load_user(user.get_id()) is user
+ assert load_user_from_session_id(old_identifier) is None
+ assert load_user_from_session_id(user.get_id()) is user
# A pre-existing, validly signed cookie no longer authenticates.
assert client.get("/received").status_code == HTTPStatus.FOUND