2020-09-30 18:42:28 +02:00
|
|
|
from phi.ldap.user import get_user_by_uid, get_users_by_ou
|
2017-12-23 17:10:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_connection(ldap_client):
|
|
|
|
assert ldap_client.connection.closed is False
|
|
|
|
assert ldap_client.connection.bound is True
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_user_by_id(ldap_client):
|
|
|
|
entry = get_user_by_uid(ldap_client, 'conte_mascetti')
|
|
|
|
assert entry['uid'] == 'conte_mascetti'
|
|
|
|
assert entry['mail'] == 'rmascetti@autistici.org'
|
2020-09-30 18:42:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_get_users_by_ou(ldap_client):
|
|
|
|
users = get_users_by_ou(ldap_client, 'Hackers')
|
|
|
|
|
|
|
|
assert 'conte_mascetti' in [u['uid'] for u in users]
|
2020-10-03 18:42:18 +02:00
|
|
|
|
|
|
|
|
2020-10-04 16:47:33 +02:00
|
|
|
def test_add_delete_user(ldap_client):
|
2020-10-03 18:42:18 +02:00
|
|
|
client = ldap_client
|
|
|
|
|
|
|
|
cn = 'Rosa'
|
|
|
|
sn = 'Rossi'
|
|
|
|
mail = 'foo@autistici.org'
|
|
|
|
uid = 'rosa_rossi'
|
|
|
|
|
2020-10-04 16:47:33 +02:00
|
|
|
dn = 'uid={},ou=Hackers,{}'.format(uid, client.base_dn)
|
2020-10-03 18:42:18 +02:00
|
|
|
|
|
|
|
response_id = client.connection.add(
|
|
|
|
dn,
|
|
|
|
attributes={
|
|
|
|
'objectClass': [
|
|
|
|
'inetOrgPerson',
|
|
|
|
'organizationalPerson',
|
|
|
|
'person', 'top'
|
|
|
|
],
|
|
|
|
'cn': cn,
|
|
|
|
'sn': sn,
|
|
|
|
'mail': mail
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
response, result, request = client.connection.get_response(
|
|
|
|
response_id, get_request=True
|
|
|
|
)
|
|
|
|
|
|
|
|
print("Request: {}".format(request))
|
|
|
|
print("Response: {}".format(response))
|
|
|
|
print("Result: {}".format(result))
|
|
|
|
|
|
|
|
entry = get_user_by_uid(ldap_client, uid)
|
|
|
|
assert entry['uid'] == uid
|
2020-10-04 14:23:26 +02:00
|
|
|
assert entry['mail'] == mail
|
2020-10-04 16:47:33 +02:00
|
|
|
|
|
|
|
response_id = client.connection.delete(dn)
|
|
|
|
|
|
|
|
response, result, request = client.connection.get_response(
|
|
|
|
response_id, get_request=True
|
|
|
|
)
|
|
|
|
|
|
|
|
print("Request: {}".format(request))
|
|
|
|
print("Response: {}".format(response))
|
|
|
|
print("Result: {}".format(result))
|
|
|
|
|
|
|
|
entry = get_user_by_uid(ldap_client, uid)
|
|
|
|
assert entry is None
|