Debian Codegraph @

tests/apps/account/test_password_autocomplete.py

raw
1 """
2 Regression tests for autocomplete="new-password" on the password
3 confirmation field.
4
5 Password managers and browsers use autocomplete="new-password" to identify
6 the field(s) that a freshly suggested password should be filled into. When
7 only the first password field carries the attribute, a suggested password is
8 filled into password1 but not password2, forcing the user to copy/type the
9 confirmation by hand. Both fields of a "set a new password" pair must
10 therefore carry the same autocomplete value.
11 """
12
13 import pytest
14
15 from allauth.account.forms import (
16 ChangePasswordForm,
17 ResetPasswordKeyForm,
18 SetPasswordForm,
19 )
20
21
22 @pytest.mark.parametrize(
23 "form_class",
24 [ChangePasswordForm, SetPasswordForm, ResetPasswordKeyForm],
25 )
26 def test_both_password_fields_have_new_password_autocomplete(form_class):
27 form = form_class()
28 for field_name in ("password1", "password2"):
29 rendered = str(form[field_name])
30 assert 'autocomplete="new-password"' in rendered, (
31 f"{form_class.__name__}.{field_name} is missing "
32 f'autocomplete="new-password"'
33 )