Esempio n. 1
0
def get_group_by_id(gid, attributes=None):
    """Retrieves a user's data from LDAP, given its identifier.

    :param gid: str -- the identifier of the group
    :param attributes: list -- Attributes to be retrieved for the group.
                       If ``None``, all attributes will be retrieved.
    :raises GroupRetrievalFailed: If the identifier is falsely.
    :return: A tuple containing the `dn` of the group as ``str`` and the
             found attributes in a ``dict``.
    """
    if not gid:
        raise GroupRetrievalFailed("No identifier specified")
    group_filter = build_group_search_filter({current_ldap.settings['gid']: {gid}}, exact=True)
    return find_one(current_ldap.settings['group_base'], group_filter, attributes=attributes)
Esempio n. 2
0
def get_group_by_id(gid, attributes=None):
    """Retrieves a user's data from LDAP, given its identifier.

    :param uid: str -- the identifier of the user
    :param attributes: list -- Attributes to be retrieved for the user.
                       If ``None``, all attributes will be retrieved.
    :raises GroupRetrievalFailed: If the identifier is falsely.
    :return: A tuple containing the `dn` of the user as ``str`` and the
             found attributes in a ``dict``.
    """
    if not gid:
        raise GroupRetrievalFailed("No identifier specified")
    group_filter = build_group_search_filter({current_ldap.settings['gid']: {gid}}, exact=True)
    return find_one(current_ldap.settings['group_base'], group_filter, attributes=attributes)
Esempio n. 3
0
def test_find_one(mocker, base_dn, search_filter, data, expected):
    settings = {
        'uri': 'ldaps://ldap.example.com:636',
        'bind_dn': 'uid=admin,DC=example,DC=com',
        'bind_password': '******',
        'verify_cert': True,
        'starttls': True,
        'timeout': 10
    }

    ldap_search = MagicMock(return_value=data)
    ldap_conn = MagicMock(search_ext_s=ldap_search)
    mocker.patch('flask_multipass.providers.ldap.util.ReconnectLDAPObject', return_value=ldap_conn)

    with ldap_context(settings):
        assert find_one(base_dn, search_filter) == expected