0001-WIP-ldap_backend-add-attribute-retrieval-unit-testin.patch
tests/test_ldap.py | ||
---|---|---|
26 | 26 |
DN = 'cn=%s,o=orga' % escape_dn_chars(CN) |
27 | 27 |
PASS = 'passé' |
28 | 28 |
EMAIL = 'etienne.michu@example.net' |
29 |
CARLICENSE = '123445ABC' |
|
29 | 30 | |
30 | 31 | |
31 | 32 |
@pytest.fixture |
... | ... | |
39 | 40 |
sn: Michu |
40 | 41 |
gn: Étienne |
41 | 42 |
mail: etienne.michu@example.net |
43 |
carLicense: {cl} |
|
42 | 44 | |
43 | 45 |
dn: cn=group1,o=orga |
44 | 46 |
objectClass: groupOfNames |
45 | 47 |
member: {dn} |
46 | 48 | |
47 |
'''.format(dn=DN, uid=UID, password=PASS)) |
|
49 |
'''.format(dn=DN, uid=UID, password=PASS, cl=CARLICENSE))
|
|
48 | 50 |
for i in range(100): |
49 | 51 |
slapd.add_ldif('''dn: uid=michu{i},o=orga |
50 | 52 |
objectClass: inetOrgPerson |
... | ... | |
351 | 353 | |
352 | 354 | |
353 | 355 |
@pytest.mark.django_db |
356 |
def test_get_attributes(slapd, settings, client): |
|
357 |
settings.LDAP_AUTH_SETTINGS = [{ |
|
358 |
'url': [slapd.ldap_url], |
|
359 |
'basedn': 'o=orga', |
|
360 |
'use_tls': False, |
|
361 |
'groupstaff': ['cn=group1,o=orga'], |
|
362 |
'attributes': ['uid', 'carLicense'], |
|
363 |
}] |
|
364 |
response = client.post('/login/', {'login-password-submit': '1', |
|
365 |
'username': 'etienne.michu', |
|
366 |
'password': PASS}, follow=True) |
|
367 |
user = response.context['user'] |
|
368 |
fetched_attrs = user.get_attributes() |
|
369 |
assert UID in fetched_attrs.get('uid') |
|
370 |
assert CARLICENSE in fetched_attrs.get('carlicense') |
|
371 | ||
372 | ||
373 |
@pytest.mark.django_db |
|
354 | 374 |
def test_get_users(slapd, settings): |
355 | 375 |
import django.db.models.base |
356 | 376 |
from types import MethodType |
357 |
- |