Commit c29aca2e authored by Andy Soiron's avatar Andy Soiron

Fix 2FA setup for LDAP users

LDAP and other oauth users couldn't set up two factor authentication
when they had a password prior to linking oauth and didn't remember
the password. This commit removes the requirement to enter the current
password if authentication with password is disabled for the
application.

Changelog: fixed
parent 3b744058
......@@ -147,7 +147,7 @@ class Profiles::TwoFactorAuthsController < Profiles::ApplicationController
end
def current_password_required?
!current_user.password_automatically_set?
!current_user.password_automatically_set? && current_user.allow_password_authentication_for_web?
end
def build_qr_code
......
......@@ -62,6 +62,32 @@ RSpec.describe Profiles::TwoFactorAuthsController do
expect(flash[:alert]).to be_nil
end
end
context 'when password authentication is disabled' do
before do
stub_application_setting(password_authentication_enabled_for_web: false)
end
it 'does not require the current password', :aggregate_failures do
go
expect(response).not_to redirect_to(redirect_path)
expect(flash[:alert]).to be_nil
end
end
context 'when the user is an LDAP user' do
before do
allow(user).to receive(:ldap_user?).and_return(true)
end
it 'does not require the current password', :aggregate_failures do
go
expect(response).not_to redirect_to(redirect_path)
expect(flash[:alert]).to be_nil
end
end
end
describe 'GET show' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment