ae_declarative_authorization 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,3 +18,23 @@ UsersController
18
18
  ParamsBlockArityTest::ParamsBlockArityTestController
19
19
  UsersController
20
20
  ParamsBlockArityTest::ParamsBlockArityTestController
21
+ UsersController
22
+ ParamsBlockArityTest::ParamsBlockArityTestController
23
+ UsersController
24
+ ParamsBlockArityTest::ParamsBlockArityTestController
25
+ UsersController
26
+ ParamsBlockArityTest::ParamsBlockArityTestController
27
+ UsersController
28
+ ParamsBlockArityTest::ParamsBlockArityTestController
29
+ UsersController
30
+ ParamsBlockArityTest::ParamsBlockArityTestController
31
+ UsersController
32
+ ParamsBlockArityTest::ParamsBlockArityTestController
33
+ UsersController
34
+ ParamsBlockArityTest::ParamsBlockArityTestController
35
+ UsersController
36
+ ParamsBlockArityTest::ParamsBlockArityTestController
37
+ UsersController
38
+ ParamsBlockArityTest::ParamsBlockArityTestController
39
+ UsersController
40
+ ParamsBlockArityTest::ParamsBlockArityTestController
@@ -266,10 +266,10 @@ class LoadObjectControllerTest < ActionController::TestCase
266
266
  request!(MockUser.new(:test_role), "show", reader)
267
267
  end
268
268
 
269
- Authorization::AuthorizationInController.failed_auto_loading_is_not_found = false
269
+ Authorization::Controller::Runtime.failed_auto_loading_is_not_found = false
270
270
  request!(MockUser.new(:test_role), "show", reader)
271
271
  assert !@controller.authorized?
272
- Authorization::AuthorizationInController.failed_auto_loading_is_not_found = true
272
+ Authorization::Controller::Runtime.failed_auto_loading_is_not_found = true
273
273
  end
274
274
 
275
275
  def test_filter_access_with_object_load_custom
data/test/test_helper.rb CHANGED
@@ -15,21 +15,9 @@ ENV['RAILS_ENV'] = 'test'
15
15
  require 'rails/all'
16
16
  require 'test_support/minitest_compatibility'
17
17
 
18
- if Rails.version < '4.2'
19
- raise "Unsupported Rails version #{Rails.version}"
20
- end
21
-
22
- puts "Testing against rails #{Rails::VERSION::STRING}"
23
-
24
- if Rails.version >= '5.0'
25
- require 'rails-controller-testing'
26
- Rails::Controller::Testing.install
27
- end
28
-
29
18
  DA_ROOT = Pathname.new(File.expand_path("..", File.dirname(__FILE__)))
30
19
 
31
20
  require DA_ROOT + File.join(%w{lib declarative_authorization authorization})
32
- require DA_ROOT + File.join(%w{lib declarative_authorization in_controller})
33
21
  require DA_ROOT + File.join(%w{lib declarative_authorization maintenance})
34
22
  require DA_ROOT + File.join(%w{lib declarative_authorization test helpers})
35
23
 
@@ -77,69 +65,12 @@ class MockUser < MockDataObject
77
65
  end
78
66
  end
79
67
 
80
- class MocksController < ActionController::Base
81
- attr_accessor :current_user
82
- attr_writer :authorization_engine
83
-
84
- def authorized?
85
- !!@authorized
86
- end
87
-
88
- def self.define_action_methods(*methods)
89
- methods.each do |method|
90
- define_method method do
91
- @authorized = true
92
- render :plain => 'nothing'
93
- end
94
- end
95
- end
96
-
97
- def self.define_resource_actions
98
- define_action_methods :index, :show, :edit, :update, :new, :create, :destroy
99
- end
100
-
101
- def logger(*args)
102
- Class.new do
103
- def warn(*args)
104
- #p args
105
- end
106
- alias_method :info, :warn
107
- alias_method :debug, :warn
108
- def warn?; end
109
- alias_method :info?, :warn?
110
- alias_method :debug?, :warn?
111
- end.new
112
- end
113
- end
114
-
115
68
  class User < ActiveRecord::Base
