Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(auth): Reuse existing user profile for unknown identity #28621

Merged
merged 12 commits into from
Sep 23, 2021

Conversation

RyanSkonnord
Copy link
Contributor

When a user supplies unrecognized SSO credentials associated with an email address for an existing user profile, offer them a chance to link their identity to that profile instead of automatically provisioning a new profile.

This is a basis for further feature development. It has function stubs and an incomplete page template that are not reachable unless a feature flag is set. For now, this flag should be set only in a development environment. Added a unit test (test_unauthenticated_with_existing_user) which should verify that the stub is unreachable.

When a user supplies unrecognized SSO credentials associated with an
email address for an existing user profile, offer them a chance to link
their identity to that profile instead of automatically provisioning a
new profile.

Introduce a feature flag. The feature is incomplete and will hit
unimplemented code if the flag is set.
@RyanSkonnord RyanSkonnord requested a review from a team as a code owner September 15, 2021 23:12
Comment on lines -47 to +48
"email": "test@example.com",
"email": self.email,
Copy link

Choose a reason for hiding this comment

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

Should we change this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you elaborate? I extracted this into an instance variable to reduce repetition of self.identity["email"] below.

Copy link
Member

@JoshFerge JoshFerge left a comment

Choose a reason for hiding this comment

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

overall looks good 👍🏼 . added some thoughts on structure + test organization

@@ -309,6 +308,25 @@ def test_authenticated(self, mock_render):
assert context["existing_user"] is self.request.user
assert "login_form" not in context

@mock.patch("sentry.auth.helper.render_to_response")
@mock.patch("sentry.auth.helper.create_verification_key")
def test_unauthenticated_with_existing_user(self, mock_create_key, mock_render):
Copy link
Member

Choose a reason for hiding this comment

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

it seems like either we are going to end up having duplicated test behavior between tests/sentry/web/frontend/test_auth_organization_login.py and here, or have tested behavior be split across both. i'm not sure what the right resolution is, but I think the integration tests are easier to work with since you don't need so many mocks.

Copy link
Member

Choose a reason for hiding this comment

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

as discussed offline, probably prudent to enable this flag in the org login tests to confirm existing behavior is preserved when this flag is enabled.

Copy link
Member

Choose a reason for hiding this comment

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

@RyanSkonnord what was your conclusion on integration tests vs unit tests? It seems like we'd still want integration tests regardless

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added an integration test: 833a633

See also #28784 😅

@RyanSkonnord
Copy link
Contributor Author

@JoshFerge I think _dispatch_to_confirmation should address most of your stylistic concerns.

(The "existing_user": existing_user or acting_user on line 480 might be a minor sin, but I like it better than passing acting_user to _dispatch_to_confirmation. If you hate it, I could revert 64f785f.)

Setting the feature flag on test_auth_organization_login does indeed seem to cause some regressions. I'll be working on that next.

@JoshFerge
Copy link
Member

@RyanSkonnord alright sounds good, will wait on your changes to have tests passing with the flag to give it another go-round.

@RyanSkonnord
Copy link
Contributor Author

RyanSkonnord commented Sep 20, 2021

Turns out test_auth_organization_login does not have genuine regressions, but the test helper sentry.testutils.helpers.features.Feature has some interesting limitations that I've tripped over. I think it may merit an application-wide fix that I'll put in another PR. Will update after I've tinkered with possible fixes a little more.

[Update: See #28686.]

@RyanSkonnord
Copy link
Contributor Author

If we don't want to wait for #28686, it should be safe to go ahead. Having manually dummied out the feature flag check, I found no regressions when running test_auth_organization_login locally.

Copy link
Member

@JoshFerge JoshFerge left a comment

Choose a reason for hiding this comment

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

having an acting_user and existing_user is still confusing to me, but I understand wanting these changes to have a small footprint is ideal. maybe we could schedule a team programming session where we do some smaller refactors to this method. see comment about integration tests, but looks good.

…assword

Change create_user so that calling it with password="" sets up the user
in a state where it does not have a usable password, as the test case
intended. Previously, any falsy value would give it a default password.

This exposes an incorrect assertion. The test case is currently failing.
@RyanSkonnord RyanSkonnord merged commit 71064ab into master Sep 23, 2021
@RyanSkonnord RyanSkonnord deleted the idp-automatic-migration-base branch September 23, 2021 18:12
vuluongj20 pushed a commit that referenced this pull request Sep 30, 2021
)

When a user supplies unrecognized SSO credentials associated with an
email address for an existing user profile, offer them a chance to link
their identity to that profile instead of automatically provisioning a
new profile.

Introduce a feature flag. The feature is incomplete and will hit
unimplemented code if the flag is set.
@github-actions github-actions bot locked and limited conversation to collaborators Oct 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants