summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-07-27 13:54:31 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-07-27 13:54:31 +0200
commit5f66d1de09d52988cfa0b519e61914713015c75c (patch)
tree389c725799e28a5d8a55f7b48938d54d66565aaa /lib
parent2ead2b97482e8e4cafbb5cdf38781df428ee0584 (diff)
downloadgitlab-ce-5f66d1de09d52988cfa0b519e61914713015c75c.tar.gz
Improve specs for blocked user tracker class
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/auth/blocked_user_tracker.rb41
1 files changed, 22 insertions, 19 deletions
diff --git a/lib/gitlab/auth/blocked_user_tracker.rb b/lib/gitlab/auth/blocked_user_tracker.rb
index 3d2011fb118..b6d2adc834b 100644
--- a/lib/gitlab/auth/blocked_user_tracker.rb
+++ b/lib/gitlab/auth/blocked_user_tracker.rb
@@ -10,21 +10,8 @@ module Gitlab
@env = env
end
- ##
- # Devise calls User#active_for_authentication? on the User model and then
- # throws an exception to Warden with User#inactive_message:
- # https://github.com/plataformatec/devise/blob/v4.2.1/lib/devise/hooks/activatable.rb#L8
- #
- # Since Warden doesn't pass the user record to the failure handler, we
- # need to do a database lookup with the username. We can limit the
- # lookups to happen when the user was blocked by checking the inactive
- # message passed along by Warden.
- #
- def has_user_blocked_message?
- strong_memoize(:user_blocked_message) do
- message = @env.dig('warden.options', :message)
- message == User::BLOCKED_MESSAGE
- end
+ def user_blocked?
+ user&.blocked?
end
def user
@@ -37,10 +24,7 @@ module Gitlab
User.by_login(login) if login.present?
end
- end
-
- def user_blocked?
- user&.blocked?
+ rescue TypeError
end
def log_blocked_user_activity!
@@ -51,6 +35,25 @@ module Gitlab
true
rescue TypeError
end
+
+ private
+
+ ##
+ # Devise calls User#active_for_authentication? on the User model and then
+ # throws an exception to Warden with User#inactive_message:
+ # https://github.com/plataformatec/devise/blob/v4.2.1/lib/devise/hooks/activatable.rb#L8
+ #
+ # Since Warden doesn't pass the user record to the failure handler, we
+ # need to do a database lookup with the username. We can limit the
+ # lookups to happen when the user was blocked by checking the inactive
+ # message passed along by Warden.
+ #
+ def has_user_blocked_message?
+ strong_memoize(:user_blocked_message) do
+ message = @env.dig('warden.options', :message)
+ message == User::BLOCKED_MESSAGE
+ end
+ end
end
end
end