Sha256: 40ca6a1bc1d361bef070e6973db5ca36df0513dfbc657a7f90f058663fe49df9

Contents?: true

Size: 1.47 KB

Versions: 13

Compression:

Stored size: 1.47 KB

Contents

require 'test_helper'

describe PrxAuth::Rails::Token do
  let (:aur) { { "123" => "test_app:read other_namespace:write", "*" => "test_app:add" } }
  let (:sub) { "123" }
  let (:scope) { "one two three" }
  let (:token_data) { Rack::PrxAuth::TokenData.new("aur" => aur, "scope" => scope, "sub" => sub)}
  let (:mock_token_data) { Minitest::Mock.new(token_data) }
  let (:token) { PrxAuth::Rails::Token.new(mock_token_data) }

  it 'automatically namespaces requests' do
    mock_token_data.expect(:authorized?, true, ["123", :test_app, :read])
    assert token.authorized?("123", :read)

    mock_token_data.expect(:resources, ["123"], [:test_app, :read])
    assert token.resources(:read) === ['123']

    mock_token_data.expect(:globally_authorized?, true, [:test_app, :add])
    assert token.globally_authorized?(:add) 

    mock_token_data.verify
  end

  it 'allows unscoped calls to authorized?' do
    assert token.authorized?("123")
  end

  it 'allows unscoped calls to resources' do
    assert token.resources == [ "123" ]
  end

  it 'allows manual setting of namespace' do
    assert token.authorized?("123", :other_namespace, :write)
    assert !token.authorized?("123", :other_namespace, :read)

    assert token.resources(:other_namespace, :write) == ["123"]
    assert token.resources(:other_namespace, :read) == []

    assert token.globally_authorized?(:add)
    assert token.globally_authorized?(:test_app, :add)
    assert !token.globally_authorized?(:other_namespace, :add)
  end

  
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
prx_auth-rails-4.1.0 test/prx_auth/rails/token_test.rb
prx_auth-rails-4.0.0 test/prx_auth/rails/token_test.rb
prx_auth-rails-3.0.1 test/prx_auth/rails/token_test.rb
prx_auth-rails-3.0.0 test/prx_auth/rails/token_test.rb
prx_auth-rails-2.1.0 test/prx_auth/rails/token_test.rb
prx_auth-rails-2.0.0 test/prx_auth/rails/token_test.rb
prx_auth-rails-1.8.0 test/prx_auth/rails/token_test.rb
prx_auth-rails-1.7.0 test/prx_auth/rails/token_test.rb
prx_auth-rails-1.6.0 test/prx_auth/rails/token_test.rb
prx_auth-rails-1.5.0 test/prx_auth/rails/token_test.rb
prx_auth-rails-1.4.1 test/prx_auth/rails/token_test.rb
prx_auth-rails-1.4.0 test/prx_auth/rails/token_test.rb
prx_auth-rails-1.3.0 test/prx_auth/rails/token_test.rb