mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 13:31:44 +08:00
FIX: sso_overrides_username may inappropriately change the username if the case changed
This commit is contained in:
parent
0f07999c11
commit
3c3d205180
|
@ -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?
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user