Sha256: ee173bb36a104c07cbb0227d1756f0eedac14e5c500f6b92c7b07185a8423759

Contents?: true

Size: 1.69 KB

Versions: 5

Compression:

Stored size: 1.69 KB

Contents

require "test_helper"

class RailsSso::SsoStrategyTest < ActiveSupport::TestCase
  test "does not store" do
    strategy = RailsSso::SsoStrategy.new(nil)

    refute strategy.store?
  end

  test "is valid when access token is present" do
    session = { access_token: "169783" }
    env = { "rack.session" => session }
    strategy = RailsSso::SsoStrategy.new(env)

    assert strategy.valid?
  end

  test "is valid when in test mode with access token mock" do
    env = { "rack.session" => {} }
    strategy = RailsSso::SsoStrategy.new(env)
    RailsSso.config.stubs(:test_mode).returns(true)
    RailsSso.config.stubs(:access_token_mock).returns("169783")

    assert strategy.valid?
  end

  test "is invalid when in test mode without access token mock" do
    env = { "rack.session" => {} }
    strategy = RailsSso::SsoStrategy.new(env)
    RailsSso.config.stubs(:test_mode).returns(true)
    RailsSso.config.stubs(:access_token_mock).returns(nil)

    refute strategy.valid?
  end

  test "is invalid when access token not present" do
    env = { "rack.session" => {} }
    strategy = RailsSso::SsoStrategy.new(env)

    refute strategy.valid?
  end

  test "authenticate! returns :success when sso can fetch user" do
    sso_app = mock()
    sso_app.stubs(:fetch_user_data).returns({ "uid" => "169783" })
    env = { "sso" => sso_app }
    strategy = RailsSso::SsoStrategy.new(env)

    assert_equal :success, strategy.authenticate!
  end

  test "authenticate! returns :failure when sso cannot fetch user" do
    sso_app = mock()
    sso_app.stubs(:fetch_user_data).returns(nil)
    env = { "sso" => sso_app }
    strategy = RailsSso::SsoStrategy.new(env)

    assert_equal :failure, strategy.authenticate!
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rails_sso-0.7.5 test/lib/rails_sso/sso_strategy_test.rb
rails_sso-0.7.4 test/lib/rails_sso/sso_strategy_test.rb
rails_sso-0.7.3 test/lib/rails_sso/sso_strategy_test.rb
rails_sso-0.7.2 test/lib/rails_sso/sso_strategy_test.rb
rails_sso-0.7.1 test/lib/rails_sso/sso_strategy_test.rb