1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00
heartcombo--devise/test/models/token_authenticatable_test.rb

56 lines
1.7 KiB
Ruby
Raw Normal View History

require 'test_helper'
class TokenAuthenticatableTest < ActiveSupport::TestCase
test 'should reset authentication token' do
user = new_user
user.reset_authentication_token
previous_token = user.authentication_token
user.reset_authentication_token
assert_not_equal previous_token, user.authentication_token
end
test 'should ensure authentication token' do
user = new_user
user.ensure_authentication_token
previous_token = user.authentication_token
user.ensure_authentication_token
assert_equal previous_token, user.authentication_token
end
test 'should authenticate a valid user with authentication token and return it' do
user = create_user
user.ensure_authentication_token!
user.confirm!
authenticated_user = User.find_for_token_authentication(:auth_token => user.authentication_token)
assert_equal authenticated_user, user
end
test 'should return nil when authenticating an invalid user by authentication token' do
user = create_user
user.ensure_authentication_token!
user.confirm!
authenticated_user = User.find_for_token_authentication(:auth_token => user.authentication_token.reverse)
assert_nil authenticated_user
end
test 'should not be subject to injection' do
2011-03-11 14:46:08 -05:00
user1 = create_user
user1.ensure_authentication_token!
user1.confirm!
2011-03-11 14:46:08 -05:00
user2 = create_user
user2.ensure_authentication_token!
user2.confirm!
2011-03-11 14:46:08 -05:00
user = User.find_for_token_authentication(:auth_token => {'$ne' => user1.authentication_token})
assert_nil user
end
test 'required_fields should contain the fields that Devise uses' do
assert_same_content Devise::Models::TokenAuthenticatable.required_fields(User), [
:authentication_token
]
end
end