Beispiel #1
0
def test_process_entry_static():
    from ldap2pg.manager import SyncManager

    manager = SyncManager()

    roles = manager.process_ldap_entry(
        entry=None, names=['ALICE'], parents=['postgres'],
        options=dict(LOGIN=True),
    )
    roles = list(roles)

    assert 1 == len(roles)
    assert 'alice' in roles
    assert 'postgres' in roles[0].parents
Beispiel #2
0
def test_process_entry_dn():
    from ldap2pg.manager import SyncManager

    manager = SyncManager()

    entry = ('dn', {'member': ['cn=alice,dc=unit', 'cn=bob,dc=unit']})

    roles = manager.process_ldap_entry(entry, name_attribute='member.cn')
    roles = list(roles)
    names = {r.name for r in roles}

    assert 2 == len(roles)
    assert 'alice' in names
    assert 'bob' in names
Beispiel #3
0
def test_process_entry_members(mocker):
    from ldap2pg.manager import SyncManager

    manager = SyncManager()

    entry = ('dn', {'member': ['cn=alice,dc=unit', 'cn=bob,dc=unit']})

    roles = manager.process_ldap_entry(
        entry, names=['group'], members_attribute='member.cn',
    )
    roles = list(roles)

    assert 1 == len(roles)
    role = roles[0]
    assert 'alice' in role.members
    assert 'bob' in role.members
Beispiel #4
0
def test_process_entry_user():
    from ldap2pg.manager import SyncManager

    manager = SyncManager()

    entry = ('dn', {'cn': [('alice', {}), ('bob', {})]})

    roles = manager.process_ldap_entry(
        entry, names=['{cn}'],
        options=dict(LOGIN=True),
    )
    roles = list(roles)

    assert 2 == len(roles)
    assert 'alice' in roles
    assert 'bob' in roles
    assert roles[0].options['LOGIN'] is True
Beispiel #5
0
def test_process_entry_membership(mocker):
    from ldap2pg.manager import SyncManager

    manager = SyncManager()

    entries = [
        ('cn=group0', {
            'cn': ['group0'],
            'member': ['cn=alice,dc=unit', 'cn=alain,dc=unit']
        }),
        ('cn=group1', {
            'cn': ['group1'],
            'member': ['cn=bob,dc=unit', 'cn=benoit,dc=unit']
        }),
    ]

    roles = []
    rule = dict(
        members=['{member.cn}'],
        parents=['{cn}'],
    )
    for i, entry in enumerate(entries):
        name = 'role%d' % i
        roles += list(manager.process_ldap_entry(entry, names=[name], **rule))

    assert 2 == len(roles)
    assert 'alice' in roles[0].members
    assert 'alain' in roles[0].members
    assert 'bob' not in roles[0].members
    assert 'benoit' not in roles[0].members
    assert 'group0' in roles[0].parents
    assert 'group1' not in roles[0].parents

    assert 'alice' not in roles[1].members
    assert 'alain' not in roles[1].members
    assert 'bob' in roles[1].members
    assert 'benoit' in roles[1].members
    assert 'group0' not in roles[1].parents
    assert 'group1' in roles[1].parents