Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Revert "Revert "Better AuthenticationOption duplicate detection"" - #36648

#36648
Merged
Hamms merged 2 commits into
stagingcode-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
Sep 9, 2020
Merged

Revert "Revert "Better AuthenticationOption duplicate detection""#36648
Hamms merged 2 commits into
stagingcode-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

@Hamms

@Hamms Hamms commented Sep 8, 2020

Copy link
Copy Markdown
Contributor

Reverts #36647, restoring #36555

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")}

@Hamms Hamms Sep 8, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it might help to know what email address was already taken when these tests failed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

whoa, any idea how a UI test is depending on a factory method? I thought we only used them for unit tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks like we use FactoryGirl pretty extensively in the PD UI tests:

FactoryGirl.create(:program_manager, name: pm_name, email: email, password: password, regional_partner: regional_partner)

FactoryGirl.create(:pd_course_facilitator, course: course, facilitator:
FactoryGirl.create(:facilitator, name: name, email: email, password: password)
)

enrollment = FactoryGirl.create(
:pd_enrollment,
:with_attendance,
:from_user,
user: find_test_user_by_name(test_teacher_name)
)

(and lots more)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your thoroughness!

@Hamms
Hamms marked this pull request as ready for review September 8, 2020 23:19

@Erin007 Erin007 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thanks for the revert and quick follow-up, Elijah!

@davidsbailey

Copy link
Copy Markdown
Member

Seems fine to unblock, but any ideas why sequence didn't work?

@Hamms

Hamms commented Sep 9, 2020

Copy link
Copy Markdown
Contributor Author

any ideas why sequence didn't work?

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 sequence actually uses to generate the sequence, particularly in a context in which we are running tests in parallel.

@Hamms
Hamms merged commit aba4f2c into staging Sep 9, 2020
@Hamms
Hamms deleted the revert-36647-revert-36555-better-auth-option-deduplication branch September 9, 2020 17:27

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'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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:

trait :sso_provider do
encrypted_password nil
provider %w(facebook windowslive clever).sample
sequence(:uid) {|n| n}
end

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this class does not appear to be using use_transactional_test_case. any reason why not?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not particularly familiar with this test. Why do you think use_transactional_test_case would be relevant?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

@davidsbailey

Copy link
Copy Markdown
Member

any ideas why sequence didn't work?

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 sequence actually uses to generate the sequence, particularly in a context in which we are running tests in parallel.

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.

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.

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.