Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #18 from Kinto/fix-tests
Browse files Browse the repository at this point in the history
Fix tests with kinto-master and Python 3.
  • Loading branch information
Rémy HUBSCHER committed Feb 23, 2017
2 parents 4cb3329 + 046e2b2 commit ec7bcbd
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 27 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ This document describes changes between each past release.
0.4.0 (unreleased)
------------------

- Nothing changed yet.
**Bug fixes**

- Fix support with Kinto 6 and Python 3. (#18)


0.3.0 (2016-11-23)
Expand Down
8 changes: 8 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 ec7bcbd

Please sign in to comment.