Skip to content

Commit

Permalink
Check Synapse version before binding email (#61)
Browse files Browse the repository at this point in the history
Old Synapse versions (0.99.3 and earlier) did not support having emails bound by password providers, and as such cause errors with the current ldap3 password provider, which expects this functionality.

This change first checks the running Synapse version, and only binds emails if a version of Synapse > 0.99.3 is running.

The only issue now though is if someone is running off the current Synapse develop. That means they'll have the ability to bind emails, but since 0.99.4/1.0.0 hasn't been tagged yet, they're still marketing themselves as 0.99.3. So emails will not be bound. This isn't a game-breaking issue, but adding emails afterwards can be a pain. To this end, we should warn people that they should not run the version of matrix-synapse-ldap3 with this PR, and Synapse /develop before 0.99.4/1.0.0 is tagged, unless they don't care about emails not being bound to their account on signup.
  • Loading branch information
anoadragon453 committed Apr 10, 2019
1 parent 8e35312 commit cfddfd3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
21 changes: 17 additions & 4 deletions ldap_auth_provider.py
Expand Up @@ -20,6 +20,9 @@
import ldap3.core.exceptions

import logging
import synapse

from pkg_resources import parse_version


__version__ = "0.1.3"
Expand Down Expand Up @@ -281,11 +284,21 @@ def register_user(self, localpart, name, email_address):
emails = [email_address] if email_address is not None else []

# create account
user_id, access_token = (
yield self.account_handler.register(
localpart=localpart, displayname=name, emails=emails,
# check if we're running a version of synapse that supports binding emails
# from password providers
if parse_version(synapse.__version__) <= parse_version("0.99.3"):
user_id, access_token = (
yield self.account_handler.register(
localpart=localpart, displayname=name,
)
)
else:
# If Synapse has support, bind emails
user_id, access_token = (
yield self.account_handler.register(
localpart=localpart, displayname=name, emails=emails,
)
)
)

logger.info(
"Registration based on LDAP data was successful: %s",
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Expand Up @@ -49,6 +49,9 @@ def exec_file(path_segments, name):
"ldap3>=2.6",
"service_identity",
],
test_require=[
"matrix-synapse",
],
long_description=read_file(("README.rst",)),
classifiers=[
'Development Status :: 4 - Beta',
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Expand Up @@ -6,6 +6,7 @@ deps =
Twisted>=15.1
mock
ldaptor
matrix-synapse
ldap0: ldap3<1.0
ldap1: ldap3>=1.0,<2.0
ldap2: ldap3>=2.0
Expand Down

0 comments on commit cfddfd3

Please sign in to comment.