Skip to content

Commit 494e82a

Browse files
author
Stephen Cefali
authored
fix(integrations): make email matching case insensitive (#20827)
1 parent cf1ca91 commit 494e82a

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/sentry/api/serializers/models/release.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,19 @@ def get_users_for_authors(organization_id, authors, user=None):
7878
# Figure out which email address matches to a user
7979
users_by_email = {}
8080
for email in user_emails:
81-
if email.email not in users_by_email:
81+
# force emails to lower case so we can do case insensitive matching
82+
lower_email = email.email.lower()
83+
if lower_email not in users_by_email:
8284
user = users_by_id.get(six.text_type(email.user_id), None)
8385
# user can be None if there's a user associated
8486
# with user_email in separate organization
8587
if user:
86-
users_by_email[email.email] = user
88+
users_by_email[lower_email] = user
8789

8890
results = {}
8991
for author in authors:
9092
results[six.text_type(author.id)] = users_by_email.get(
91-
author.email, {"name": author.name, "email": author.email}
93+
author.email.lower(), {"name": author.name, "email": author.email}
9294
)
9395

9496
return results

src/sentry/models/commitauthor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class CommitAuthorManager(BaseManager):
1010
def get_or_create(self, organization_id, email, defaults, **kwargs):
11-
# Force email address to lowercase because GitHub does this. Note though that this isn't technically
11+
# Force email address to lowercase because many providers do this. Note though that this isn't technically
1212
# to spec; only the domain part of the email address is actually case-insensitive.
1313
# See: https://stackoverflow.com/questions/9807909/are-email-addresses-case-sensitive
1414
return super(CommitAuthorManager, self).get_or_create(

tests/sentry/api/serializers/test_release.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ def test_no_tag_data(self):
159159
assert not result["lastEvent"]
160160

161161
def test_get_user_from_email(self):
162-
user = User.objects.create(email="[email protected]")
162+
user = User.objects.create(
163+
164+
) # upper case so we can test case sensitivity
163165
UserEmail.get_primary_email(user=user)
164166
project = self.create_project()
165167
self.create_member(user=user, organization=project.organization)

0 commit comments

Comments
 (0)