summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-07-19 10:34:58 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-07-19 10:34:58 +0200
commitac4b954c5fabbfa98fb72d88526a30713a20af5d (patch)
treea1fccb6ca951e96374e54872b548f160decd034b
parent416076610e7b1674669ad33bae604155f55a3d02 (diff)
downloadgitlab-ce-ac4b954c5fabbfa98fb72d88526a30713a20af5d.tar.gz
Rename authentication activity observer methods
-rw-r--r--config/initializers/warden.rb4
-rw-r--r--lib/gitlab/auth/activity.rb16
-rw-r--r--spec/features/users/login_spec.rb1
-rw-r--r--spec/support/prometheus/custom_matchers.rb5
4 files changed, 11 insertions, 15 deletions
diff --git a/config/initializers/warden.rb b/config/initializers/warden.rb
index c75a76a3118..450564be1a3 100644
--- a/config/initializers/warden.rb
+++ b/config/initializers/warden.rb
@@ -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
diff --git a/lib/gitlab/auth/activity.rb b/lib/gitlab/auth/activity.rb
index c0254ca81cd..b8a0979ac35 100644
--- a/lib/gitlab/auth/activity.rb
+++ b/lib/gitlab/auth/activity.rb
@@ -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
diff --git a/spec/features/users/login_spec.rb b/spec/features/users/login_spec.rb
index 21891b9ccda..7a268c54de5 100644
--- a/spec/features/users/login_spec.rb
+++ b/spec/features/users/login_spec.rb
@@ -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
diff --git a/spec/support/prometheus/custom_matchers.rb b/spec/support/prometheus/custom_matchers.rb
new file mode 100644
index 00000000000..2ad3b8a7fce
--- /dev/null
+++ b/spec/support/prometheus/custom_matchers.rb
@@ -0,0 +1,5 @@
+RSpec::Matchers.define :increment do |counter|
+ match do |metric|
+ expect(metric.send(counter)).to receive(:increment)
+ end
+end