mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Sanity check the serialized class.
This commit is contained in:
parent
3805bf2f26
commit
4f6dfefe0e
2 changed files with 14 additions and 0 deletions
|
@ -93,6 +93,7 @@ module Devise
|
|||
# Hook to serialize user from session. Overwrite if you want.
|
||||
def serialize_from_session(keys)
|
||||
klass, id = keys
|
||||
raise "#{self} cannot serialize from #{klass} session since it's not its ancestors" unless klass <= self
|
||||
klass.find_by_id(id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -145,4 +145,17 @@ class AuthenticatableTest < ActiveSupport::TestCase
|
|||
user = create_user
|
||||
assert_equal user.id, User.serialize_from_session([User, user.id]).id
|
||||
end
|
||||
|
||||
test 'should not serialize another klass from session' do
|
||||
user = create_user
|
||||
assert_raise RuntimeError, /ancestors/ do
|
||||
User.serialize_from_session([Admin, user.id])
|
||||
end
|
||||
end
|
||||
|
||||
test 'should serialize another klass from session' do
|
||||
user = create_user
|
||||
klass = Class.new(User)
|
||||
assert_equal user.id, User.serialize_from_session([klass, user.id]).id
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue