FIX: auth incorrectly handles duplicate usernames #15197
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If the
auth_overrides_usernamesetting is enabled, and a username is used by more than two users on the SSO provider site, users other than the first user to register on Discourse with the username will have the digit that’s appended to their username changed when they logout and log back into Discourse. For example, if there are three users with the username bob on the SSO provider site and the Discourse user bob1 logs into Discourse via SSO, they are likely to have their Discourse username updated to bob3.This is an edge case, but we were handling it correctly in the past. A part of my changes in #14531 broke that handling. Turned out, this edge case was the reason why we needed the
allowed_username = nilparameter inUserNameSuggester.suggest. I removed this parameter in that PR and introduced the regression.In this PR, I've returned the second parameter to
UserNameSuggester.suggest. I've named itcurrent_usernamethis time, in my opinion the previous nameallowed_usernamewas a bit confusing:Also, I've added test cases that explicitly document this edge case.
I was thinking of going even further, but I'm on the fence here. We can remove the
suggestmethod and create two new methods:This way, clients will always be enforced to
Without passing the current username for existent users, we'll always be seeing the same bug. It would be fine to enforce it.