116
69
  attr_accessor :role_symbols
117
70
 
118
71
  scope :visible_by, ->(user) { where(id: user.id) }
119
72
  end
120
73
 
121
- class TestApp
122
- class Application < ::Rails::Application
123
- config.eager_load = false
124
- config.secret_key_base = 'testingpurposesonly'
125
- config.active_support.deprecation = :stderr
126
- config.paths['config/database'] = File.expand_path('../database.yml', __FILE__)
127
- config.active_support.test_order = :random
128
- initialize!
129
- end
130
- end
131
-
132
- class ApplicationController < ActionController::Base
133
- end
134
-
135
- Rails.application.routes.draw do
136
- match '/name/spaced_things(/:action)' => 'name/spaced_things', via: [:get, :post, :put, :patch, :delete]
137
- match '/deep/name_spaced/things(/:action)' => 'deep/name_spaced/things', via: [:get, :post, :put, :patch, :delete]
138
- match '/:controller(/:action(/:id))', via: [:get, :post, :put, :patch, :delete]
139
- end
140
-
141
- ActionController::Base.send :include, Authorization::AuthorizationInController
142
-
143
74
  module Test
144
75
  module Unit
145
76
  class TestCase < Minitest::Test
@@ -160,10 +91,13 @@ module ActiveSupport
160
91
  ((params.delete(:clear) || []) + [:@authorized]).each do |var|
161
92
  @controller.instance_variable_set(var, nil)
162
93
  end
94
+
95
+ method = params.delete(:method) || :get
96
+
163
97
  if Rails.version >= '5.0'
164
- get action, params: params
98
+ send method, action, params: params
165
99
  else
166
- get action, params
100
+ send method, action, params
167
101
  end
168
102
  end
169
103
 
@@ -172,3 +106,12 @@ module ActiveSupport
172
106
  end
173
107
  end
174
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
@@ -0,0 +1,93 @@
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
@@ -0,0 +1,69 @@
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ae_declarative_authorization
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - AppFolio
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-08-17 00:00:00.000000000 Z
12
+ date: 2018-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: blockenspiel
@@ -69,14 +69,17 @@ files:
69
69
  - gemfiles/rails507.gemfile
70
70
  - gemfiles/rails507.gemfile.lock
71
71
  - gemfiles/rails516.gemfile
72
- - gemfiles/rails516.gemfile.lock
73
72
  - gemfiles/rails521.gemfile
74
73
  - gemfiles/rails521.gemfile.lock
75
74
  - init.rb
76
75
  - lib/declarative_authorization.rb
77
76
  - lib/declarative_authorization/authorization.rb
77
+ - lib/declarative_authorization/controller/dsl.rb
78
+ - lib/declarative_authorization/controller/grape.rb
79
+ - lib/declarative_authorization/controller/rails.rb
80
+ - lib/declarative_authorization/controller/runtime.rb
81
+ - lib/declarative_authorization/controller_permission.rb
78
82
  - lib/declarative_authorization/helper.rb
79
- - lib/declarative_authorization/in_controller.rb
80
83
  - lib/declarative_authorization/in_model.rb
81
84
  - lib/declarative_authorization/maintenance.rb
82
85
  - lib/declarative_authorization/obligation_scope.rb
@@ -89,23 +92,26 @@ files:
89
92
  - lib/generators/authorization/rules/templates/authorization_rules.rb
90
93
  - lib/tasks/authorization_tasks.rake
91
94
  - log/test.log
92
- - pkg/ae_declarative_authorization-0.7.1.gem
93
- - pkg/ae_declarative_authorization-0.8.0.gem
95
+ - pkg/ae_declarative_authorization-0.9.0.gem
96
+ - pkg/ae_declarative_authorization-0.9.0.tim1.gem
94
97
  - test/authorization_test.rb
