Skip to content

Commit

Permalink
Merge pull request #11 from Kinto/8-fix-heartbeat
Browse files Browse the repository at this point in the history
Fix heartbeat when server is unreachable
  • Loading branch information
leplatrem committed Nov 2, 2016
2 parents 5a50308 + 43534b7 commit 5c33691
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ This document describes changes between each past release.
- Set default value for ``multiauth.policy.ldap.use`` (fixes #3)
- Add the plugin version in the capability.

**Bug fixes**

- Fix heartbeat when server is unreachable (fixes #8)

0.1.0 (2016-06-27)
------------------
Expand Down
2 changes: 1 addition & 1 deletion kinto_ldap/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def ldap_ping(request):
"""Verify if the LDAP server is ready."""
cm = request.registry.ldap_cm
try:
with cm.connection():
with cm.connection('mail=mail@test,o=com,dc=test', 'password'):
ldap = True
except Exception:
logger.exception("Heartbeat Failure")
Expand Down
9 changes: 0 additions & 9 deletions kinto_ldap/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +0,0 @@
try:
import unittest2 as unittest
except ImportError:
import unittest

from kinto.tests.core.support import DummyRequest


__all__ = (DummyRequest, unittest)
7 changes: 5 additions & 2 deletions kinto_ldap/tests/test_authentication.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import base64
import ldap
import mock
import unittest
import time

import mock

from kinto.core.cache import memory as memory_backend
from kinto.core.testing import DummyRequest

from kinto_ldap import authentication, DEFAULT_SETTINGS
from . import unittest, DummyRequest


class LDAPBasicAuthAuthenticationPolicyTest(unittest.TestCase):
Expand Down
3 changes: 2 additions & 1 deletion kinto_ldap/tests/test_includeme.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import unittest

import kinto.core
from pyramid.exceptions import ConfigurationError
from pyramid import testing

from kinto_ldap import includeme
from . import unittest


class IncludeMeTest(unittest.TestCase):
Expand Down
16 changes: 15 additions & 1 deletion kinto_ldap/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import unittest

import kinto.core
import webtest
from kinto.core.utils import random_bytes_hex
from pyramid.config import Configurator

from kinto_ldap import __version__ as ldap_version
from . import unittest


def get_request_class(prefix):
Expand Down Expand Up @@ -74,3 +75,16 @@ def test_ldap_capability(self, additional_settings=None):
"LDAP server."
}
self.assertEqual(expected, capabilities['ldap'])


class HeartbeatTest(BaseWebTest, unittest.TestCase):

def get_app_settings(self, extras=None):
settings = super(HeartbeatTest, self).get_app_settings(extras)
settings['ldap.endpoint'] = 'ldap://ldap.with.unreachable.server.com'
return settings

def test_heartbeat_returns_false(self):
resp = self.app.get('/__heartbeat__', status=503)
heartbeat = resp.json['ldap']
self.assertFalse(heartbeat)

0 comments on commit 5c33691

Please sign in to comment.