Пример #1
0
def test_ldap_exception(LDAP, mock, monkeypatch, user_template_config):
    from devpi_ldap.main import AuthException
    monkeypatch.setattr(LDAP.ldap3.Connection, 'open', mock.Mock(side_effect=LDAP.LDAPException()))
    ldap = LDAP(user_template_config.strpath)
    with pytest.raises(AuthException) as e:
        ldap.validate('user', 'foo')
    assert e.value.args[0] == "Couldn't open LDAP connection to ldap://localhost"
Пример #2
0
def test_socket_timeout(LDAP, mock, monkeypatch, user_template_config):
    from devpi_ldap.main import AuthException
    import socket
    monkeypatch.setattr(LDAP.ldap3.Connection, 'open', mock.Mock(side_effect=socket.timeout()))
    ldap = LDAP(user_template_config.strpath)
    with pytest.raises(AuthException) as e:
        ldap.validate('user', 'foo')
    assert e.value.args[0] == "Timeout on LDAP connect to ldap://localhost"
Пример #3
0
def test_extra_result_data(LDAP, MockServer, group_user_template_config):
    class Connection(MockConnection):
        def search(self, base, search_filter, search_scope, attributes):
            result = MockConnection.search(self, base, search_filter, search_scope, attributes)
            if self.response:
                self.response.insert(0, {})
            return result
    MockServer.users['user'] = dict(pw="password", groups=[dict(cn='users')])
    LDAP.ldap3.Connection = Connection
    ldap = LDAP(group_user_template_config.strpath)
    assert ldap.validate('user', 'password') == dict(status="ok", groups=[u'users'])
Пример #4
0
def test_extra_result_data(LDAP, MockServer, group_user_template_config):
    class Connection(MockConnection):
        def search(self, base, search_filter, search_scope, attributes):
            result = MockConnection.search(self, base, search_filter,
                                           search_scope, attributes)
            if self.response:
                self.response.insert(0, {})
            return result

    MockServer.users['user'] = dict(pw="password", groups=[dict(cn='users')])
    LDAP.ldap3.Connection = Connection
    ldap = LDAP(group_user_template_config.strpath)
    assert ldap.validate('user', 'password') == dict(status="ok",
                                                     groups=[u'users'])
Пример #5
0
def test_reject_as_unknown_empty(LDAP, reject_as_unknown_config):
    ldap = LDAP(reject_as_unknown_config.strpath)
    assert ldap.validate('user', '') == dict(status="unknown")
Пример #6
0
def test_reject_as_unknown(LDAP, reject_as_unknown_config):
    ldap = LDAP(reject_as_unknown_config.strpath)
    assert ldap._rejection() == dict(status="unknown")
Пример #7
0
def test_empty_password_fails(LDAP, user_template_config):
    ldap = LDAP(user_template_config.strpath)
    assert ldap.validate('user', '') == dict(status="reject")
Пример #8
0
def test_empty_password_fails(LDAP, user_template_config):
    ldap = LDAP(user_template_config.strpath)
    assert ldap.validate('user', '') == dict(status="reject")
Пример #9
0
def test_reject_as_unknown_empty(LDAP, reject_as_unknown_config):
    ldap = LDAP(reject_as_unknown_config.strpath)
    assert ldap.validate('user', '') == dict(status="unknown")
Пример #10
0
def test_reject_as_unknown(LDAP, reject_as_unknown_config):
    ldap = LDAP(reject_as_unknown_config.strpath)
    assert ldap._rejection() == dict(status="unknown")