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

Ldap authenticator #207

Merged
merged 8 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
19 changes: 19 additions & 0 deletions continuous_integration/docker-configs/ldap-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '2'

services:
openldap:
image: docker.io/bitnami/openldap:2.6
ports:
- '1389:1389'
- '1636:1636'
environment:
- LDAP_ADMIN_USERNAME=admin
- LDAP_ADMIN_PASSWORD=adminpassword
- LDAP_USERS=user01,user02
- LDAP_PASSWORDS=password1,password2
volumes:
- 'openldap_data:/bitnami/openldap'

volumes:
openldap_data:
driver: local
3 changes: 3 additions & 0 deletions continuous_integration/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash
set -vxeuo pipefail

# Start LDAP (in docker)
source start_LDAP.sh

# These packages are installed in the base environment but may be older
# versions. Explicitly upgrade them because they often create
# installation problems if out of date.
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
codecov
coverage
flake8
ldap3
pre-commit
pytest
pytest-asyncio
Expand Down
7 changes: 7 additions & 0 deletions start_LDAP.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -e

# Start LDAP server in docker container
sudo docker pull bitnami/openldap:latest
sudo docker-compose -f continuous_integration/docker-configs/ldap-docker-compose.yml up -d
sudo docker ps
30 changes: 30 additions & 0 deletions tiled/_tests/test_authenticators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import asyncio

import pytest

from ..authenticators import LDAPAuthenticator


@pytest.mark.parametrize("use_tls,use_ssl", [(False, False)])
def test_LDAPAuthenticator_01(use_tls, use_ssl):
"""
Basic test for ``LDAPAuthenticator``.

TODO: The test could be extended with enabled TLS or SSL, but it requires configuration
of the LDAP server.
"""
authenticator = LDAPAuthenticator(
"localhost",
1389,
bind_dn_template="cn={username},ou=users,dc=example,dc=org",
use_tls=use_tls,
use_ssl=use_ssl,
)

async def testing():
assert await authenticator.authenticate("user01", "password1") == "user01"
assert await authenticator.authenticate("user02", "password2") == "user02"
assert await authenticator.authenticate("user02a", "password2") is None
assert await authenticator.authenticate("user02", "password2a") is None

asyncio.run(testing())
Loading