FIX: sso_overrides_username may inappropriately change the username if the case changed

This commit is contained in:
Michael Brown 2018-03-09 16:06:55 -05:00
parent 0f07999c11
commit 3c3d205180
2 changed files with 27 additions and 2 deletions

View File

@ -181,8 +181,12 @@ class DiscourseSingleSignOn < SingleSignOn
user.active = false if require_activation
end
if SiteSetting.sso_overrides_username && user.username != username && username.present?
user.username = UserNameSuggester.suggest(username || name || email, user.username)
if SiteSetting.sso_overrides_username?
if user.username.downcase == username.downcase
user.username = username # there may be a change of case
elsif user.username != username && username.present?
user.username = UserNameSuggester.suggest(username || name || email, user.username)
end
end
if SiteSetting.sso_overrides_name && user.name != name && name.present?

View File

@ -166,6 +166,27 @@ describe DiscourseSingleSignOn do
expect(add_group4.usernames).to eq(user.username)
end
it 'can override username properly when only the case changes' do
SiteSetting.sso_overrides_username = true
sso = DiscourseSingleSignOn.new
sso.username = "testuser"
sso.name = "test user"
sso.email = "test@test.com"
sso.external_id = "100"
sso.bio = "This **is** the bio"
sso.suppress_welcome_message = true
# create the original user
user = sso.lookup_or_create_user(ip_address)
expect(user.username).to eq "testuser"
# change the username case
sso.username = "TestUser"
user = sso.lookup_or_create_user(ip_address)
expect(user.username).to eq "TestUser"
end
it "can override name / email / username" do
admin = Fabricate(:admin)