FIX: require re-activation if SSO changes email and updates it

This commit is contained in:
Sam 2017-05-16 16:18:18 -04:00
parent 4424fd81b8
commit 763f156d91
2 changed files with 25 additions and 2 deletions

View File

@ -166,6 +166,7 @@ class DiscourseSingleSignOn < SingleSignOn
def change_external_attributes_and_override(sso_record, user)
if SiteSetting.sso_overrides_email && user.email != email
user.email = email
user.active = false if require_activation
end
if SiteSetting.sso_overrides_username && user.username != username && username.present?

View File

@ -253,6 +253,28 @@ describe DiscourseSingleSignOn do
expect(user.active).to eq(false)
end
it 'deactivates accounts that have updated email address' do
SiteSetting.sso_overrides_email = true
sso.require_activation = true
user = sso.lookup_or_create_user(ip_address)
expect(user.active).to eq(false)
old_email = user.email
user.update_columns(active: true)
user = sso.lookup_or_create_user(ip_address)
expect(user.active).to eq(true)
user.update_columns(email: 'xXx@themovie.com')
user = sso.lookup_or_create_user(ip_address)
expect(user.email).to eq(old_email)
expect(user.active).to eq(false)
end
end
context 'welcome emails' do
@ -267,13 +289,13 @@ describe DiscourseSingleSignOn do
it "sends a welcome email by default" do
User.any_instance.expects(:enqueue_welcome_message).once
user = sso.lookup_or_create_user(ip_address)
_user = sso.lookup_or_create_user(ip_address)
end
it "suppresses the welcome email when asked to" do
User.any_instance.expects(:enqueue_welcome_message).never
sso.suppress_welcome_message = true
user = sso.lookup_or_create_user(ip_address)
_user = sso.lookup_or_create_user(ip_address)
end
end