Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémy HUBSCHER committed Feb 23, 2017
1 parent 4cb3329 commit 74f22e1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 26 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
@@ -1,10 +1,10 @@
language: python
python: 2.7
python: 3.5
sudo: false
services: redis-server
env:
- TOX_ENV=py27
- TOX_ENV=py34
- TOX_ENV=py35
- TOX_ENV=kinto-master
- TOX_ENV=flake8
install:
- pip install tox
Expand All @@ -14,3 +14,7 @@ after_success:
# Report coverage results to coveralls.io
- pip install coveralls
- coveralls
matrix:
include:
- python: 2.7
env: TOX_ENV=py27
8 changes: 8 additions & 0 deletions dev-requirements.txt
@@ -0,0 +1,8 @@
coverage
mock
pytest
pytest-cache
pytest-capturelog
pytest-cover
pytest-sugar
webtest
18 changes: 16 additions & 2 deletions kinto_ldap/authentication.py
Expand Up @@ -3,7 +3,7 @@
from kinto.core import utils
from ldap import INVALID_CREDENTIALS, SCOPE_SUBTREE
from ldappool import BackendError
from pyramid.authentication import BasicAuthAuthenticationPolicy
from pyramid import authentication as base_auth

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -72,12 +72,26 @@ def user_checker(username, password, request):
return None


class LDAPBasicAuthAuthenticationPolicy(BasicAuthAuthenticationPolicy):
class LDAPBasicAuthAuthenticationPolicy(base_auth.BasicAuthAuthenticationPolicy):
"""Basic auth with user credentials checked against an LDAP server."""
def __init__(self, *args, **kwargs):
super(LDAPBasicAuthAuthenticationPolicy, self).__init__(
user_checker, *args, **kwargs)

def effective_principals(self, request):
# Bypass default Pyramid construction of principals because
# Pyramid multiauth already adds userid, Authenticated and Everyone
# principals.
return []

def _get_credentials(self, request):
# Pyramid < 1.8
policy = base_auth.BasicAuthAuthenticationPolicy
if hasattr(policy, '_get_credentials'): # pragma: no cover
return policy._get_credentials(self, request)
# Pyramid > 1.8
return base_auth.extract_http_basic_credentials(request) # pragma: no cover

def unauthenticated_userid(self, request):
credentials = self._get_credentials(request)
if credentials:
Expand Down
3 changes: 2 additions & 1 deletion kinto_ldap/tests/test_authentication.py
Expand Up @@ -15,7 +15,7 @@
class LDAPBasicAuthAuthenticationPolicyTest(unittest.TestCase):
def setUp(self):
self.policy = authentication.LDAPBasicAuthAuthenticationPolicy()
self.backend = memory_backend.Cache(cache_prefix="tests")
self.backend = memory_backend.Cache(cache_prefix="tests", cache_max_size_bytes=524288)

self.request = DummyRequest()
self.request.registry.cache = self.backend
Expand All @@ -25,6 +25,7 @@ def setUp(self):
self.request.registry.ldap_cm.connection.return_value.__enter__.return_value = self.conn
settings = DEFAULT_SETTINGS.copy()
settings['userid_hmac_secret'] = 'abcdef'
settings['cache_max_size_bytes'] = 524288
settings['ldap.cache_ttl_seconds'] = 0.01
self.request.registry.settings = settings
self.request.headers['Authorization'] = (
Expand Down
27 changes: 7 additions & 20 deletions tox.ini
@@ -1,33 +1,20 @@
[tox]
envlist = py27,py34,flake8
envlist = py27,py35,kinto-master,flake8

[testenv]
commands =
python --version
py.test --cov-report term-missing --cov-fail-under 100 --cov kinto_ldap {posargs}
deps =
coverage
mock
pytest
pytest-cache
pytest-capturelog
pytest-cover
pytest-sugar
unittest2
webtest
-rdev-requirements.txt
install_command = pip install --process-dependency-links --pre {opts} {packages}

[testenv:py34]
[testenv:kinto-master]
basepython=python3
deps =
coverage
mock
pytest
pytest-cache
pytest-capturelog
pytest-cover
pytest-sugar
unittest2
webtest
-rdev-requirements.txt
https://github.com/Kinto/kinto/tarball/master


[testenv:flake8]
commands = flake8 kinto_ldap
Expand Down

0 comments on commit 74f22e1

Please sign in to comment.