Sha256: 51076096c4ccb4fc97c2fc3ab02e652066fcd60c5d9c3c66076c6639dcf7e40c

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), '../../../../test/test_helper'))
require 'test/unit'
require 'rubygems'

# Dummy code for overriding the default current_user behavior
module Cbac
  def current_user
    1
  end
end

###
# Tests the Cbac system for authorization with context roles
#
class CbacAuthorizeContextRolesTest <  ActiveSupport::TestCase
  include Cbac
  
  self.fixture_path = File.join(File.dirname(__FILE__), "fixtures")
  fixtures :all
  attr_accessor :authorize_context_eval_string

  # Setup defines the PrivilegeSet that is being used by all PrivilegeTest methods
  def setup
    return if PrivilegeSet.sets.include?(:cbac_context_role)
    PrivilegeSet.add :cbac_context_role, ""
    Privilege.resource  :cbac_context_role, "authorize/context/roles", :get
    ContextRole.add :authorize_context_role, "context.authorize_context_eval_string"
  end

  # Check to see if action is correctly authorized
  def test_authorize_ok
    self.authorize_context_eval_string = true
    assert_equal true, authorization_check("authorize/context", "roles", :get, self)
  end

  # Run authorization with incorrect authorization
  def test_authorize_incorrect_privilege
    self.authorize_context_eval_string = false
#    ContextRole.roles[:authorize_context_role] = "false"
    assert_equal false, authorization_check("authorize/context", "roles", :get, self)
#    ContextRole.roles[:authorize_context_role] = "true"
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cbac-0.5.3 test/test_cbac_authorize_context_roles.rb
cbac-0.5.2 test/test_cbac_authorize_context_roles.rb
cbac-0.5.1 test/test_cbac_authorize_context_roles.rb
cbac-0.3.1 test/test_cbac_authorize_context_roles.rb