Skip to content

Commit

Permalink
Fix #201: empty email attribute in LDAP causes exception
Browse files Browse the repository at this point in the history
We were checking to see if the email attribute had no value, but not to see if it had a non-empty value!

We were making the same mistake with username.
  • Loading branch information
adobeDan committed Jun 2, 2017
1 parent 2ecc908 commit 8715b69
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions user_sync/connector/directory_ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def iter_users(self, users_filter, extended_attributes):
continue

email, last_attribute_name = self.user_email_formatter.generate_value(record)
if email is None:
if not email:
if last_attribute_name is not None:
self.logger.warning('Skipping user with dn %s: empty email attribute (%s)', dn, last_attribute_name)
continue
Expand All @@ -296,10 +296,13 @@ def iter_users(self, users_filter, extended_attributes):

username, last_attribute_name = self.user_username_formatter.generate_value(record)
source_attributes['username'] = username
if last_attribute_name and not username:
self.logger.warning('No username attribute (%s) for user with dn: %s, default to email (%s)',
last_attribute_name, dn, email)
user['username'] = username if username is not None else email
if username:
user['username'] = username
else:
if last_attribute_name:
self.logger.warning('No username attribute (%s) for user with dn: %s, default to email (%s)',
last_attribute_name, dn, email)
user['username'] = email

domain, last_attribute_name = self.user_domain_formatter.generate_value(record)
source_attributes['domain'] = domain
Expand Down

0 comments on commit 8715b69

Please sign in to comment.