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

Add a new option: use_tls #216

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ repos:
rev: v1.9.0
hooks:
- id: reorder-python-imports
- repo: https://github.com/ambv/black
rev: 19.10b0
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
12 changes: 11 additions & 1 deletion ldapauthenticator/ldapauthenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def _server_port_default(self):
""",
)

use_tls = Bool(
True,
config=True,
help="""
Use TLS to communicate with the LDAP server when SSL is not used.
""",
)

bind_dn_template = Union(
[List(), Unicode()],
config=True,
Expand Down Expand Up @@ -309,7 +317,9 @@ def get_connection(self, userdn, password):
self.server_address, port=self.server_port, use_ssl=self.use_ssl
)
auto_bind = (
ldap3.AUTO_BIND_NO_TLS if self.use_ssl else ldap3.AUTO_BIND_TLS_BEFORE_BIND
ldap3.AUTO_BIND_NO_TLS
if self.use_ssl or not self.use_tls
else ldap3.AUTO_BIND_TLS_BEFORE_BIND
)
conn = ldap3.Connection(
server, user=userdn, password=password, auto_bind=auto_bind
Expand Down
10 changes: 10 additions & 0 deletions ldapauthenticator/tests/test_ldapauthenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ async def test_ldap_auth_ssl(authenticator):
assert authorized["name"] == "fry"


async def test_ldap_auth_tls(authenticator):
authenticator.use_tls = True

# proper username and password in allowed group
authorized = await authenticator.get_authenticated_user(
None, {"username": "fry", "password": "fry"}
)
assert authorized["name"] == "fry"


async def test_ldap_auth_use_lookup_dn(authenticator):
authenticator.use_lookup_dn_username = True

Expand Down