Skip to content

Conversation

@bistline
Copy link
Contributor

BACKGROUND & CHANGES

This fixes a long-standing bug with some users not being able to sign back into SCP after initially creating an account. The problem lies with Devise (our main auth handler) and the fact that these users have capitalization in their emails according to their Google profiles. Since all modern email providers do not recognize capitalization, this is not normally an issue, but SCP has custom handling to decode the email from their profile and then do a lookup based on that value. If there are capital letters, the query fails. This leads to SCP trying to create a new user account (which is what happens the first time anyone logs in). This always works the first time and will fail every time after because the email address is taken, but the query will never find the correct account. This explains the infinite loop because we redirect back to the sign in page as the user hasn't successfully signed into SCP. Now, the account lookup correctly uses the downcased email, as this is what is saved by Devise.

MANUAL TESTING

If you do not have access to an email account with capitalization of the email in the Google profile, it is not possible to test this manually. The new UserTest should correctly find user if profile has capital letters covers this sufficiently. You can prove that it works by doing the following:

  1. Change line 126 in app/models/user.rb back to the original:
user = User.create(email: data['email'],
  1. Run the test manually and confirm it fails:
bin/rails test test/models/user_test.rb -n /capital/
...
  1) Failure:
UserTest#test_should_correctly_find_user_if_profile_has_capital_letters [test/models/user_test.rb:183]:
Expected false to be truthy.

@bistline bistline requested a review from eweitz October 23, 2025 20:39
@codecov
Copy link

codecov bot commented Oct 23, 2025

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 71.55%. Comparing base (ee78d40) to head (ac324b1).
⚠️ Report is 12 commits behind head on development.

Files with missing lines Patch % Lines
app/models/user.rb 80.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##           development    #2319      +/-   ##
===============================================
- Coverage        71.55%   71.55%   -0.01%     
===============================================
  Files              340      340              
  Lines            29129    29130       +1     
  Branches          2651     2651              
===============================================
  Hits             20844    20844              
- Misses            8144     8145       +1     
  Partials           141      141              
Files with missing lines Coverage Δ
app/models/user.rb 78.32% <80.00%> (+5.55%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines +123 to +125
# gotcha to downcase email as Devise does this by default, but it will break the query if the user profile has
# any capitalization in it. this mismatch leads to an infinite login loop as the user successfully authenticates
# but SCP can't find/create a user account
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks -- helpful maintenance context.

@bistline bistline merged commit 1dbc3ab into development Oct 28, 2025
6 checks passed
@github-actions github-actions bot deleted the jb-email-case-bug branch October 28, 2025 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants