Rename authentication activity observer methods

This commit is contained in:
Grzegorz Bizon 2018-07-19 10:34:58 +02:00
parent 416076610e
commit ac4b954c5f
4 changed files with 11 additions and 15 deletions

View file

@ -22,12 +22,12 @@ Rails.application.configure do |config|
end
Warden::Manager.after_set_user(scope: :user, only: :set_user) do |user, auth, opts|
Gitlab::Auth::Activity.new(opts).user_set_manually!
Gitlab::Auth::Activity.new(opts).user_session_override!
end
Warden::Manager.before_logout(scope: :user) do |user, auth, opts|
ActiveSession.destroy(user || auth.user, auth.request.session.id)
Gitlab::Auth::Activity.new(opts).user_logout!
Gitlab::Auth::Activity.new(opts).user_signed_out!
end
end

View file

@ -39,28 +39,18 @@ module Gitlab
self.class.user_session_fetched_counter.increment
end
def user_set_manually!
def user_session_override!
self.class.user_session_override_counter.increment
end
def user_logout!
def user_signed_out!
self.class.user_signed_out_counter.increment
end
class StubCounter
def initialize(metric)
Rails.logger.warn("METRIC #{metric}")
end
def increment
end
end
COUNTERS.each_pair do |metric, description|
define_singleton_method("#{metric}_counter") do
strong_memoize(metric) do
StubCounter.new(metric)
# Gitlab::Metrics.counter("gitlab_auth_#{metric}_total", description)
Gitlab::Metrics.counter("gitlab_auth_#{metric}_total".to_sym, description)
end
end
end

View file

@ -29,6 +29,7 @@ describe 'Login' do
User.delete_all
user = create(:admin, password_automatically_set: true)
expect(Gitlab::Auth::Activity).to increment(:user_authenticated_counter)
visit root_path
expect(current_path).to eq edit_user_password_path

View file

@ -0,0 +1,5 @@
RSpec::Matchers.define :increment do |counter|
match do |metric|
expect(metric.send(counter)).to receive(:increment)
end
end