Sha256: 69c42a2c15330e8d9b62bf0a2e3011963c7358198fe9ef8f39b4cbbe55cd4e42

Contents?: true

Size: 1.53 KB

Versions: 30

Compression:

Stored size: 1.53 KB

Contents

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
    user1 = create_user
    user1.ensure_authentication_token!
    user1.confirm!

    user2 = create_user
    user2.ensure_authentication_token!
    user2.confirm!

    user = User.find_for_token_authentication(:auth_token => {'$ne' => user1.authentication_token})
    assert_nil user
  end
end

Version data entries

30 entries across 30 versions & 4 rubygems

Version Path
devise-2.0.6 test/models/token_authenticatable_test.rb
devise_sociable-0.1.0 vendor/bundle/gems/devise-1.5.4/test/models/token_authenticatable_test.rb
devise-2.0.5 test/models/token_authenticatable_test.rb
devise-1.5.4 test/models/token_authenticatable_test.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/devise-2.0.4/test/models/token_authenticatable_test.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/devise-2.0.4/test/models/token_authenticatable_test.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/devise-2.0.4/test/models/token_authenticatable_test.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/devise-2.0.4/test/models/token_authenticatable_test.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/devise-2.0.4/test/models/token_authenticatable_test.rb
devise-2.0.4 test/models/token_authenticatable_test.rb
devise-2.0.2 test/models/token_authenticatable_test.rb
devise-2.0.1 test/models/token_authenticatable_test.rb
devise-2.0.0 test/models/token_authenticatable_test.rb
devise-2.0.0.rc2 test/models/token_authenticatable_test.rb
devise-2.0.0.rc test/models/token_authenticatable_test.rb
devise-1.5.3 test/models/token_authenticatable_test.rb
cloudfoundry-devise-1.5.2 test/models/token_authenticatable_test.rb
devise-1.5.2 test/models/token_authenticatable_test.rb
devise-1.5.1 test/models/token_authenticatable_test.rb
devise-1.5.0 test/models/token_authenticatable_test.rb