BUGFIX: blank name causes SSO to explode

This commit is contained in:
Sam 2014-06-02 17:32:39 +10:00
parent 9e9c41ac52
commit e087e37907
2 changed files with 20 additions and 4 deletions

View file

@ -1,6 +1,7 @@
require_dependency 'single_sign_on'
class DiscourseSingleSignOn < SingleSignOn
def self.sso_url
SiteSetting.sso_url
end
@ -57,7 +58,7 @@ class DiscourseSingleSignOn < SingleSignOn
if sso_record && (user = sso_record.user) && !user.active
user.active = true
user.save
user.save!
user.enqueue_welcome_message('welcome_user')
end
@ -77,13 +78,16 @@ class DiscourseSingleSignOn < SingleSignOn
def match_email_or_create_user
user = User.find_by(email: Email.downcase(email))
try_name = name.blank? ? nil : name
try_username = username.blank? ? nil : username
user_params = {
email: email,
name: User.suggest_name(name || username || email),
username: UserNameSuggester.suggest(username || name || email),
name: User.suggest_name(try_name || try_username || email),
username: UserNameSuggester.suggest(try_username || try_name || email),
}
if user || user = User.create(user_params)
if user || user = User.create!(user_params)
if sso_record = user.single_sign_on_record
sso_record.last_payload = unsigned_payload
sso_record.external_id = external_id

View file

@ -34,6 +34,18 @@ describe DiscourseSingleSignOn do
parsed.custom_fields["b.b"].should == "B.b"
end
it "can lookup or create user when name is blank" do
# so we can create system messages
Fabricate(:admin)
sso = DiscourseSingleSignOn.new
sso.username = "test"
sso.name = ""
sso.email = "test@test.com"
sso.external_id = "A"
user = sso.lookup_or_create_user
user.should_not == nil
end
it "can fill in data on way back" do
sso = make_sso