ae_declarative_authorization 0.10.1 → 0.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +37 -0
- data/.gitignore +32 -0
- data/.ruby-version +1 -0
- data/declarative_authorization.gemspec +1 -1
- data/lib/declarative_authorization/version.rb +1 -1
- metadata +6 -70
- data/Gemfile.lock +0 -138
- data/gemfiles/ruby_2.3.3_rails507.gemfile +0 -12
- data/gemfiles/ruby_2.3.3_rails507.gemfile.lock +0 -164
- data/gemfiles/ruby_2.3.3_rails516.gemfile +0 -12
- data/gemfiles/ruby_2.3.3_rails516.gemfile.lock +0 -164
- data/gemfiles/ruby_2.3.3_rails521.gemfile +0 -12
- data/gemfiles/ruby_2.3.3_rails521.gemfile.lock +0 -172
- data/gemfiles/ruby_2.3.3_rails522.gemfile +0 -12
- data/gemfiles/ruby_2.3.3_rails522.gemfile.lock +0 -172
- data/gemfiles/ruby_2.5.3_rails507.gemfile +0 -12
- data/gemfiles/ruby_2.5.3_rails507.gemfile.lock +0 -164
- data/gemfiles/ruby_2.5.3_rails516.gemfile +0 -12
- data/gemfiles/ruby_2.5.3_rails516.gemfile.lock +0 -164
- data/gemfiles/ruby_2.5.3_rails521.gemfile +0 -12
- data/gemfiles/ruby_2.5.3_rails521.gemfile.lock +0 -172
- data/gemfiles/ruby_2.5.3_rails522.gemfile +0 -12
- data/gemfiles/ruby_2.5.3_rails522.gemfile.lock +0 -172
- data/gemfiles/ruby_2.6.2_rails507.gemfile +0 -12
- data/gemfiles/ruby_2.6.2_rails507.gemfile.lock +0 -164
- data/gemfiles/ruby_2.6.2_rails516.gemfile +0 -12
- data/gemfiles/ruby_2.6.2_rails516.gemfile.lock +0 -164
- data/gemfiles/ruby_2.6.2_rails521.gemfile +0 -12
- data/gemfiles/ruby_2.6.2_rails521.gemfile.lock +0 -172
- data/gemfiles/ruby_2.6.2_rails522.gemfile +0 -12
- data/gemfiles/ruby_2.6.2_rails522.gemfile.lock +0 -172
- data/log/test.log +0 -89694
- data/pkg/ae_declarative_authorization-0.10.0.gem +0 -0
- data/pkg/ae_declarative_authorization-0.9.0.gem +0 -0
- data/pkg/ae_declarative_authorization-0.9.0.tim1.gem +0 -0
- data/pkg/ae_declarative_authorization-0.9.1.gem +0 -0
- data/pkg/ae_declarative_authorization-0.9.2.gem +0 -0
- data/test/authorization_test.rb +0 -1189
- data/test/controller_filter_resource_access_test.rb +0 -573
- data/test/database.yml +0 -3
- data/test/dsl_reader_test.rb +0 -178
- data/test/functional/filter_access_to_with_id_in_scope_test.rb +0 -88
- data/test/functional/no_filter_access_to_test.rb +0 -79
- data/test/functional/params_block_arity_test.rb +0 -39
- data/test/grape_api_test.rb +0 -508
- data/test/helper_test.rb +0 -248
- data/test/maintenance_test.rb +0 -46
- data/test/model_test.rb +0 -1840
- data/test/profiles/access_checking +0 -100
- data/test/rails_controller_test.rb +0 -478
- data/test/schema.sql +0 -60
- data/test/test_helper.rb +0 -117
- data/test/test_support/grape.rb +0 -93
- data/test/test_support/minitest_compatibility.rb +0 -27
- data/test/test_support/rails.rb +0 -69
data/test/schema.sql
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
CREATE TABLE 'test_models' (
|
2
|
-
'id' INTEGER PRIMARY KEY NOT NULL,
|
3
|
-
'test_attr_through_id' INTEGER,
|
4
|
-
'content' text,
|
5
|
-
'country_id' integer,
|
6
|
-
'created_at' datetime,
|
7
|
-
'updated_at' datetime
|
8
|
-
);
|
9
|
-
|
10
|
-
CREATE TABLE 'test_attrs' (
|
11
|
-
'id' INTEGER PRIMARY KEY NOT NULL,
|
12
|
-
'test_model_id' integer,
|
13
|
-
'test_another_model_id' integer,
|
14
|
-
'test_a_third_model_id' integer,
|
15
|
-
'branch_id' integer,
|
16
|
-
'company_id' integer,
|
17
|
-
'test_attr_through_id' INTEGER,
|
18
|
-
'n_way_join_item_id' INTEGER,
|
19
|
-
'test_model_security_model_id' integer,
|
20
|
-
'attr' integer default 1
|
21
|
-
);
|
22
|
-
|
23
|
-
CREATE TABLE 'test_attr_throughs' (
|
24
|
-
'id' INTEGER PRIMARY KEY NOT NULL,
|
25
|
-
'test_attr_id' integer
|
26
|
-
);
|
27
|
-
|
28
|
-
CREATE TABLE 'test_model_security_models' (
|
29
|
-
'id' INTEGER PRIMARY KEY NOT NULL,
|
30
|
-
'attr' integer default 1,
|
31
|
-
'attr_2' integer default 1,
|
32
|
-
'test_attr_id' integer
|
33
|
-
);
|
34
|
-
|
35
|
-
CREATE TABLE 'n_way_join_items' (
|
36
|
-
'id' INTEGER PRIMARY KEY NOT NULL
|
37
|
-
);
|
38
|
-
|
39
|
-
CREATE TABLE 'branches' (
|
40
|
-
'id' INTEGER PRIMARY KEY NOT NULL,
|
41
|
-
'company_id' integer,
|
42
|
-
'test_model_id' integer,
|
43
|
-
'name' text
|
44
|
-
);
|
45
|
-
|
46
|
-
CREATE TABLE 'companies' (
|
47
|
-
'id' INTEGER PRIMARY KEY NOT NULL,
|
48
|
-
'country_id' integer,
|
49
|
-
'type' text,
|
50
|
-
'name' text
|
51
|
-
);
|
52
|
-
|
53
|
-
CREATE TABLE 'countries' (
|
54
|
-
'id' INTEGER PRIMARY KEY NOT NULL,
|
55
|
-
'name' text
|
56
|
-
);
|
57
|
-
|
58
|
-
CREATE TABLE 'users' (
|
59
|
-
'id' INTEGER PRIMARY KEY NOT NULL
|
60
|
-
);
|
data/test/test_helper.rb
DELETED
@@ -1,117 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
|
11
|
-
require 'minitest/autorun'
|
12
|
-
|
13
|
-
ENV['RAILS_ENV'] = 'test'
|
14
|
-
|
15
|
-
require 'rails/all'
|
16
|
-
require 'test_support/minitest_compatibility'
|
17
|
-
|
18
|
-
DA_ROOT = Pathname.new(File.expand_path("..", File.dirname(__FILE__)))
|
19
|
-
|
20
|
-
require DA_ROOT + File.join(%w{lib declarative_authorization authorization})
|
21
|
-
require DA_ROOT + File.join(%w{lib declarative_authorization maintenance})
|
22
|
-
require DA_ROOT + File.join(%w{lib declarative_authorization test helpers})
|
23
|
-
|
24
|
-
class MockDataObject
|
25
|
-
def initialize(attrs = {})
|
26
|
-
attrs.each do |key, value|
|
27
|
-
instance_variable_set(:"@#{key}", value)
|
28
|
-
self.class.class_eval do
|
29
|
-
attr_reader key
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.descends_from_active_record?
|
35
|
-
true
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.table_name
|
39
|
-
name.tableize
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.name
|
43
|
-
"Mock"
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.find(*args)
|
47
|
-
raise StandardError, "Couldn't find #{self.name} with id #{args[0].inspect}" unless args[0]
|
48
|
-
new :id => args[0]
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.find_or_initialize_by(args)
|
52
|
-
raise StandardError, "Syntax error: find_or_initialize by expects a hash: User.find_or_initialize_by(:id => @user.id)" unless args.is_a?(Hash)
|
53
|
-
new args
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
class MockUser < MockDataObject
|
58
|
-
def initialize(*roles)
|
59
|
-
options = roles.last.is_a?(::Hash) ? roles.pop : {}
|
60
|
-
super({:role_symbols => roles, :login => hash}.merge(options))
|
61
|
-
end
|
62
|
-
|
63
|
-
def initialize_copy(other)
|
64
|
-
@role_symbols = @role_symbols.clone
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
class User < ActiveRecord::Base
|
69
|
-
attr_accessor :role_symbols
|
70
|
-
|
71
|
-
scope :visible_by, ->(user) { where(id: user.id) }
|
72
|
-
end
|
73
|
-
|
74
|
-
module Test
|
75
|
-
module Unit
|
76
|
-
class TestCase < Minitest::Test
|
77
|
-
include Authorization::TestHelper
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
module ActiveSupport
|
83
|
-
class TestCase
|
84
|
-
include Authorization::TestHelper
|
85
|
-
|
86
|
-
def request!(user, action, reader, params = {})
|
87
|
-
action = action.to_sym if action.is_a?(String)
|
88
|
-
@controller.current_user = user
|
89
|
-
@controller.authorization_engine = Authorization::Engine.new(reader)
|
90
|
-
|
91
|
-
((params.delete(:clear) || []) + [:@authorized]).each do |var|
|
92
|
-
@controller.instance_variable_set(var, nil)
|
93
|
-
end
|
94
|
-
|
95
|
-
method = params.delete(:method) || :get
|
96
|
-
|
97
|
-
if Rails.version >= '5.0'
|
98
|
-
send method, action, params: params
|
99
|
-
else
|
100
|
-
send method, action, params
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def setup
|
105
|
-
@routes = Rails.application.routes
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
require 'test_support/rails'
|
111
|
-
|
112
|
-
begin
|
113
|
-
require 'grape'
|
114
|
-
require 'test_support/grape'
|
115
|
-
rescue LoadError
|
116
|
-
# Grape is not defined in the gemspec so the Grape tests will not be run
|
117
|
-
end
|
data/test/test_support/grape.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
require 'grape'
|
2
|
-
require 'mocha/minitest'
|
3
|
-
|
4
|
-
require DA_ROOT + File.join(%w{lib declarative_authorization controller grape})
|
5
|
-
|
6
|
-
class ApiTestCase < ActiveSupport::TestCase
|
7
|
-
include Rack::Test::Methods
|
8
|
-
include Authorization::TestHelper
|
9
|
-
|
10
|
-
class << self
|
11
|
-
attr_accessor :api
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_accessor :last_endpoint
|
15
|
-
|
16
|
-
def self.tests(api)
|
17
|
-
@api = api
|
18
|
-
end
|
19
|
-
|
20
|
-
def app
|
21
|
-
self.class.api
|
22
|
-
end
|
23
|
-
|
24
|
-
def request!(user, action, reader, params = {}, &block)
|
25
|
-
Grape::Endpoint.before_each do |endpoint|
|
26
|
-
self.last_endpoint = endpoint
|
27
|
-
|
28
|
-
engine = Authorization::Engine.new(reader)
|
29
|
-
endpoint.stubs(:current_user).returns(user)
|
30
|
-
endpoint.stubs(:authorization_engine).returns(engine)
|
31
|
-
|
32
|
-
((params.delete(:clear) || []) + [:@authorized]).each do |var|
|
33
|
-
endpoint.instance_variable_set(var, nil)
|
34
|
-
end
|
35
|
-
|
36
|
-
yield endpoint if block_given?
|
37
|
-
end
|
38
|
-
|
39
|
-
method = params.delete(:method) || :get
|
40
|
-
send method, action #, params
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
class MocksAPI < Grape::API
|
45
|
-
include Authorization::Controller::Grape
|
46
|
-
|
47
|
-
helpers do
|
48
|
-
attr_accessor :authorized
|
49
|
-
|
50
|
-
def authorization_engine
|
51
|
-
end
|
52
|
-
|
53
|
-
def current_user
|
54
|
-
end
|
55
|
-
|
56
|
-
def authorized?
|
57
|
-
!!@authorized
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
def self.define_action_methods(*methods)
|
63
|
-
resource_name = name.to_param.underscore.gsub(/_api$/, '')
|
64
|
-
resources resource_name do
|
65
|
-
methods.each do |method|
|
66
|
-
get method do
|
67
|
-
@authorized = true
|
68
|
-
'nothing'
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.define_resource_actions
|
75
|
-
define_action_methods :index, :show, :edit, :update, :new, :create, :destroy
|
76
|
-
end
|
77
|
-
|
78
|
-
def logger(*args)
|
79
|
-
Class.new do
|
80
|
-
def warn(*args)
|
81
|
-
#p args
|
82
|
-
end
|
83
|
-
alias_method :info, :warn
|
84
|
-
alias_method :debug, :warn
|
85
|
-
def warn?; end
|
86
|
-
alias_method :info?, :warn?
|
87
|
-
alias_method :debug?, :warn?
|
88
|
-
end.new
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class ApplicationAPI < ActionController::Base
|
93
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'minitest/assertions'
|
2
|
-
|
3
|
-
module Minitest
|
4
|
-
module Assertions
|
5
|
-
|
6
|
-
# test/unit backwards compatibility methods
|
7
|
-
alias :assert_raise :assert_raises
|
8
|
-
alias :assert_not_empty :refute_empty
|
9
|
-
alias :assert_not_equal :refute_equal
|
10
|
-
alias :assert_not_in_delta :refute_in_delta
|
11
|
-
alias :assert_not_in_epsilon :refute_in_epsilon
|
12
|
-
alias :assert_not_includes :refute_includes
|
13
|
-
alias :assert_not_instance_of :refute_instance_of
|
14
|
-
alias :assert_not_kind_of :refute_kind_of
|
15
|
-
alias :assert_no_match :refute_match
|
16
|
-
alias :assert_not_nil :refute_nil
|
17
|
-
alias :assert_not_operator :refute_operator
|
18
|
-
alias :assert_not_predicate :refute_predicate
|
19
|
-
alias :assert_not_respond_to :refute_respond_to
|
20
|
-
alias :assert_not_same :refute_same
|
21
|
-
|
22
|
-
def assert_nothing_raised(*)
|
23
|
-
yield
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
data/test/test_support/rails.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require DA_ROOT + File.join(%w{lib declarative_authorization controller rails})
|
2
|
-
|
3
|
-
if Rails.version < '4.2'
|
4
|
-
raise "Unsupported Rails version #{Rails.version}"
|
5
|
-
end
|
6
|
-
|
7
|
-
puts "Testing against rails #{Rails::VERSION::STRING}"
|
8
|
-
|
9
|
-
if Rails.version >= '5.0'
|
10
|
-
require 'rails-controller-testing'
|
11
|
-
Rails::Controller::Testing.install
|
12
|
-
end
|
13
|
-
|
14
|
-
class TestApp
|
15
|
-
class Application < ::Rails::Application
|
16
|
-
config.eager_load = false
|
17
|
-
config.secret_key_base = 'testingpurposesonly'
|
18
|
-
config.active_support.deprecation = :stderr
|
19
|
-
config.paths['config/database'] = File.expand_path('../../database.yml', __FILE__)
|
20
|
-
config.active_support.test_order = :random
|
21
|
-
initialize!
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class MocksController < ActionController::Base
|
26
|
-
attr_accessor :current_user
|
27
|
-
attr_writer :authorization_engine
|
28
|
-
|
29
|
-
def authorized?
|
30
|
-
!!@authorized
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.define_action_methods(*methods)
|
34
|
-
methods.each do |method|
|
35
|
-
define_method method do
|
36
|
-
@authorized = true
|
37
|
-
render :plain => 'nothing'
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.define_resource_actions
|
43
|
-
define_action_methods :index, :show, :edit, :update, :new, :create, :destroy
|
44
|
-
end
|
45
|
-
|
46
|
-
def logger(*args)
|
47
|
-
Class.new do
|
48
|
-
def warn(*args)
|
49
|
-
#p args
|
50
|
-
end
|
51
|
-
alias_method :info, :warn
|
52
|
-
alias_method :debug, :warn
|
53
|
-
def warn?; end
|
54
|
-
alias_method :info?, :warn?
|
55
|
-
alias_method :debug?, :warn?
|
56
|
-
end.new
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
class ApplicationController < ActionController::Base
|
61
|
-
end
|
62
|
-
|
63
|
-
Rails.application.routes.draw do
|
64
|
-
match '/name/spaced_things(/:action)' => 'name/spaced_things', via: [:get, :post, :put, :patch, :delete]
|
65
|
-
match '/deep/name_spaced/things(/:action)' => 'deep/name_spaced/things', via: [:get, :post, :put, :patch, :delete]
|
66
|
-
match '/:controller(/:action(/:id))', via: [:get, :post, :put, :patch, :delete]
|
67
|
-
end
|
68
|
-
|
69
|
-
ActionController::Base.send :include, Authorization::Controller::Rails
|