acl9 0.12.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +21 -7
  3. data/.travis.yml +19 -0
  4. data/Appraisals +8 -0
  5. data/CONTRIBUTING.md +58 -0
  6. data/Gemfile +2 -0
  7. data/Gemfile.lock +88 -32
  8. data/LICENSE +9 -0
  9. data/README.md +156 -0
  10. data/Rakefile +6 -3
  11. data/acl9.gemspec +10 -13
  12. data/gemfiles/rails_4.0.gemfile +8 -0
  13. data/gemfiles/rails_4.1.gemfile +8 -0
  14. data/lib/acl9/model_extensions/for_subject.rb +5 -1
  15. data/lib/acl9/model_extensions.rb +3 -24
  16. data/lib/acl9/version.rb +1 -1
  17. data/lib/acl9.rb +1 -1
  18. data/test/controller_extensions/actions_test.rb +167 -0
  19. data/test/controller_extensions/anon_test.rb +39 -0
  20. data/test/controller_extensions/base.rb +96 -0
  21. data/test/controller_extensions/basics_test.rb +44 -0
  22. data/test/controller_extensions/conditions_test.rb +48 -0
  23. data/test/controller_extensions/method_test.rb +50 -0
  24. data/test/controller_extensions/multi_match_test.rb +142 -0
  25. data/test/controller_extensions/multiple_role_arguments_test.rb +135 -0
  26. data/test/controller_extensions/prepositions_test.rb +99 -0
  27. data/test/controller_extensions/pseudo_role_test.rb +26 -0
  28. data/test/controller_extensions/role_test.rb +75 -0
  29. data/test/controllers/acl_action_override_test.rb +24 -0
  30. data/test/controllers/acl_arguments_test.rb +5 -0
  31. data/test/controllers/acl_block_test.rb +5 -0
  32. data/test/controllers/acl_boolean_method_test.rb +5 -0
  33. data/test/controllers/acl_helper_method_test.rb +26 -0
  34. data/test/controllers/acl_ivars_test.rb +15 -0
  35. data/test/controllers/acl_method2_test.rb +6 -0
  36. data/test/controllers/acl_method_test.rb +6 -0
  37. data/test/controllers/acl_object_hash_test.rb +18 -0
  38. data/test/controllers/acl_query_method_named_test.rb +9 -0
  39. data/test/controllers/acl_query_method_test.rb +9 -0
  40. data/test/controllers/acl_query_method_with_lambda_test.rb +9 -0
  41. data/test/controllers/acl_query_mixin.rb +51 -0
  42. data/test/controllers/acl_subject_method_test.rb +15 -0
  43. data/test/controllers/arguments_checking_test.rb +43 -0
  44. data/test/dummy/app/controllers/acl_action_override.rb +15 -0
  45. data/test/dummy/app/controllers/acl_arguments.rb +10 -0
  46. data/test/dummy/app/controllers/acl_block.rb +6 -0
  47. data/test/dummy/app/controllers/acl_boolean_method.rb +23 -0
  48. data/test/dummy/app/controllers/acl_helper_method.rb +11 -0
  49. data/test/dummy/app/controllers/acl_ivars.rb +17 -0
  50. data/test/dummy/app/controllers/acl_method.rb +6 -0
  51. data/test/dummy/app/controllers/acl_method2.rb +6 -0
  52. data/test/dummy/app/controllers/acl_objects_hash.rb +10 -0
  53. data/test/dummy/app/controllers/acl_query_method.rb +9 -0
  54. data/test/dummy/app/controllers/acl_query_method_named.rb +13 -0
  55. data/test/dummy/app/controllers/acl_query_method_with_lambda.rb +9 -0
  56. data/test/dummy/app/controllers/acl_subject_method.rb +16 -0
  57. data/test/dummy/app/controllers/application_controller.rb +7 -0
  58. data/test/dummy/app/controllers/empty_controller.rb +5 -0
  59. data/test/dummy/app/helpers/application_helper.rb +2 -0
  60. data/test/dummy/app/helpers/some_helper.rb +8 -0
  61. data/test/dummy/app/models/.keep +0 -0
  62. data/test/dummy/app/models/access.rb +3 -0
  63. data/test/dummy/app/models/account.rb +3 -0
  64. data/test/dummy/app/models/bar.rb +3 -0
  65. data/test/dummy/app/models/concerns/.keep +0 -0
  66. data/test/dummy/app/models/foo.rb +3 -0
  67. data/test/dummy/app/models/foo_bar.rb +3 -0
  68. data/test/dummy/app/models/other/foo.rb +5 -0
  69. data/test/dummy/app/models/other/role.rb +5 -0
  70. data/test/dummy/app/models/other/user.rb +5 -0
  71. data/test/dummy/app/models/role.rb +3 -0
  72. data/test/dummy/app/models/user.rb +3 -0
  73. data/test/dummy/app/models/uuid.rb +4 -0
  74. data/test/dummy/config/application.rb +23 -0
  75. data/test/dummy/config/boot.rb +4 -0
  76. data/test/dummy/config/database.yml +25 -0
  77. data/test/dummy/config/environment.rb +5 -0
  78. data/test/dummy/config/environments/development.rb +37 -0
  79. data/test/dummy/config/environments/production.rb +78 -0
  80. data/test/dummy/config/environments/test.rb +39 -0
  81. data/test/dummy/config/initializers/assets.rb +8 -0
  82. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  83. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  84. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  85. data/test/dummy/config/initializers/inflections.rb +16 -0
  86. data/test/dummy/config/initializers/mime_types.rb +4 -0
  87. data/test/dummy/config/initializers/secrets.rb +1 -0
  88. data/test/dummy/config/initializers/session_store.rb +3 -0
  89. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  90. data/test/dummy/config/locales/en.yml +23 -0
  91. data/test/dummy/config/routes.rb +3 -0
  92. data/test/dummy/config.ru +4 -0
  93. data/test/dummy/db/migrate/20141117132218_create_tables.rb +102 -0
  94. data/test/helpers/helper_test.rb +89 -0
  95. data/test/models/roles_test.rb +251 -0
  96. data/test/models/roles_with_custom_association_names_test.rb +28 -0
  97. data/test/models/roles_with_custom_class_names_test.rb +28 -0
  98. data/test/models/system_roles_test.rb +16 -0
  99. data/test/models/users_roles_and_subjects_with_namespaced_class_names_test.rb +30 -0
  100. data/test/test_helper.rb +76 -23
  101. data/test/version_test.rb +2 -2
  102. metadata +190 -74
  103. data/README.textile +0 -921
  104. data/VERSION.yml +0 -5
  105. data/init.rb +0 -1
  106. data/test/access_control_test.rb +0 -338
  107. data/test/dsl_base_test.rb +0 -795
  108. data/test/helpers_test.rb +0 -133
  109. data/test/roles_test.rb +0 -370
  110. data/test/support/controllers.rb +0 -207
  111. data/test/support/models.rb +0 -59
  112. data/test/support/schema.rb +0 -93
