forms/authn: define explicit fields order (#72430)
gitea/authentic/pipeline/head Something is wrong with the build of this commit Details

This commit is contained in:
Paul Marillonnet 2022-12-14 17:05:48 +01:00
parent 73ac9f079a
commit 86f919e306
2 changed files with 42 additions and 1 deletions

View File

@ -59,6 +59,8 @@ class AuthenticationForm(auth_forms.AuthenticationForm):
queryset=OU.objects.all(),
)
field_order = ['username', 'phone', 'password', 'ou', 'remember_me']
def __init__(self, *args, **kwargs):
preferred_ous = kwargs.pop('preferred_ous', [])
self.authenticator = kwargs.pop('authenticator')

View File

@ -21,7 +21,7 @@ from django.contrib.auth import get_user_model
from authentic2 import models
from authentic2.apps.authenticators.models import LoginPasswordAuthenticator
from authentic2.utils.misc import get_token_login_url
from authentic2.utils.misc import get_authenticators, get_token_login_url
from .utils import assert_event, login, set_service
@ -96,6 +96,45 @@ def test_required_username_identifier(db, app, settings, caplog):
assert response.pyquery('span.optional')
def test_login_form_fields_order(db, app, settings, ou1, ou2):
response = app.get('/login/')
assert list(response.form.fields.keys()) == [
'csrfmiddlewaretoken',
'username',
'password',
'login-password-submit',
]
settings.A2_ACCEPT_PHONE_AUTHENTICATION = True
response = app.get('/login/')
assert list(response.form.fields.keys()) == [
'csrfmiddlewaretoken',
'username',
'phone_0',
'phone_1',
'password',
'login-password-submit',
]
authn = get_authenticators()[0]
authn.remember_me = True
authn.include_ou_selector = True
authn.save()
response = app.get('/login/')
assert list(response.form.fields.keys()) == [
'csrfmiddlewaretoken',
'username',
'phone_0',
'phone_1',
'password',
'ou',
'remember_me',
'login-password-submit',
]
def test_login_inactive_user(db, app):
user1 = User.objects.create(username='john.doe')
user1.set_password('john.doe')