Projet

Général

Profil

0001-views-use-LDAPBackendPasswordLost-to-switch-to-LDAP-.patch

Benjamin Dauvergne, 01 avril 2021 17:37

Télécharger (2,28 ko)

Voir les différences:

Subject: [PATCH] views: use LDAPBackendPasswordLost to switch to LDAP account
 (#43585)

 src/authentic2/views.py |  3 +++
 tests/test_ldap.py      | 24 +++++++++++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)
src/authentic2/views.py
1362 1362
        user = switch_user.resolve_token(uuid)
1363 1363
        if not user:
1364 1364
            raise Http404
1365
        # LDAP ad-hoc behaviour
1366
        if user.userexternalid_set.exists():
1367
            user = utils.authenticate(request, user=user)
1365 1368
        return utils.simulate_authentication(request, user, 'su')
1366 1369

  
1367 1370

  
tests/test_ldap.py
36 36
from authentic2.a2_rbac.utils import get_default_ou
37 37
from authentic2.backends import ldap_backend
38 38
from authentic2.models import Service
39
from authentic2.utils import authenticate
39
from authentic2.utils import authenticate, switch_user
40 40
from django_rbac.utils import get_ou_model
41 41

  
42 42
from . import utils
......
1652 1652
            }
1653 1653
        ],
1654 1654
    }
1655

  
1656

  
1657
def test_switch_user_ldap_user(slapd, settings, app, db):
1658
    settings.LDAP_AUTH_SETTINGS = [
1659
        {
1660
            'url': [slapd.ldap_url],
1661
            'binddn': force_text(slapd.root_bind_dn),
1662
            'bindpw': force_text(slapd.root_bind_password),
1663
            'basedn': u'o=ôrga',
1664
            'use_tls': False,
1665
            'attributes': ['carLicense'],
1666
        }
1667
    ]
1668
    # get all users
1669
    management.call_command('sync-ldap-users', verbosity=2)
1670

  
1671
    user = User.objects.get(username=USERNAME + '@ldap')
1672
    url = switch_user.build_url(user)
1673
    response = app.get(url).follow()
1674
    assert app.session['_auth_user_backend'] == 'authentic2.backends.ldap_backend.LDAPBackendPasswordLost'
1675
    template_user = response.context['user']
1676
    assert 'carlicense' in template_user.get_attributes(object(), {})
1655
-