Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests. #18

Merged
merged 1 commit into from
Feb 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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