예제 #1
0
def test_apply_role_rule_unexpected_dn(mocker):
    gla = mocker.patch('ldap2pg.manager.expand_attributes', autospec=True)

    from ldap2pg.manager import SyncManager, RDNError, UserError

    manager = SyncManager()

    gla.side_effect = RDNError

    list(
        manager.apply_role_rules(
            entries=[('dn0', ), ('dn1', )],
            rules=[dict(names=['{cn}'], on_unexpected_dn='warn')],
        ))

    list(
        manager.apply_role_rules(
            entries=[('dn0', ), ('dn1', )],
            rules=[dict(names=['{cn}'], on_unexpected_dn='ignore')],
        ))

    with pytest.raises(UserError):
        list(
            manager.apply_role_rules(
                entries=[('dn0', ), ('dn1', )],
                rules=[dict(names=['{cn}'])],
            ))
예제 #2
0
def test_apply_role_rule_ko(mocker):
    gla = mocker.patch('ldap2pg.manager.expand_attributes', autospec=True)

    from ldap2pg.manager import SyncManager, UserError

    manager = SyncManager()

    gla.side_effect = ValueError
    items = manager.apply_role_rules(
        entries=[('dn0',), ('dn1',)],
        rules=[dict(names=['{cn}'])],
    )
    with pytest.raises(UserError):
        list(items)
예제 #3
0
def test_apply_role_rule_ko(mocker):
    gla = mocker.patch('ldap2pg.manager.get_ldap_attribute', autospec=True)

    from ldap2pg.manager import SyncManager, UserError

    manager = SyncManager()

    gla.side_effect = ValueError
    items = manager.apply_role_rules(
        entries=[None, None],
        rules=[dict(
            name_attribute='cn',
        )],
    )
    with pytest.raises(UserError):
        list(items)