Does not log failed sign-in attempts when database is in read-only mode

parent efd7b57b
...@@ -1097,8 +1097,11 @@ class User < ActiveRecord::Base ...@@ -1097,8 +1097,11 @@ class User < ActiveRecord::Base
# <https://github.com/plataformatec/devise/blob/v4.0.0/lib/devise/models/lockable.rb#L92> # <https://github.com/plataformatec/devise/blob/v4.0.0/lib/devise/models/lockable.rb#L92>
# #
def increment_failed_attempts! def increment_failed_attempts!
return if ::Gitlab::Database.read_only?
self.failed_attempts ||= 0 self.failed_attempts ||= 0
self.failed_attempts += 1 self.failed_attempts += 1
if attempts_exceeded? if attempts_exceeded?
lock_access! unless access_locked? lock_access! unless access_locked?
else else
......
...@@ -2755,4 +2755,18 @@ describe User do ...@@ -2755,4 +2755,18 @@ describe User do
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
end end
end end
describe '#increment_failed_attempts!' do
subject(:user) { create(:user, failed_attempts: 0) }
it 'logs failed sign-in attempts' do
expect { user.increment_failed_attempts! }.to change(user, :failed_attempts).from(0).to(1)
end
it 'does not log failed sign-in attempts when in a GitLab read-only instance' do
allow(Gitlab::Database).to receive(:read_only?) { true }
expect { user.increment_failed_attempts! }.not_to change(user, :failed_attempts)
end
end
end end
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