Skip to content
Snippets Groups Projects
Commit de8f8cdf authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Improve authentication activity code readability

parent 719eeb0f
No related branches found
No related tags found
1 merge request!10495Merge Requests - Assignee
Loading
Loading
@@ -2,16 +2,18 @@ Rails.application.configure do |config|
Warden::Manager.after_set_user(scope: :user) do |user, auth, opts|
Gitlab::Auth::UniqueIpsLimiter.limit_user!(user)
 
activity = Gitlab::Auth::Activity.new(user, opts)
case opts[:event]
when :authentication
Gitlab::Auth::Activity.new(user, opts).user_authenticated!
activity.user_authenticated!
when :set_user
Gitlab::Auth::Activity.new(user, opts).user_authenticated!
Gitlab::Auth::Activity.new(user, opts).user_session_override!
activity.user_authenticated!
activity.user_session_override!
when :fetch # rubocop:disable Lint/EmptyWhen
# We ignore session fetch events
else
Gitlab::Auth::Activity.new(user, opts).user_session_override!
activity.user_session_override!
end
end
 
Loading
Loading
Loading
Loading
@@ -7,15 +7,15 @@ module Gitlab
extend Gitlab::Utils::StrongMemoize
 
COUNTERS = {
user_authenticated: 'Counter of total successful authentication events',
user_unauthenticated: 'Counter of total authentication failures',
user_not_found: 'Counter of total failed log-ins when user is unknown',
user_authenticated: 'Counter of successful authentication events',
user_unauthenticated: 'Counter of authentication failures',
user_not_found: 'Counter of failed log-ins when user is unknown',
user_password_invalid: 'Counter of failed log-ins with invalid password',
user_session_override: 'Counter of manual log-ins and sessions overrides',
user_session_destroyed: 'Counter of total user sessions being destroyed',
user_session_destroyed: 'Counter of user sessions being destroyed',
user_two_factor_authenticated: 'Counter of two factor authentications',
user_sessionless_authentication: 'Counter of sessionless authentications',
user_blocked: 'Counter of total sign in attempts when user is blocked'
user_blocked: 'Counter of sign in attempts when user is blocked'
}.freeze
 
def initialize(user, opts)
Loading
Loading
Loading
Loading
@@ -159,6 +159,7 @@ describe 'Login' do
 
it 'blocks login with invalid code' do
# TODO invalid 2FA code does not generate any events
# See gitlab-org/gitlab-ce#49785
 
enter_code('foo')
 
Loading
Loading
@@ -233,7 +234,7 @@ describe 'Login' do
context 'with invalid code' do
it 'blocks login' do
# TODO, invalid two factor authentication does not increment
# metrics / counters
# metrics / counters, see gitlab-org/gitlab-ce#49785
 
code = codes.sample
expect(user.invalidate_otp_backup_code!(code)).to eq true
Loading
Loading
@@ -267,7 +268,8 @@ describe 'Login' do
end
 
it 'signs user in without prompting for second factor' do
# TODO, OAuth authentication does not fire events
# TODO, OAuth authentication does not fire events,
# see gitlab-org/gitlab-ce#49786
 
expect(authentication_metrics)
.to increment(:user_authenticated_counter)
Loading
Loading
Loading
Loading
@@ -5,9 +5,8 @@ module StubMetrics
 
def stub_authentication_activity_metrics(debug: false)
authentication_metrics.each_counter do |name, metric, description|
double("#{metric} - #{description}").tap do |counter|
allow(authentication_metrics).to receive(name).and_return(counter)
end
allow(authentication_metrics).to receive(name)
.and_return(double("#{metric} - #{description}"))
end
 
debug_authentication_activity_metrics if debug
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment