mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 06:09:15 +08:00
FEATURE: add profile_background fields into SSO (#5701)
Add profile_background and card_background fields into Discourse SSO.
This commit is contained in:

committed by
Régis Hanol

parent
5a57a454fe
commit
ff6be3c2e3
@ -584,4 +584,167 @@ describe DiscourseSingleSignOn do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when sso_overrides_profile_background is not enabled' do
|
||||
|
||||
it "correctly handles provided profile_background_urls" do
|
||||
sso = DiscourseSingleSignOn.new
|
||||
sso.external_id = 666
|
||||
sso.email = "sam@sam.com"
|
||||
sso.name = "sam"
|
||||
sso.username = "sam"
|
||||
sso.profile_background_url = "http://awesome.com/image.png"
|
||||
sso.suppress_welcome_message = true
|
||||
|
||||
FileHelper.stubs(:download).returns(file_from_fixtures("logo.png"))
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
user.user_profile.reload
|
||||
profile_background = user.user_profile.profile_background
|
||||
|
||||
# initial creation ...
|
||||
expect(profile_background).to_not eq(nil)
|
||||
expect(profile_background).to_not eq('')
|
||||
|
||||
FileHelper.stubs(:download) { raise "should not be called" }
|
||||
sso.profile_background_url = "https://some.new/avatar.png"
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
user.user_profile.reload
|
||||
|
||||
# profile_background updated but no override specified ...
|
||||
expect(user.user_profile.profile_background).to eq(profile_background)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when sso_overrides_profile_background is enabled' do
|
||||
let!(:sso_record) { Fabricate(:single_sign_on_record, external_profile_background_url: "http://example.com/an_image.png") }
|
||||
|
||||
let!(:sso) {
|
||||
sso = DiscourseSingleSignOn.new
|
||||
sso.username = "test"
|
||||
sso.name = "test"
|
||||
sso.email = sso_record.user.email
|
||||
sso.external_id = sso_record.external_id
|
||||
sso
|
||||
}
|
||||
|
||||
let(:logo) { file_from_fixtures("logo.png") }
|
||||
|
||||
before do
|
||||
SiteSetting.sso_overrides_profile_background = true
|
||||
end
|
||||
|
||||
it "deal with no profile_background_url passed for an existing user with a profile_background" do
|
||||
Sidekiq::Testing.inline! do
|
||||
# Deliberately not setting profile_background_url so it should not update
|
||||
sso_record.user.user_profile.update_columns(profile_background: '')
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
user.user_profile.reload
|
||||
|
||||
expect(user).to_not be_nil
|
||||
expect(user.user_profile.profile_background).to eq('')
|
||||
end
|
||||
end
|
||||
|
||||
it "deal with a profile_background_url passed for an existing user with a profile_background" do
|
||||
Sidekiq::Testing.inline! do
|
||||
FileHelper.stubs(:download).returns(logo)
|
||||
|
||||
sso_record.user.user_profile.update_columns(profile_background: '')
|
||||
|
||||
sso.profile_background_url = "http://example.com/a_different_image.png"
|
||||
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
user.user_profile.reload
|
||||
|
||||
expect(user).to_not be_nil
|
||||
expect(user.user_profile.profile_background).to_not eq('')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when sso_overrides_card_background is not enabled' do
|
||||
|
||||
it "correctly handles provided card_background_urls" do
|
||||
sso = DiscourseSingleSignOn.new
|
||||
sso.external_id = 666
|
||||
sso.email = "sam@sam.com"
|
||||
sso.name = "sam"
|
||||
sso.username = "sam"
|
||||
sso.card_background_url = "http://awesome.com/image.png"
|
||||
sso.suppress_welcome_message = true
|
||||
|
||||
FileHelper.stubs(:download).returns(file_from_fixtures("logo.png"))
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
user.user_profile.reload
|
||||
card_background = user.user_profile.card_background
|
||||
|
||||
# initial creation ...
|
||||
expect(card_background).to_not eq(nil)
|
||||
expect(card_background).to_not eq('')
|
||||
|
||||
FileHelper.stubs(:download) { raise "should not be called" }
|
||||
sso.card_background_url = "https://some.new/avatar.png"
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
user.user_profile.reload
|
||||
|
||||
# card_background updated but no override specified ...
|
||||
expect(user.user_profile.card_background).to eq(card_background)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when sso_overrides_card_background is enabled' do
|
||||
let!(:sso_record) { Fabricate(:single_sign_on_record, external_card_background_url: "http://example.com/an_image.png") }
|
||||
|
||||
let!(:sso) {
|
||||
sso = DiscourseSingleSignOn.new
|
||||
sso.username = "test"
|
||||
sso.name = "test"
|
||||
sso.email = sso_record.user.email
|
||||
sso.external_id = sso_record.external_id
|
||||
sso
|
||||
}
|
||||
|
||||
let(:logo) { file_from_fixtures("logo.png") }
|
||||
|
||||
before do
|
||||
SiteSetting.sso_overrides_card_background = true
|
||||
end
|
||||
|
||||
it "deal with no card_background_url passed for an existing user with a card_background" do
|
||||
Sidekiq::Testing.inline! do
|
||||
# Deliberately not setting card_background_url so it should not update
|
||||
sso_record.user.user_profile.update_columns(card_background: '')
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
user.user_profile.reload
|
||||
|
||||
expect(user).to_not be_nil
|
||||
expect(user.user_profile.card_background).to eq('')
|
||||
end
|
||||
end
|
||||
|
||||
it "deal with a card_background_url passed for an existing user with a card_background_url" do
|
||||
Sidekiq::Testing.inline! do
|
||||
FileHelper.stubs(:download).returns(logo)
|
||||
|
||||
sso_record.user.user_profile.update_columns(card_background: '')
|
||||
|
||||
sso.card_background_url = "http://example.com/a_different_image.png"
|
||||
|
||||
user = sso.lookup_or_create_user(ip_address)
|
||||
user.reload
|
||||
user.user_profile.reload
|
||||
|
||||
expect(user).to_not be_nil
|
||||
expect(user.user_profile.card_background).to_not eq('')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user