mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
🪲 Fix strategy checking in #unlock_strategy_enabled? for :none and undefined strategies
A bug that if the unlock strategy was set to `:both`, it would return true for all & any inputs See #4072
This commit is contained in:
parent
8ac32f14b1
commit
7346ce709a
2 changed files with 25 additions and 1 deletions
|
@ -181,7 +181,9 @@ module Devise
|
|||
|
||||
# Is the unlock enabled for the given unlock strategy?
|
||||
def unlock_strategy_enabled?(strategy)
|
||||
[:both, strategy].include?(self.unlock_strategy)
|
||||
self.unlock_strategy == strategy ||
|
||||
# only :time and :email are subsets of the :both strategy
|
||||
(self.unlock_strategy == :both && [:time, :email].include?(strategy))
|
||||
end
|
||||
|
||||
# Is the lock enabled for the given lock strategy?
|
||||
|
|
|
@ -325,4 +325,26 @@ class LockableTest < ActiveSupport::TestCase
|
|||
user.lock_access!
|
||||
assert_equal :locked, user.unauthenticated_message
|
||||
end
|
||||
|
||||
test 'unlock_strategy_enabled? should return true for both, email, and time strategies if :both is used' do
|
||||
swap Devise, unlock_strategy: :both do
|
||||
user = create_user
|
||||
assert_equal true, user.unlock_strategy_enabled?(:both)
|
||||
assert_equal true, user.unlock_strategy_enabled?(:time)
|
||||
assert_equal true, user.unlock_strategy_enabled?(:email)
|
||||
assert_equal false, user.unlock_strategy_enabled?(:none)
|
||||
assert_equal false, user.unlock_strategy_enabled?(:an_undefined_strategy)
|
||||
end
|
||||
end
|
||||
|
||||
test 'unlock_strategy_enabled? should return true only for the configured strategy' do
|
||||
swap Devise, unlock_strategy: :email do
|
||||
user = create_user
|
||||
assert_equal false, user.unlock_strategy_enabled?(:both)
|
||||
assert_equal false, user.unlock_strategy_enabled?(:time)
|
||||
assert_equal true, user.unlock_strategy_enabled?(:email)
|
||||
assert_equal false, user.unlock_strategy_enabled?(:none)
|
||||
assert_equal false, user.unlock_strategy_enabled?(:an_undefined_strategy)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue