示例#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")