Commit 2df09a40 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch...

Merge branch '46361-does-not-log-failed-sign-in-attempts-when-the-database-is-in-read-only-mode' into 'master'

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

Closes #46361

See merge request gitlab-org/gitlab-ce!18957
parents f4ef6b47 80393f0f
...@@ -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
......
---
title: Does not log failed sign-in attempts when the database is in read-only mode
merge_request: 18957
author:
type: fixed
...@@ -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