Compare commits

...

5 Commits

Author SHA1 Message Date
Ulisses Almeida
12029092b8 Release 4.0.3 2016-05-15 12:07:40 -03:00
Ralin Chimev
a96b920277 Fix overwriting the remember_token when a valid one already exists (#4101)
The remember_token should not get overwritten when a user is
signing in and a valid token already exists.

Fixes #3950.
2016-05-15 12:05:49 -03:00
Ulisses Almeida
b8e496a33d Release 4.0.2 2016-05-02 23:41:42 -03:00
Justin Bull
0813debb0b Extract list of both strategies into class constant 2016-05-02 23:38:51 -03:00
Justin Bull
d7d9b9e258 🪲 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
2016-05-02 23:38:39 -03:00
7 changed files with 54 additions and 7 deletions

View File

@@ -1,4 +1,13 @@
### Unreleased
### 4.0.3 - 2016-05-15
* bug fixes
* Fix overwriting the remember_token when a valid one already exists (by @ralinchimev).
### 4.0.2 - 2016-04-25
* bug fixes
* Fix strategy checking in `Lockable#unlock_strategy_enabled?` for `:none`
and `:undefined` strategies. (by @f3ndot)
### 4.0.1 - 2016-04-25

View File

@@ -1,7 +1,7 @@
PATH
remote: .
specs:
devise (4.0.1)
devise (4.0.3)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 5.1)
@@ -134,7 +134,7 @@ GEM
rake (11.0.1)
rdoc (4.2.2)
json (~> 1.4)
responders (2.1.2)
responders (2.2.0)
railties (>= 4.2.0, < 5.1)
ruby-openid (2.7.0)
sprockets (3.5.2)
@@ -176,4 +176,4 @@ DEPENDENCIES
webrat (= 0.7.3)
BUNDLED WITH
1.11.2
1.12.3

View File

@@ -155,6 +155,9 @@ module Devise
end
module ClassMethods
# List of strategies that are enabled/supported if :both is used.
BOTH_STRATEGIES = [:time, :email]
# Attempt to find a user by its unlock keys. If a record is found, send new
# unlock instructions to it. If not user is found, returns a new user
# with an email not found error.
@@ -181,7 +184,8 @@ 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 ||
(self.unlock_strategy == :both && BOTH_STRATEGIES.include?(strategy))
end
# Is the lock enabled for the given lock strategy?

View File

@@ -46,7 +46,7 @@ module Devise
end
def remember_me!
self.remember_token = self.class.remember_token if respond_to?(:remember_token)
self.remember_token ||= self.class.remember_token if respond_to?(:remember_token)
self.remember_created_at ||= Time.now.utc
save(validate: false) if self.changed?
end

View File

@@ -1,3 +1,3 @@
module Devise
VERSION = "4.0.1".freeze
VERSION = "4.0.3".freeze
end

View File

@@ -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

View File

@@ -16,6 +16,18 @@ class RememberableTest < ActiveSupport::TestCase
assert user.remember_created_at
end
test 'remember_me should not generate a new token if valid token exists' do
user = create_user
user.singleton_class.send(:attr_accessor, :remember_token)
User.to_adapter.expects(:find_first).returns(nil)
user.remember_me!
existing_token = user.remember_token
user.remember_me!
assert_equal existing_token, user.remember_token
end
test 'forget_me should not clear remember token if using salt' do
user = create_user
user.remember_me!