Skip LDAP cache check when LDAP is disabled

This commit is contained in:
Jacob Vosmaer 2014-08-06 15:17:12 +02:00
parent 1118a6fd34
commit e0fea696c6
2 changed files with 24 additions and 11 deletions

View file

@ -403,7 +403,9 @@ class User < ActiveRecord::Base
end
def requires_ldap_check?
if ldap_user?
if !Gitlab.config.ldap.enabled
false
elsif ldap_user?
!last_credential_check_at || (last_credential_check_at + 1.hour) < Time.now
else
false

View file

@ -315,12 +315,22 @@ describe User do
describe :requires_ldap_check? do
let(:user) { User.new }
it 'is false when LDAP is disabled' do
# Create a condition which would otherwise cause 'true' to be returned
user.stub(ldap_user?: true)
user.last_credential_check_at = nil
expect(user.requires_ldap_check?).to be_false
end
context 'when LDAP is enabled' do
before { Gitlab.config.ldap.stub(enabled: true) }
it 'is false for non-LDAP users' do
user.stub(ldap_user?: false)
expect(user.requires_ldap_check?).to be_false
end
context 'when the user is an LDAP user' do
context 'and when the user is an LDAP user' do
before { user.stub(ldap_user?: true) }
it 'is true when the user has never had an LDAP check before' do
@ -334,6 +344,7 @@ describe User do
end
end
end
end
describe '#full_website_url' do
let(:user) { create(:user) }