Project

General

Profile

0001-utils-set-LDAP-auth-backend-when-resetting-password-.patch

Benjamin Dauvergne, 01 April 2021 05:07 PM

Download (2.03 KB)

View differences:

Subject: [PATCH] utils: set LDAP auth backend when resetting password of an
 LDAP account (#52638)

 src/authentic2/utils/__init__.py | 15 ++++++++-------
 tests/test_ldap.py               |  1 +
 2 files changed, 9 insertions(+), 7 deletions(-)
src/authentic2/utils/__init__.py
1150 1150
    return True
1151 1151

  
1152 1152

  
1153
def simulate_authentication(
1154
    request, user, method, backend='authentic2.backends.models_backend.ModelBackend', service=None, **kwargs
1155
):
1156
    '''Simulate a normal login by forcing a backend attribute on the user instance'''
1157
    # do not modify the passed user
1158
    user = copy.deepcopy(user)
1159
    user.backend = backend
1153
def simulate_authentication(request, user, method, backend=None, service=None, **kwargs):
1154
    '''Simulate a normal login by eventually forcing a backend attribute on the
1155
       user instance'''
1156
    if not getattr(user, 'backend', None) and not backend:
1157
        backend = 'authentic2.backends.models_backend.ModelBackend'
1158
    if backend:
1159
        user = copy.deepcopy(user)
1160
        user.backend = backend
1160 1161
    return login(request, user, method, service=service, record=False, **kwargs)
1161 1162

  
1162 1163

  
tests/test_ldap.py
878 878
    response.form['new_password1'] = new_password
879 879
    response.form['new_password2'] = new_password
880 880
    response = response.form.submit(status=302).maybe_follow()
881
    assert app.session['_auth_user_backend'] == 'authentic2.backends.ldap_backend.LDAPBackendPasswordLost'
881 882
    # logout
882 883
    response = response.click('Logout').maybe_follow()
883 884
    return new_password
884
-