Commit 0ee30de7 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-ee' into 'master'

Port of 46361-does-not-log-failed-sign-in-attempts-when-the-database-is-in-read-only-mode to EE

See merge request gitlab-org/gitlab-ee!5703
parents d7f95be9 ad657dea
......@@ -1119,8 +1119,11 @@ class User < ActiveRecord::Base
# <https://github.com/plataformatec/devise/blob/v4.0.0/lib/devise/models/lockable.rb#L92>
#
def increment_failed_attempts!
return if ::Gitlab::Database.read_only?
self.failed_attempts ||= 0
self.failed_attempts += 1
if attempts_exceeded?
lock_access! unless access_locked?
else
......
---
title: Does not log failed sign-in attempts when the database is in read-only mode
merge_request: 18957
author:
type: fixed
......@@ -5,7 +5,6 @@ module EE
# and be prepended in the `User` model
module User
extend ActiveSupport::Concern
extend ::Gitlab::Utils::Override
include AuditorUserHelper
included do
......@@ -92,10 +91,5 @@ module EE
def email_opted_in_source
email_opted_in_source_id == EMAIL_OPT_IN_SOURCE_ID_GITLAB_COM ? 'GitLab.com' : ''
end
override :increment_failed_attempts!
def increment_failed_attempts!
super if ::Gitlab::Database.read_write?
end
end
end
......@@ -137,18 +137,4 @@ describe EE::User do
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
......@@ -2858,4 +2858,18 @@ describe User do
it { is_expected.to be_truthy }
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
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