0001-views-use-LDAPBackendPasswordLost-to-switch-to-LDAP-.patch
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 |
... | ... | |
1653 | 1653 |
} |
1654 | 1654 |
], |
1655 | 1655 |
} |
1656 | ||
1657 | ||
1658 |
def test_switch_user_ldap_user(slapd, settings, app, db): |
|
1659 |
settings.LDAP_AUTH_SETTINGS = [ |
|
1660 |
{ |
|
1661 |
'url': [slapd.ldap_url], |
|
1662 |
'binddn': force_text(slapd.root_bind_dn), |
|
1663 |
'bindpw': force_text(slapd.root_bind_password), |
|
1664 |
'basedn': u'o=ôrga', |
|
1665 |
'use_tls': False, |
|
1666 |
'attributes': ['carLicense'], |
|
1667 |
} |
|
1668 |
] |
|
1669 |
# get all users |
|
1670 |
management.call_command('sync-ldap-users', verbosity=2) |
|
1671 | ||
1672 |
user = User.objects.get(username=USERNAME + '@ldap') |
|
1673 |
url = switch_user.build_url(user) |
|
1674 |
response = app.get(url).follow() |
|
1675 |
assert app.session['_auth_user_backend'] == 'authentic2.backends.ldap_backend.LDAPBackendPasswordLost' |
|
1676 |
template_user = response.context['user'] |
|
1677 |
assert 'carlicense' in template_user.get_attributes(object(), {}) |
|
1656 |
- |