Revert "Revert "Better AuthenticationOption duplicate detection"" - #36648
#36648Revert "Revert "Better AuthenticationOption duplicate detection""#36648Hamms merged 2 commits intostagingcode-dot-org/code-dot-org:stagingfrom revert-36647-revert-36555-better-auth-option-deduplicationcode-dot-org/code-dot-org:revert-36647-revert-36555-better-auth-option-deduplicationCopy head branch name to clipboard
Conversation
| factory :user do | ||
| birthday Time.zone.today - 21.years | ||
| email {("#{user_type}_#{(User.maximum(:id) || 0) + 1}@code.org")} | ||
| email {("#{user_type}_#{SecureRandom.uuid}@code.org")} |
There was a problem hiding this comment.
My first attempt at this PR used a sequence here to attempt to reduce the chance of collision.
I suspect that this is what caused the Validation failed: Email has already been taken error we saw; I was able to repro locally, and verified that that using a UUID rather than a sequential ID here allowed the test to pass on my local machine.
There was a problem hiding this comment.
it might help to know what email address was already taken when these tests failed.
There was a problem hiding this comment.
teacher_5@code.org, at least when I run just the relevant subset of tests via bundle exec runner.rb -l -f features/plc/pd/* --eyes --html
There was a problem hiding this comment.
whoa, any idea how a UI test is depending on a factory method? I thought we only used them for unit tests.
There was a problem hiding this comment.
Looks like we use FactoryGirl pretty extensively in the PD UI tests:
code-dot-org/dashboard/test/ui/features/step_definitions/pd.rb
Lines 48 to 50 in 51706f3
code-dot-org/dashboard/test/ui/features/step_definitions/pd.rb
Lines 104 to 109 in 51706f3
(and lots more)
There was a problem hiding this comment.
mmmm interesting! the first 2 calls look ok because they are using their own mechanism to generate a unique email, so they wouldn't touch the uuid logic you added. However, this one call does not specify an email and would therefore hit your uuid logic:
Can you double-check my reasoning here, and say whether you think it might be worth changing the user factory email back to using sequence and making the line linked above specify an email? I would be willing to open the PR for this.
There was a problem hiding this comment.
I'm not seeing the value in that solution; in particular, it seems to me that you shouldn't need to specify an email in order for the factory to work.
There was a problem hiding this comment.
Good point. This solution sounds good, now that we know why sequence wasn't working, because it lets UI tests rely on factories for generating unique emails. Thanks for your willingness to investigate!
There was a problem hiding this comment.
Thank you for your thoroughness!
Erin007
left a comment
There was a problem hiding this comment.
LGTM! Thanks for the revert and quick follow-up, Elijah!
|
Seems fine to unblock, but any ideas why |
Not so far; I could definitely spend more time digging in, though. In particular, it's not clear to me what exactly it is that |
|
|
||
| test "age is set exactly for Google OAuth users between ages 4 and 20" do | ||
| four_year_old = create :user, birthday: (Date.today - 4.years), provider: 'google_oauth2' | ||
| four_year_old = build :user, birthday: (Date.today - 4.years), provider: 'google_oauth2' |
There was a problem hiding this comment.
is it a problem that there is no uid here? apologies for my lack of deep understanding here. I am just asking because I see that it is specified by this trait:
code-dot-org/dashboard/test/factories/factories.rb
Lines 319 to 323 in 71a185b
There was a problem hiding this comment.
My understanding is that user.uid is the pre-authentication-options way of identifying oauth, and that that information has been migrated to authentication_option.authentication_id
| @@ -20,13 +20,17 @@ class UserMultiAuthHelperTest < ActiveSupport::TestCase | ||
| test 'oauth_tokens_for_provider returns most recently updated tokens for migrated teacher' do |
There was a problem hiding this comment.
this class does not appear to be using use_transactional_test_case. any reason why not?
There was a problem hiding this comment.
I'm not particularly familiar with this test. Why do you think use_transactional_test_case would be relevant?
There was a problem hiding this comment.
Just because we are running into problems with duplicate emails, and wrapping the test in a transaction would cause it not to persist and changes to the DB, which could decrease the changes of conflicting emails. It sounds from your earlier comment that this test isn't failing and isn't even using the same DB as the test that is failing though, because this is a unit test and it is a UI test that is failing. so with that information I don't think this could be causing a UI test to fail.
There was a problem hiding this comment.
Ah, that makes sense. Yeah, this test was touched because of the original PR's changes to the way we handle duplicate authentication option detection, not because of the email issue
I added a few follow-up questions/comments inline related to helping track this down. If none of those or anything you want to try are successful in turning anything up, then I think it could be fine to move on and use uuids. |
Reverts #36647, restoring #36555