95
98
  - test/controller_filter_resource_access_test.rb
96
- - test/controller_test.rb
97
99
  - test/database.yml
98
100
  - test/dsl_reader_test.rb
99
101
  - test/functional/filter_access_to_with_id_in_scope_test.rb
100
102
  - test/functional/no_filter_access_to_test.rb
101
103
  - test/functional/params_block_arity_test.rb
104
+ - test/grape_api_test.rb
102
105
  - test/helper_test.rb
103
106
  - test/maintenance_test.rb
104
107
  - test/model_test.rb
105
108
  - test/profiles/access_checking
109
+ - test/rails_controller_test.rb
106
110
  - test/schema.sql
107
111
  - test/test_helper.rb
112
+ - test/test_support/grape.rb
108
113
  - test/test_support/minitest_compatibility.rb
114
+ - test/test_support/rails.rb
109
115
  homepage: http://github.com/appfolio/ae_declarative_authorization
110
116
  licenses:
111
117
  - MIT
@@ -126,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
132
  version: '0'
127
133
  requirements: []
128
134
  rubyforge_project:
129
- rubygems_version: 2.7.7
135
+ rubygems_version: 2.5.2
130
136
  signing_key:
131
137
  specification_version: 4
132
138
  summary: ae_declarative_authorization is a Rails gem for maintainable authorization
@@ -134,16 +140,19 @@ summary: ae_declarative_authorization is a Rails gem for maintainable authorizat
134
140
  test_files:
135
141
  - test/authorization_test.rb
136
142
  - test/controller_filter_resource_access_test.rb
137
- - test/controller_test.rb
138
143
  - test/database.yml
139
144
  - test/dsl_reader_test.rb
140
145
  - test/functional/filter_access_to_with_id_in_scope_test.rb
141
146
  - test/functional/no_filter_access_to_test.rb
142
147
  - test/functional/params_block_arity_test.rb
148
+ - test/grape_api_test.rb
143
149
  - test/helper_test.rb
144
150
  - test/maintenance_test.rb
145
151
  - test/model_test.rb
146
152
  - test/profiles/access_checking
153
+ - test/rails_controller_test.rb
147
154
  - test/schema.sql
148
155
  - test/test_helper.rb
156
+ - test/test_support/grape.rb
149
157
  - test/test_support/minitest_compatibility.rb
