Sha256: 3968a5bd5dfd48a6d8c5f4fe865fc10384e88eac1aa6cb71affec9765109e6e1

Contents?: true

Size: 1.61 KB

Versions: 48

Compression:

Stored size: 1.61 KB

Contents

require 'test_helper'

class UserManagerTest < ::ActiveSupport::TestCase
  
  class MyAuthEngine < ::Incline::AuthEngineBase
    def initialize(options = {})
      @valid_password = options[:valid_password] || 'password'
    end
    
    def authenticate(email, password, client_ip)
      return nil unless password == @valid_password
      ::Incline::User.find_by(email: email)
    end
  end
  
  def setup
    @manager = ::Incline::UserManager.new valid_password: 'super-secret'
    @user = incline_users(:one)
  end
  
  test 'password should be based on database value' do
    assert_nil @manager.authenticate(@user.email, 'super-secret', '0.0.0.0')
    assert @manager.authenticate(@user.email, 'Password123', '0.0.0.0')
  end
  
  test 'password should be based on auth engine' do
    @manager.register_auth_engine ::UserManagerTest::MyAuthEngine, 'example.com'
    assert @manager.authenticate(@user.email, 'super-secret', '0.0.0.0')
    assert_nil @manager.authenticate(@user.email, 'Password123', '0.0.0.0')
  end
  
  test 'default instance also works with auth engine' do
    assert ::Incline::UserManager.authenticate(@user.email, 'Password123', '0.0.0.0')
    assert_nil ::Incline::UserManager.authenticate(@user.email, 'password', '0.0.0.0')
    begin
      ::Incline::UserManager.register_auth_engine(::UserManagerTest::MyAuthEngine, 'example.com')
      assert_nil ::Incline::UserManager.authenticate(@user.email, 'Password123', '0.0.0.0')
      assert ::Incline::UserManager.authenticate(@user.email, 'password', '0.0.0.0')
    ensure
      ::Incline::UserManager.clear_auth_engine('example.com')
    end
    
  end
  
  
  
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
incline-0.3.14 test/lib/user_manager_test.rb
incline-0.3.13 test/lib/user_manager_test.rb
incline-0.3.12 test/lib/user_manager_test.rb
incline-0.3.11 test/lib/user_manager_test.rb
incline-0.3.10 test/lib/user_manager_test.rb
incline-0.3.9 test/lib/user_manager_test.rb
incline-0.3.8 test/lib/user_manager_test.rb
incline-0.3.7 test/lib/user_manager_test.rb
incline-0.3.6 test/lib/user_manager_test.rb
incline-0.3.5 test/lib/user_manager_test.rb
incline-0.3.4 test/lib/user_manager_test.rb
incline-0.3.3 test/lib/user_manager_test.rb
incline-0.3.2 test/lib/user_manager_test.rb
incline-0.3.1 test/lib/user_manager_test.rb
incline-0.3.0 test/lib/user_manager_test.rb
incline-0.2.36 test/lib/user_manager_test.rb
incline-0.2.35 test/lib/user_manager_test.rb
incline-0.2.34 test/lib/user_manager_test.rb
incline-0.2.28 test/lib/user_manager_test.rb
incline-0.2.27 test/lib/user_manager_test.rb