Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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'])
Ejemplo n.º 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'])
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 7
0
def test_empty_password_fails(LDAP, user_template_config):
    ldap = LDAP(user_template_config.strpath)
    assert ldap.validate('user', '') == dict(status="reject")
Ejemplo n.º 8
0
def test_empty_password_fails(LDAP, user_template_config):
    ldap = LDAP(user_template_config.strpath)
    assert ldap.validate('user', '') == dict(status="reject")
Ejemplo n.º 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")
Ejemplo n.º 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")