158
+ - test/test_support/rails.rb
@@ -1,136 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- ae_declarative_authorization (0.7.1)
5
- blockenspiel (~> 0.5.0)
6
- rails (>= 4.2.5.2, < 6)
7
-
8
- GEM
9
- remote: http://rubygems.org/
10
- specs:
11
- actioncable (5.1.6)
12
- actionpack (= 5.1.6)
13
- nio4r (~> 2.0)
14
- websocket-driver (~> 0.6.1)
15
- actionmailer (5.1.6)
16
- actionpack (= 5.1.6)
17
- actionview (= 5.1.6)
18
- activejob (= 5.1.6)
19
- mail (~> 2.5, >= 2.5.4)
20
- rails-dom-testing (~> 2.0)
21
- actionpack (5.1.6)
22
- actionview (= 5.1.6)
23
- activesupport (= 5.1.6)
24
- rack (~> 2.0)
25
- rack-test (>= 0.6.3)
26
- rails-dom-testing (~> 2.0)
27
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
- actionview (5.1.6)
29
- activesupport (= 5.1.6)
30
- builder (~> 3.1)
31
- erubi (~> 1.4)
32
- rails-dom-testing (~> 2.0)
33
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
34
- activejob (5.1.6)
35
- activesupport (= 5.1.6)
36
- globalid (>= 0.3.6)
37
- activemodel (5.1.6)
38
- activesupport (= 5.1.6)
39
- activerecord (5.1.6)
40
- activemodel (= 5.1.6)
41
- activesupport (= 5.1.6)
42
- arel (~> 8.0)
43
- activesupport (5.1.6)
44
- concurrent-ruby (~> 1.0, >= 1.0.2)
45
- i18n (>= 0.7, < 2)
46
- minitest (~> 5.1)
47
- tzinfo (~> 1.1)
48
- appraisal (2.2.0)
49
- bundler
50
- rake
51
- thor (>= 0.14.0)
52
- arel (8.0.0)
53
- blockenspiel (0.5.0)
54
- builder (3.2.3)
55
- concurrent-ruby (1.0.5)
56
- crass (1.0.4)
57
- erubi (1.7.1)
58
- globalid (0.4.1)
59
- activesupport (>= 4.2.0)
60
- i18n (1.1.0)
61
- concurrent-ruby (~> 1.0)
62
- loofah (2.2.2)
63
- crass (~> 1.0.2)
64
- nokogiri (>= 1.5.9)
65
- mail (2.7.0)
66
- mini_mime (>= 0.1.1)
67
- metaclass (0.0.4)
68
- method_source (0.9.0)
69
- mini_mime (1.0.1)
70
- mini_portile2 (2.3.0)
71
- minitest (5.11.3)
72
- mocha (1.7.0)
73
- metaclass (~> 0.0.1)
74
- nio4r (2.3.1)
75
- nokogiri (1.8.4)
76
- mini_portile2 (~> 2.3.0)
77
- rack (2.0.5)
78
- rack-test (1.1.0)
79
- rack (>= 1.0, < 3)
80
- rails (5.1.6)
81
- actioncable (= 5.1.6)
82
- actionmailer (= 5.1.6)
83
- actionpack (= 5.1.6)
84
- actionview (= 5.1.6)
85
- activejob (= 5.1.6)
86
- activemodel (= 5.1.6)
87
- activerecord (= 5.1.6)
88
- activesupport (= 5.1.6)
89
- bundler (>= 1.3.0)
90
- railties (= 5.1.6)
91
- sprockets-rails (>= 2.0.0)
92
- rails-controller-testing (1.0.2)
93
- actionpack (~> 5.x, >= 5.0.1)
94
- actionview (~> 5.x, >= 5.0.1)
95
- activesupport (~> 5.x)
96
- rails-dom-testing (2.0.3)
97
- activesupport (>= 4.2.0)
98
- nokogiri (>= 1.6)
99
- rails-html-sanitizer (1.0.4)
100
- loofah (~> 2.2, >= 2.2.2)
101
- railties (5.1.6)
102
- actionpack (= 5.1.6)
103
- activesupport (= 5.1.6)
104
- method_source
105
- rake (>= 0.8.7)
106
- thor (>= 0.18.1, < 2.0)
107
- rake (12.3.1)
108
- sprockets (3.7.2)
109
- concurrent-ruby (~> 1.0)
110
- rack (> 1, < 3)
111
- sprockets-rails (3.2.1)
112
- actionpack (>= 4.0)
113
- activesupport (>= 4.0)
114
- sprockets (>= 3.0.0)
115
- sqlite3 (1.3.13)
116
- thor (0.20.0)
117
- thread_safe (0.3.6)
118
- tzinfo (1.2.5)
119
- thread_safe (~> 0.1)
120
- websocket-driver (0.6.5)
121
- websocket-extensions (>= 0.1.0)
122
- websocket-extensions (0.1.3)
123
-
124
- PLATFORMS
125
- ruby
126
-
127
- DEPENDENCIES
128
- ae_declarative_authorization!
129
- appraisal (~> 2.1)
130
- mocha (~> 1.0)
131
- rails (= 5.1.6)
132
- rails-controller-testing
133
- sqlite3
134
-
135
- BUNDLED WITH
136
- 1.16.3