forked from bluesky/tiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ENH: add LDAPAuthenticator * STY: black * Make ldap3 an optional dependency. * Remove global imports. * Refactor imports. * Satisfy isort. * Make LDAP authenticator non-blocking. Ported from bluesky/bluesky-httpserver#38 by @dmgav * Fix missing await. Co-authored-by: Dan Allan <dallan@bnl.gov>
- Loading branch information
1 parent
001b257
commit 3f4a7c8
Showing
6 changed files
with
542 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
continuous_integration/docker-configs/ldap-docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
codecov | ||
coverage | ||
flake8 | ||
ldap3 | ||
pre-commit | ||
pytest | ||
pytest-asyncio | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
Oops, something went wrong.