data/VERSION.yml DELETED
@@ -1,5 +0,0 @@
1
- ---
2
- :build:
3
- :minor: 12
4
- :patch: 3
5
- :major: 0
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require 'acl9'
@@ -1,338 +0,0 @@
1
- require 'test_helper'
2
- require File.join(File.dirname(__FILE__), '..', 'lib', 'acl9')
3
- require 'support/controllers'
4
-
5
- #######################################################################
6
-
7
- class Admin
8
- def has_role?(role, obj = nil)
9
- role == "admin"
10
- end
11
- end
12
-
13
- class OwnerOfFoo
14
- def has_role?(role, obj)
15
- role == 'owner' && obj == MyDearFoo.instance
16
- end
17
- end
18
-
19
- class Bartender
20
- def has_role?(role, obj)
21
- role == 'bartender' && obj == ACLIvars::VenerableBar
22
- end
23
- end
24
-
25
- class TheOnlyUser
26
- include Singleton
27
-
28
- def has_role?(role, subj)
29
- role == "the_only_one"
30
- end
31
- end
32
-
33
- class Beholder
34
- def initialize(role)
35
- @role = role.to_s
36
- end
37
-
38
- def has_role?(role, obj)
39
- role.to_s == @role
40
- end
41
- end
42
-
43
- #######################################################################
44
-
45
- module BaseTests
46
- # permit anonymous to index and show and admin everywhere else
47
- def self.included(klass)
48
- klass.class_eval do
49
- [:index, :show].each do |act|
50
- it "should permit anonymous to #{act}" do
51
- get act
52
- @response.body.should == 'OK'
53
- end
54
- end
55
-
56
- [:new, :edit, :update, :delete, :destroy].each do |act|
57
- it "should forbid anonymous to #{act}" do
58
- get act
59
- @response.body.should == 'AccessDenied'
60
- end
61
- end
62
-
63
- [:index, :show, :new, :edit, :update, :delete, :destroy].each do |act|
64
- it "should permit admin to #{act}" do
65
- get act, :user => Admin.new
66
- @response.body.should == 'OK'
67
- end
68
- end
69
- end
70
- end
71
- end
72
-
73
- module ShouldRespondToAcl
74
- def self.included(klass)
75
- klass.class_eval do
76
- it "should add :acl as a method" do
77
- @controller.should respond_to(:acl)
78
- end
79
-
80
- it "should_not add :acl? as a method" do
81
- @controller.should_not respond_to(:acl?)
82
- end
83
- end
84
- end
85
- end
86
-
87
- #######################################################################
88
-
89
- class ACLBlockTest < ActionController::TestCase
90
- tests ACLBlock
91
-
92
- include BaseTests
93
- end
94
-
95
- class ACLMethodTest < ActionController::TestCase
96
- tests ACLMethod
97
-
98
- include BaseTests
99
- include ShouldRespondToAcl
100
- end
101
-
102
- class ACLMethod2Test < ActionController::TestCase
103
- tests ACLMethod2
104
-
105
- include BaseTests
106
- include ShouldRespondToAcl
107
- end
108
-
109
- class ACLArgumentsTest < ActionController::TestCase
110
- tests ACLArguments
111
-
112
- include BaseTests
113
- end
114
-
115
- class ACLBooleanMethodTest < ActionController::TestCase
116
- tests ACLBooleanMethod
117
-
118
- include BaseTests
119
- end
120
-
121
- class ACLIvarsTest < ActionController::TestCase
122
- tests ACLIvars
123
-
124
- it "should allow owner of foo to destroy" do
125
- delete :destroy, :user => OwnerOfFoo.new
126
- @response.body.should == 'OK'
127
- end
128
-
129
- it "should allow bartender to destroy" do
130
- delete :destroy, :user => Bartender.new
131
- @response.body.should == 'OK'
132
- end
133
- end
134
-
135
- class ACLSubjectMethodTest < ActionController::TestCase
136
- tests ACLSubjectMethod
137
-
138
- it "should allow the only user to index" do
139
- get :index, :user => TheOnlyUser.instance
140
- @response.body.should == 'OK'
141
- end
142
-
143
- it "should deny anonymous to index" do
144
- get :index
145
- @response.body.should == 'AccessDenied'
146
- end
147
- end
148
-
149
- class ACLObjectsHashTest < ActionController::TestCase
150
- tests ACLObjectsHash
151
-
152
- it "should consider objects hash and prefer it to @ivar" do
153
- get :allow, :user => OwnerOfFoo.new
154
- @response.body.should == 'OK'
155
- end
156
-
157
- it "should return AccessDenied when not logged in" do
158
- get :allow
159
- @response.body.should == 'AccessDenied'
160
- end
161
- end
162
-
163
- class ACLActionOverrideTest < ActionController::TestCase
164
- tests ACLActionOverride
165
-
166
- it "should allow index action to anonymous" do
167
- get :check_allow, :_action => :index
168
- @response.body.should == 'OK'
169
- end
170
-
171
- it "should deny show action to anonymous" do
172
- get :check_allow, :_action => :show
173
- @response.body.should == 'AccessDenied'
174
- end
175
-
176
- it "should deny edit action to regular user" do
177
- get :check_allow_with_foo, :_action => :edit, :user => TheOnlyUser.instance
178
-
179
- @response.body.should == 'AccessDenied'
180
- end
181
-
182
- it "should allow edit action to owner of foo" do
183
- get :check_allow_with_foo, :_action => :edit, :user => OwnerOfFoo.new
184
-
185
- @response.body.should == 'OK'
186
- end
187
- end
188
-
189
- class ACLHelperMethodTest < ActionController::TestCase
190
- tests ACLHelperMethod
191
-
192
- it "should return OK checking helper method" do
193
- get :allow, :user => OwnerOfFoo.new
194
- @response.body.should == 'OK'
195
- end
196
-
197
- it "should return AccessDenied when not logged in" do
198
- get :allow
199
- @response.body.should == 'AccessDenied'
200
- end
201
- end
202
-
203
- #######################################################################
204
-
205
- module ACLQueryMixin
206
- def self.included(base)
207
- base.class_eval do
208
- describe "#acl_question_mark" do # describe "#acl?" doesn't work
209
- before do
210
- @editor = Beholder.new(:editor)
211
- @viewer = Beholder.new(:viewer)
212
- @owneroffoo = OwnerOfFoo.new
213
- end
214
-
215
- [:edit, :update, :destroy].each do |meth|
216
- it "should return true for editor/#{meth}" do
217
- @controller.current_user = @editor
218
- @controller.acl?(meth).should == true
219
- @controller.acl?(meth.to_s).should == true
220
- end
221
-
222
- it "should return false for viewer/#{meth}" do
223
- @controller.current_user = @viewer
224
- @controller.acl?(meth).should == false
225
- @controller.acl?(meth.to_s).should == false
226
- end
227
- end
228
-
229
- [:index, :show].each do |meth|
230
- it "should return false for editor/#{meth}" do
231
- @controller.current_user = @editor
232
- @controller.acl?(meth).should == false
233
- @controller.acl?(meth.to_s).should == false
234
- end
235
-
236
- it "should return true for viewer/#{meth}" do
237
- @controller.current_user = @viewer
238
- @controller.acl?(meth).should == true
239
- @controller.acl?(meth.to_s).should == true
240
- end
241
- end
242
-
243
- it "should return false for editor/fooize" do
244
- @controller.current_user = @editor
245
- @controller.acl?(:fooize).should == false
246
- end
247
-
248
- it "should return true for foo owner" do
249
- @controller.current_user = @owneroffoo
250
- @controller.acl?(:fooize, :foo => MyDearFoo.instance).should == true
251
- end
252
- end
253
- end
254
- end
255
- end
256
-
257
- class ACLQueryMethodTest < ActionController::TestCase
258
- tests ACLQueryMethod
259
-
260
- it "should respond to :acl?" do
261
- @controller.should respond_to(:acl?)
262
- end
263
-
264
- include ACLQueryMixin
265
- end
266
-
267
- class ACLQueryMethodWithLambdaTest < ActionController::TestCase
268
- tests ACLQueryMethodWithLambda
269
-
270
- it "should respond to :acl?" do
271
- @controller.should respond_to(:acl?)
272
- end
273
-
274
- include ACLQueryMixin
275
- end
276
-
277
- #######################################################################
278
-
279
- class ACLNamedQueryMethodTest < ActionController::TestCase
280
- tests ACLNamedQueryMethod
281
-
282
- it "should respond to :allow_ay" do
283
- @controller.should respond_to(:allow_ay)
284
- end
285
-
286
- include ACLQueryMixin
287
- end
288
-
289
- #######################################################################
290
-
291
- class ArgumentsCheckingTest < ActiveSupport::TestCase
292
- def arg_err(&block)
293
- lambda do
294
- block.call
295
- end.should raise_error(ArgumentError)
296
- end
297
-
298
- it "should raise ArgumentError without a block" do
299
- arg_err do
300
- class FailureController < ApplicationController
301
- access_control
302
- end
303
- end
304
- end
305
-
306
- it "should raise ArgumentError with 1st argument which is not a symbol" do
307
- arg_err do
308
- class FailureController < ApplicationController
309
- access_control 123 do end
310
- end
311
- end
312
- end
313
-
314
- it "should raise ArgumentError with more than 1 positional argument" do
315
- arg_err do
316
- class FailureController < ApplicationController
317
- access_control :foo, :bar do end
318
- end
319
- end
320
- end
321
-
322
- it "should raise ArgumentError with :helper => true and no method name" do
323
- arg_err do
324
- class FailureController < ApplicationController
325
- access_control :helper => true do end
326
- end
327
- end
328
- end
329
-
330
- it "should raise ArgumentError with :helper => :method and a method name" do
331
- arg_err do
332
- class FailureController < ApplicationController
333
- access_control :meth, :helper => :another_meth do end
334
- end
335
- end
336
- end
337
- end
338
-