diff options
| author | Dennis Fink | 2026-11-17 21:23:57 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-17 21:23:57 +0100 |
| commit | acd1f42847786963fc4aaeed884c3091700c9e35 (patch) | |
| tree | 5a126bdfd96e69c985137bb2a3db8d9066ecd12d /tests/forms/test_user.py | |
| parent | c4c17e3e046a627a7d2353c734bc69f05d4fc3b1 (diff) | |
| download | webmentions-ssg-acd1f42847786963fc4aaeed884c3091700c9e35.tar.gz webmentions-ssg-acd1f42847786963fc4aaeed884c3091700c9e35.zip | |
feat(core): add user account page
Add an authenticated user page showing the current username and remote
address, including guidance for validating reverse-proxy hop
configuration.
Allow users to change their own password through a CSRF-protected
WTForms form while preserving the active session and invalidating other
existing sessions.
Diffstat (limited to '')
| -rw-r--r-- | tests/forms/test_user.py | 83 |
1 files changed, 82 insertions, 1 deletions
diff --git a/tests/forms/test_user.py b/tests/forms/test_user.py index 4b35a9a..216b0dc 100644 --- a/tests/forms/test_user.py +++ b/tests/forms/test_user.py @@ -6,7 +6,7 @@ import pytest from flask import Flask from werkzeug.datastructures import MultiDict -from webmentions_ssg.forms.user import LoginForm +from webmentions_ssg.forms.user import ChangePasswordForm, LoginForm @pytest.mark.parametrize( @@ -33,3 +33,84 @@ def test_login_form_accepts_credentials(app: Flask) -> None: meta={"csrf": False}, ) assert form.validate() + + +@pytest.mark.parametrize( + ("password", "error"), + [ + pytest.param("short", "at least 8 characters", id="too-short"), + pytest.param("valid\x00password", "control characters", id="control-character"), + ], +) +def test_change_password_form_uses_shared_password_policy( + app: Flask, password: str, error: str +) -> None: + with app.test_request_context("/user", method="POST"): + form = ChangePasswordForm( + formdata=MultiDict( + { + "current_password": "old password", + "new_password": password, + "confirm_password": password, + } + ), + meta={"csrf": False}, + ) + + assert not form.validate() + assert any(error in message for message in form.errors["new_password"]) + + +def test_change_password_form_rejects_mismatched_confirmation(app: Flask) -> None: + with app.test_request_context("/user", method="POST"): + form = ChangePasswordForm( + formdata=MultiDict( + { + "current_password": "old password", + "new_password": "new password", + "confirm_password": "different password", + } + ), + meta={"csrf": False}, + ) + + assert not form.validate() + assert "Passwords must match." in form.errors["confirm_password"] + + +@pytest.mark.parametrize( + "missing_field", ["current_password", "new_password", "confirm_password"] +) +def test_change_password_form_requires_all_fields( + app: Flask, missing_field: str +) -> None: + form_data = { + "current_password": "old password", + "new_password": "new password", + "confirm_password": "new password", + } + del form_data[missing_field] + with app.test_request_context("/user", method="POST"): + form = ChangePasswordForm(formdata=MultiDict(form_data), meta={"csrf": False}) + + assert not form.validate() + assert "This field is required." in form.errors[missing_field] + + +@pytest.mark.parametrize("password", [" ", "pāssword🐈"]) +def test_change_password_form_accepts_valid_unicode_and_whitespace_passwords( + app: Flask, password: str +) -> None: + with app.test_request_context("/user", method="POST"): + form = ChangePasswordForm( + formdata=MultiDict( + { + "current_password": "old password", + "new_password": password, + "confirm_password": password, + } + ), + meta={"csrf": False}, + ) + + assert form.validate() |
