ae_declarative_authorization 0.10.1 → 0.12.1.tim1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +29 -0
  3. data/.gitignore +32 -0
  4. data/.ruby-version +1 -0
  5. data/Appraisals +18 -23
  6. data/Gemfile +3 -1
  7. data/declarative_authorization.gemspec +2 -2
  8. data/lib/declarative_authorization/controller/grape.rb +15 -4
  9. data/lib/declarative_authorization/controller_permission.rb +1 -5
  10. data/lib/declarative_authorization/test/helpers.rb +8 -2
  11. data/lib/declarative_authorization/version.rb +1 -1
  12. metadata +11 -76
  13. data/Gemfile.lock +0 -138
  14. data/gemfiles/ruby_2.3.3_rails507.gemfile +0 -12
  15. data/gemfiles/ruby_2.3.3_rails507.gemfile.lock +0 -164
  16. data/gemfiles/ruby_2.3.3_rails516.gemfile +0 -12
  17. data/gemfiles/ruby_2.3.3_rails516.gemfile.lock +0 -164
  18. data/gemfiles/ruby_2.3.3_rails521.gemfile +0 -12
  19. data/gemfiles/ruby_2.3.3_rails521.gemfile.lock +0 -172
  20. data/gemfiles/ruby_2.3.3_rails522.gemfile +0 -12
  21. data/gemfiles/ruby_2.3.3_rails522.gemfile.lock +0 -172
  22. data/gemfiles/ruby_2.5.3_rails507.gemfile +0 -12
  23. data/gemfiles/ruby_2.5.3_rails507.gemfile.lock +0 -164
  24. data/gemfiles/ruby_2.5.3_rails516.gemfile +0 -12
  25. data/gemfiles/ruby_2.5.3_rails516.gemfile.lock +0 -164
  26. data/gemfiles/ruby_2.5.3_rails521.gemfile +0 -12
  27. data/gemfiles/ruby_2.5.3_rails521.gemfile.lock +0 -172
  28. data/gemfiles/ruby_2.5.3_rails522.gemfile +0 -12
  29. data/gemfiles/ruby_2.5.3_rails522.gemfile.lock +0 -172
  30. data/gemfiles/ruby_2.6.2_rails507.gemfile +0 -12
  31. data/gemfiles/ruby_2.6.2_rails507.gemfile.lock +0 -164
  32. data/gemfiles/ruby_2.6.2_rails516.gemfile +0 -12
  33. data/gemfiles/ruby_2.6.2_rails516.gemfile.lock +0 -164
  34. data/gemfiles/ruby_2.6.2_rails521.gemfile +0 -12
  35. data/gemfiles/ruby_2.6.2_rails521.gemfile.lock +0 -172
  36. data/gemfiles/ruby_2.6.2_rails522.gemfile +0 -12
  37. data/gemfiles/ruby_2.6.2_rails522.gemfile.lock +0 -172
  38. data/log/test.log +0 -89694
  39. data/pkg/ae_declarative_authorization-0.10.0.gem +0 -0
  40. data/pkg/ae_declarative_authorization-0.9.0.gem +0 -0
  41. data/pkg/ae_declarative_authorization-0.9.0.tim1.gem +0 -0
  42. data/pkg/ae_declarative_authorization-0.9.1.gem +0 -0
  43. data/pkg/ae_declarative_authorization-0.9.2.gem +0 -0
  44. data/test/authorization_test.rb +0 -1189
  45. data/test/controller_filter_resource_access_test.rb +0 -573
  46. data/test/database.yml +0 -3
  47. data/test/dsl_reader_test.rb +0 -178
  48. data/test/functional/filter_access_to_with_id_in_scope_test.rb +0 -88
  49. data/test/functional/no_filter_access_to_test.rb +0 -79
  50. data/test/functional/params_block_arity_test.rb +0 -39
  51. data/test/grape_api_test.rb +0 -508
  52. data/test/helper_test.rb +0 -248
  53. data/test/maintenance_test.rb +0 -46
  54. data/test/model_test.rb +0 -1840
  55. data/test/profiles/access_checking +0 -100
  56. data/test/rails_controller_test.rb +0 -478
  57. data/test/schema.sql +0 -60
  58. data/test/test_helper.rb +0 -117
  59. data/test/test_support/grape.rb +0 -93
  60. data/test/test_support/minitest_compatibility.rb +0 -27
  61. data/test/test_support/rails.rb +0 -69
@@ -1,1189 +0,0 @@
1
- require 'test_helper'
2
-
3
- class AuthorizationTest < Test::Unit::TestCase
4
-
5
- def test_permit
6
- reader = Authorization::Reader::DSLReader.new
7
- reader.parse %{
8
- authorization do
9
- role :test_role do
10
- has_permission_on :permissions, :to => :test
11
- end
12
- end
13
- }
14
- engine = Authorization::Engine.new(reader)
15
- assert engine.permit?(:test, :context => :permissions,
16
- :user => MockUser.new(:test_role, :test_role_2))
17
- assert !engine.permit?(:test_2, :context => :permissions_2,
18
- :user => MockUser.new(:test_role))
19
- assert !engine.permit?(:test, :context => :permissions,
20
- :user => MockUser.new(:test_role_2))
21
- end
22
-
23
- def test_permit_context_people
24
- reader = Authorization::Reader::DSLReader.new
25
- reader.parse %{
26
- authorization do
27
- role :test_role do
28
- has_permission_on :people, :to => :test
29
- end
30
- end
31
- }
32
- engine = Authorization::Engine.new(reader)
33
- assert engine.permit?(:test, :context => :people,
34
- :user => MockUser.new(:test_role))
35
- end
36
-
37
- def test_permit_with_has_omnipotence
38
- reader = Authorization::Reader::DSLReader.new
39
- reader.parse %{
40
- authorization do
41
- role :admin do
42
- has_omnipotence
43
- end
44
- end
45
- }
46
- engine = Authorization::Engine.new(reader)
47
- assert engine.permit?(:test, :context => :people,
48
- :user => MockUser.new(:admin))
49
- end
50
-
51
- def test_permit_multiple_contexts
52
- reader = Authorization::Reader::DSLReader.new
53
- reader.parse %{
54
- authorization do
55
- role :test_role do
56
- has_permission_on [:permissions, :permissions_2], :to => :test
57
- has_permission_on :permissions_4, :permissions_5, :to => :test
58
- end
59
- end
60
- }
61
- engine = Authorization::Engine.new(reader)
62
- assert engine.permit?(:test, :context => :permissions,
63
- :user => MockUser.new(:test_role))
64
- assert engine.permit?(:test, :context => :permissions_2,
65
- :user => MockUser.new(:test_role))
66
- assert !engine.permit?(:test, :context => :permissions_3,
67
- :user => MockUser.new(:test_role))
68
-
69
- assert engine.permit?(:test, :context => :permissions_4, :user => MockUser.new(:test_role))
70
- assert engine.permit?(:test, :context => :permissions_5, :user => MockUser.new(:test_role))
71
- end
72
-
73
- def test_permit_with_frozen_roles
74
- reader = Authorization::Reader::DSLReader.new
75
- reader.parse %{
76
- authorization do
77
- role :other_role do
78
- includes :test_role
79
- end
80
- role :test_role do
81
- has_permission_on :permissions, :to => :test
82
- end
83
- end
84
- }
85
- engine = Authorization::Engine.new(reader)
86
- roles = [:other_role].freeze
87
- assert engine.permit?(:test, :context => :permissions,
88
- :user => MockUser.new(:role_symbols => roles))
89
- end
90
-
91
- def test_obligations_without_conditions
92
- reader = Authorization::Reader::DSLReader.new
93
- reader.parse %{
94
- authorization do
95
- role :test_role do
96
- has_permission_on :permissions, :to => :test
97
- end
98
- end
99
- }
100
- engine = Authorization::Engine.new(reader)
101
- assert_equal [{}], engine.obligations(:test, :context => :permissions,
102
- :user => MockUser.new(:test_role))
103
- end
104
-
105
- def test_obligations_with_conditions
106
- reader = Authorization::Reader::DSLReader.new
107
- reader.parse %{
108
- authorization do
109
- role :test_role do
110
- has_permission_on :permissions, :to => :test do
111
- if_attribute :attr => is { user.attr }
112
- end
113
- end
114
- end
115
- }
116
- engine = Authorization::Engine.new(reader)
117
- assert_equal [{:attr => [:is, 1]}],
118
- engine.obligations(:test, :context => :permissions,
119
- :user => MockUser.new(:test_role, :attr => 1))
120
- end
121
-
122
- def test_obligations_with_omnipotence
123
- reader = Authorization::Reader::DSLReader.new
124
- reader.parse %{
125
- authorization do
126
- role :admin do
127
- has_omnipotence
128
- end
129
- role :test_role do
130
- has_permission_on :permissions, :to => :test do
131
- if_attribute :attr => is { user.attr }
132
- end
133
- end
134
- end
135
- }
136
- engine = Authorization::Engine.new(reader)
137
- assert_equal [],
138
- engine.obligations(:test, :context => :permissions,
139
- :user => MockUser.new(:test_role, :admin, :attr => 1))
140
- end
141
-
142
- def test_obligations_with_anded_conditions
143
- reader = Authorization::Reader::DSLReader.new
144
- reader.parse %{
145
- authorization do
146
- role :test_role do
147
- has_permission_on :permissions, :to => :test, :join_by => :and do
148
- if_attribute :attr => is { user.attr }
149
- if_attribute :attr_2 => is { user.attr_2 }
150
- end
151
- end
152
- end
153
- }
154
- engine = Authorization::Engine.new(reader)
155
- assert_equal [{:attr => [:is, 1], :attr_2 => [:is, 2]}],
156
- engine.obligations(:test, :context => :permissions,
157
- :user => MockUser.new(:test_role, :attr => 1, :attr_2 => 2))
158
- end
159
-
160
- def test_obligations_with_deep_anded_conditions
161
- reader = Authorization::Reader::DSLReader.new
162
- reader.parse %{
163
- authorization do
164
- role :test_role do
165
- has_permission_on :permissions, :to => :test, :join_by => :and do
166
- if_attribute :attr => { :deeper_attr => is { user.deeper_attr }}
167
- if_attribute :attr => { :deeper_attr_2 => is { user.deeper_attr_2 }}
168
- end
169
- end
170
- end
171
- }
172
- engine = Authorization::Engine.new(reader)
173
- assert_equal [{:attr => { :deeper_attr => [:is, 1], :deeper_attr_2 => [:is, 2] } }],
174
- engine.obligations(:test, :context => :permissions,
175
- :user => MockUser.new(:test_role, :deeper_attr => 1, :deeper_attr_2 => 2))
176
- end
177
-
178
- def test_obligations_with_has_many
179
- reader = Authorization::Reader::DSLReader.new
180
- reader.parse %{
181
- authorization do
182
- role :test_role do
183
- has_permission_on :permissions, :to => :test do
184
- if_attribute :attrs => { :deeper_attr => is { user.deeper_attr } }
185
- end
186
- end
187
- end
188
- }
189
- engine = Authorization::Engine.new(reader)
190
- assert_equal [{:attrs => {:deeper_attr => [:is, 1]}}],
191
- engine.obligations(:test, :context => :permissions,
192
- :user => MockUser.new(:test_role, :deeper_attr => 1))
193
- end
194
-
195
- def test_obligations_with_conditions_and_empty
196
- reader = Authorization::Reader::DSLReader.new
197
- reader.parse %{
198
- authorization do
199
- role :test_role do
200
- has_permission_on :permissions, :to => :test
201
- has_permission_on :permissions, :to => :test do
202
- if_attribute :attr => is { user.attr }
203
- end
204
- end
205
- end
206
- }
207
- engine = Authorization::Engine.new(reader)
208
- assert_equal [{}, {:attr => [:is, 1]}],
209
- engine.obligations(:test, :context => :permissions,
210
- :user => MockUser.new(:test_role, :attr => 1))
211
- end
212
-
213
- def test_obligations_with_permissions
214
- reader = Authorization::Reader::DSLReader.new
215
- reader.parse %{
216
- authorization do
217
- role :test_role do
218
- has_permission_on :permissions, :to => :test do
219
- if_attribute :attr => is { user.attr }
220
- end
221
- has_permission_on :permission_children, :to => :test do
222
- if_permitted_to :test, :permission, :context => :permissions
223
- end
224
- has_permission_on :permission_children_2, :to => :test do
225
- if_permitted_to :test, :permission
226
- end
227
- has_permission_on :permission_children_children, :to => :test do
228
- if_permitted_to :test, :permission_child => :permission,
229
- :context => :permissions
230
- end
231
- end
232
- end
233
- }
234
- engine = Authorization::Engine.new(reader)
235
- assert_equal [{:permission => {:attr => [:is, 1]}}],
236
- engine.obligations(:test, :context => :permission_children,
237
- :user => MockUser.new(:test_role, :attr => 1))
238
- assert_equal [{:permission => {:attr => [:is, 1]}}],
239
- engine.obligations(:test, :context => :permission_children_2,
240
- :user => MockUser.new(:test_role, :attr => 1))
241
- assert_equal [{:permission_child => {:permission => {:attr => [:is, 1]}}}],
242
- engine.obligations(:test, :context => :permission_children_children,
243
- :user => MockUser.new(:test_role, :attr => 1))
244
- end
245
-
246
- def test_obligations_with_has_many_permissions
247
- reader = Authorization::Reader::DSLReader.new
248
- reader.parse %{
249
- authorization do
250
- role :test_role do
251
- has_permission_on :permissions, :to => :test do
252
- if_attribute :attr => is { user.attr }
253
- end
254
- has_permission_on :permission_children, :to => :test do
255
- if_permitted_to :test, :permissions, :context => :permissions
256
- end
257
- has_permission_on :permission_children_2, :to => :test do
258
- if_permitted_to :test, :permissions
259
- end
260
- has_permission_on :permission_children_children, :to => :test do
261
- if_permitted_to :test, :permission_child => :permissions,
262
- :context => :permissions
263
- end
264
- end
265
- end
266
- }
267
- engine = Authorization::Engine.new(reader)
268
- assert_equal [{:permissions => {:attr => [:is, 1]}}],
269
- engine.obligations(:test, :context => :permission_children,
270
- :user => MockUser.new(:test_role, :attr => 1))
271
- assert_equal [{:permissions => {:attr => [:is, 1]}}],
272
- engine.obligations(:test, :context => :permission_children_2,
273
- :user => MockUser.new(:test_role, :attr => 1))
274
- assert_equal [{:permission_child => {:permissions => {:attr => [:is, 1]}}}],
275
- engine.obligations(:test, :context => :permission_children_children,
276
- :user => MockUser.new(:test_role, :attr => 1))
277
- end
278
-
279
- def test_obligations_with_permissions_multiple
280
- reader = Authorization::Reader::DSLReader.new
281
- reader.parse %{
282
- authorization do
283
- role :test_role do
284
- has_permission_on :permissions, :to => :test do
285
- if_attribute :attr => is { 1 }
286
- if_attribute :attr => is { 2 }
287
- end
288
- has_permission_on :permission_children_children, :to => :test do
289
- if_permitted_to :test, :permission_child => :permission
290
- end
291
- end
292
- end
293
- }
294
- engine = Authorization::Engine.new(reader)
295
- assert_equal [{:permission_child => {:permission => {:attr => [:is, 1]}}},
296
- {:permission_child => {:permission => {:attr => [:is, 2]}}}],
297
- engine.obligations(:test, :context => :permission_children_children,
298
- :user => MockUser.new(:test_role))
299
- end
300
-
301
- def test_obligations_with_permissions_and_anded_conditions
302
- reader = Authorization::Reader::DSLReader.new
303
- reader.parse %{
304
- authorization do
305
- role :test_role do
306
- has_permission_on :permission_children, :to => :test, :join_by => :and do
307
- if_permitted_to :test, :permission
308
- if_attribute :test_attr => 1
309
- end
310
- has_permission_on :permissions, :to => :test do
311
- if_attribute :test_attr => 1
312
- end
313
- end
314
- end
315
- }
316
- engine = Authorization::Engine.new(reader)
317
-
318
- assert_equal [{:test_attr => [:is, 1], :permission => {:test_attr => [:is, 1]}}],
319
- engine.obligations(:test, :context => :permission_children,
320
- :user => MockUser.new(:test_role))
321
- end
322
-
323
- def test_guest_user
324
- reader = Authorization::Reader::DSLReader.new
325
- reader.parse %{
326
- authorization do
327
- role :guest do
328
- has_permission_on :permissions, :to => :test
329
- end
330
- end
331
- }
332
- engine = Authorization::Engine.new(reader)
333
- Authorization.stub :current_user, MockUser.new do
334
- assert engine.permit?(:test, :context => :permissions)
335
- assert !engine.permit?(:test, :context => :permissions_2)
336
- end
337
- end
338
-
339
- def test_default_role
340
- reader = Authorization::Reader::DSLReader.new
341
- reader.parse %{
342
- authorization do
343
- role :anonymous do
344
- has_permission_on :permissions, :to => :test
345
- end
346
- end
347
- }
348
- Authorization.stub :default_role, :anonymous do
349
- engine = Authorization::Engine.new(reader)
350
- Authorization.stub :current_user, MockUser.new do
351
- assert engine.permit?(:test, :context => :permissions)
352
- end
353
- assert !engine.permit?(:test, :context => :permissions,
354
- :user => MockUser.new(:guest))
355
- end
356
- end
357
-
358
- def test_invalid_user_model
359
- reader = Authorization::Reader::DSLReader.new
360
- reader.parse %{
361
- authorization do
362
- role :guest do
363
- has_permission_on :permissions, :to => :test
364
- end
365
- end
366
- }
367
- engine = Authorization::Engine.new(reader)
368
- assert_raise(Authorization::AuthorizationUsageError) do
369
- engine.permit?(:test, :context => :permissions, :user => MockUser.new(1, 2))
370
- end
371
- assert_raise(Authorization::AuthorizationUsageError) do
372
- engine.permit?(:test, :context => :permissions, :user => MockDataObject.new)
373
- end
374
- end
375
-
376
- def test_role_hierarchy
377
- reader = Authorization::Reader::DSLReader.new
378
- reader.parse %{
379
- authorization do
380
- role :test_role do
381
- includes :lower_role
382
- has_permission_on :permissions, :to => :test
383
- end
384
- role :lower_role do
385
- has_permission_on :permissions, :to => :lower
386
- end
387
- end
388
- }
389
- engine = Authorization::Engine.new(reader)
390
- assert engine.permit?(:test, context: :permissions, user: MockUser.new(:test_role))
391
- assert engine.permit?(:lower, context: :permissions, user: MockUser.new(:test_role))
392
- end
393
-
394
- def test_role_hierarchy__recursive
395
- reader = Authorization::Reader::DSLReader.new
396
- reader.parse %{
397
- authorization do
398
- role :test_role do
399
- includes :lower_role
400
- has_permission_on :permissions, :to => :test
401
- end
402
- role :lower_role do
403
- has_permission_on :permissions, :to => :lower
404
- includes :lowest_role
405
- end
406
- role :lowest_role do
407
- has_permission_on :permissions, :to => :lowest
408
- end
409
- end
410
- }
411
- engine = Authorization::Engine.new(reader)
412
- assert engine.permit?(:test, context: :permissions, user: MockUser.new(:test_role))
413
- assert engine.permit?(:lower, context: :permissions, user: MockUser.new(:test_role))
414
- assert engine.permit?(:lowest, context: :permissions, user: MockUser.new(:test_role))
415
- end
416
-
417
- def test_role_hierarchy__circular
418
- reader = Authorization::Reader::DSLReader.new
419
- reader.parse %{
420
- authorization do
421
- role :test_role do
422
- includes :lower_role
423
- has_permission_on :permissions, :to => :test
424
- end
425
- role :lower_role do
426
- includes :test_role
427
- has_permission_on :permissions, :to => :lower
428
- end
429
- end
430
- }
431
- engine = Authorization::Engine.new(reader)
432
- assert engine.permit?(:test, context: :permissions, user: MockUser.new(:test_role))
433
- assert engine.permit?(:lower, context: :permissions, user: MockUser.new(:test_role))
434
- end
435
-
436
- def test_role_hierarchy__recursive__circular
437
- reader = Authorization::Reader::DSLReader.new
438
- reader.parse %{
439
- authorization do
440
- role :test_role do
441
- includes :lower_role
442
- has_permission_on :permissions, :to => :test
443
- end
444
- role :lower_role do
445
- includes :lowest_role
446
- has_permission_on :permissions, :to => :lower
447
- end
448
- role :lowest_role do
449
- includes :test_role
450
- has_permission_on :permissions, :to => :lowest
451
- end
452
- end
453
- }
454
- engine = Authorization::Engine.new(reader)
455
- assert engine.permit?(:test, context: :permissions, user: MockUser.new(:test_role))
456
- assert engine.permit?(:lower, context: :permissions, user: MockUser.new(:test_role))
457
- assert engine.permit?(:lowest, context: :permissions, user: MockUser.new(:test_role))
458
- end
459
-
460
- def test_privilege_hierarchy
461
- reader = Authorization::Reader::DSLReader.new
462
- reader.parse %{
463
- privileges do
464
- privilege :test, :permissions do
465
- includes :lower
466
- end
467
- end
468
- authorization do
469
- role :test_role do
470
- has_permission_on :permissions, :to => :test
471
- end
472
- end
473
- }
474
- engine = Authorization::Engine.new(reader)
475
- assert engine.permit?(:lower, context: :permissions, user: MockUser.new(:test_role))
476
- end
477
-
478
- def test_privilege_hierarchy__recursive
479
- reader = Authorization::Reader::DSLReader.new
480
- reader.parse %{
481
- privileges do
482
- privilege :test, :permissions do
483
- includes :lower
484
- end
485
- privilege :lower, :permissions do
486
- includes :lowest
487
- end
488
- end
489
- authorization do
490
- role :test_role do
491
- has_permission_on :permissions, :to => :test
492
- end
493
- end
494
- }
495
- engine = Authorization::Engine.new(reader)
496
- assert engine.permit?(:lower, context: :permissions, user: MockUser.new(:test_role))
497
- assert engine.permit?(:lowest, context: :permissions, user: MockUser.new(:test_role))
498
- end
499
-
500
- def test_privilege_hierarchy_without_context
501
- reader = Authorization::Reader::DSLReader.new
502
- reader.parse %{
503
- privileges do
504
- privilege :read do
505
- includes :list, :show
506
- end
507
- end
508
- authorization do
509
- role :test_role do
510
- has_permission_on :permissions, :to => :read
511
- end
512
- end
513
- }
514
- engine = Authorization::Engine.new(reader)
515
- assert engine.permit?(:list, :context => :permissions,
516
- :user => MockUser.new(:test_role))
517
- end
518
-
519
- def test_attribute_is
520
- reader = Authorization::Reader::DSLReader.new
521
- reader.parse %|
522
- authorization do
523
- role :test_role do
524
- has_permission_on :permissions, :to => :test do
525
- if_attribute :test_attr => is { user.test_attr }
526
- if_attribute :test_attr => 3
527
- end
528
- end
529
- end
530
- |
531
- engine = Authorization::Engine.new(reader)
532
- assert engine.permit?(:test, :context => :permissions,
533
- :user => MockUser.new(:test_role, :test_attr => 1),
534
- :object => MockDataObject.new(:test_attr => 1))
535
- assert engine.permit?(:test, :context => :permissions,
536
- :user => MockUser.new(:test_role, :test_attr => 2),
537
- :object => MockDataObject.new(:test_attr => 3))
538
- assert((not(engine.permit?(:test, :context => :permissions,
539
- :user => MockUser.new(:test_role, :test_attr => 2),
540
- :object => MockDataObject.new(:test_attr => 1)))))
541
- end
542
-
543
- def test_attribute_is_not
544
- reader = Authorization::Reader::DSLReader.new
545
- reader.parse %|
546
- authorization do
547
- role :test_role do
548
- has_permission_on :permissions, :to => :test do
549
- if_attribute :test_attr => is_not { user.test_attr }
550
- end
551
- end
552
- end
553
- |
554
- engine = Authorization::Engine.new(reader)
555
- assert !engine.permit?(:test, :context => :permissions,
556
- :user => MockUser.new(:test_role, :test_attr => 1),
557
- :object => MockDataObject.new(:test_attr => 1))
558
- assert engine.permit?(:test, :context => :permissions,
559
- :user => MockUser.new(:test_role, :test_attr => 2),
560
- :object => MockDataObject.new(:test_attr => 1))
561
- end
562
-
563
- def test_attribute_contains
564
- reader = Authorization::Reader::DSLReader.new
565
- reader.parse %|
566
- authorization do
567
- role :test_role do
568
- has_permission_on :permissions, :to => :test do
569
- if_attribute :test_attr => contains { user.test_attr }
570
- end
571
- end
572
- end
573
- |
574
- engine = Authorization::Engine.new(reader)
575
- assert engine.permit?(:test, :context => :permissions,
576
- :user => MockUser.new(:test_role, :test_attr => 1),
577
- :object => MockDataObject.new(:test_attr => [1,2]))
578
- assert !engine.permit?(:test, :context => :permissions,
579
- :user => MockUser.new(:test_role, :test_attr => 3),
580
- :object => MockDataObject.new(:test_attr => [1,2]))
581
- end
582
-
583
- def test_attribute_does_not_contain
584
- reader = Authorization::Reader::DSLReader.new
585
- reader.parse %|
586
- authorization do
587
- role :test_role do
588
- has_permission_on :permissions, :to => :test do
589
- if_attribute :test_attr => does_not_contain { user.test_attr }
590
- end
591
- end
592
- end
593
- |
594
- engine = Authorization::Engine.new(reader)
595
- assert !engine.permit?(:test, :context => :permissions,
596
- :user => MockUser.new(:test_role, :test_attr => 1),
597
- :object => MockDataObject.new(:test_attr => [1,2]))
598
- assert engine.permit?(:test, :context => :permissions,
599
- :user => MockUser.new(:test_role, :test_attr => 3),
600
- :object => MockDataObject.new(:test_attr => [1,2]))
601
- end
602
-
603
- def test_attribute_in_array
604
- reader = Authorization::Reader::DSLReader.new
605
- reader.parse %|
606
- authorization do
607
- role :test_role do
608
- has_permission_on :permissions, :to => :test do
609
- if_attribute :test_attr => is_in { [1,2] }
610
- if_attribute :test_attr => [2,3]
611
- end
612
- end
613
- end
614
- |
615
- engine = Authorization::Engine.new(reader)
616
- assert engine.permit?(:test, :context => :permissions,
617
- :user => MockUser.new(:test_role),
618
- :object => MockDataObject.new(:test_attr => 1))
619
- assert engine.permit?(:test, :context => :permissions,
620
- :user => MockUser.new(:test_role),
621
- :object => MockDataObject.new(:test_attr => 3))
622
- assert !engine.permit?(:test, :context => :permissions,
623
- :user => MockUser.new(:test_role),
624
- :object => MockDataObject.new(:test_attr => 4))
625
- end
626
-
627
- def test_attribute_not_in_array
628
- reader = Authorization::Reader::DSLReader.new
629
- reader.parse %|
630
- authorization do
631
- role :test_role do
632
- has_permission_on :permissions, :to => :test do
633
- if_attribute :test_attr => is_not_in { [1,2] }
634
- end
635
- end
636
- end
637
- |
638
- engine = Authorization::Engine.new(reader)
639
- assert !engine.permit?(:test, :context => :permissions,
640
- :user => MockUser.new(:test_role),
641
- :object => MockDataObject.new(:test_attr => 1))
642
- assert engine.permit?(:test, :context => :permissions,
643
- :user => MockUser.new(:test_role),
644
- :object => MockDataObject.new(:test_attr => 4))
645
- end
646
-
647
- def test_attribute_intersects_with
648
- reader = Authorization::Reader::DSLReader.new
649
- reader.parse %{
650
- authorization do
651
- role :test_role do
652
- has_permission_on :permissions, :to => :test do
653
- if_attribute :test_attrs => intersects_with { [1,2] }
654
- end
655
- end
656
- role :test_role_2 do
657
- has_permission_on :permissions, :to => :test do
658
- if_attribute :test_attrs => intersects_with { 1 }
659
- end
660
- end
661
- end
662
- }
663
-
664
- engine = Authorization::Engine.new(reader)
665
- assert_raise Authorization::AuthorizationUsageError do
666
- engine.permit?(:test, :context => :permissions,
667
- :user => MockUser.new(:test_role),
668
- :object => MockDataObject.new(:test_attrs => 1 ))
669
- end
670
- assert_raise Authorization::AuthorizationUsageError do
671
- engine.permit?(:test, :context => :permissions,
672
- :user => MockUser.new(:test_role_2),
673
- :object => MockDataObject.new(:test_attrs => [1, 2] ))
674
- end
675
- assert engine.permit?(:test, :context => :permissions,
676
- :user => MockUser.new(:test_role),
677
- :object => MockDataObject.new(:test_attrs => [1,3] ))
678
- assert !engine.permit?(:test, :context => :permissions,
679
- :user => MockUser.new(:test_role),
680
- :object => MockDataObject.new(:test_attrs => [3,4] ))
681
- end
682
-
683
- def test_attribute_lte
684
- reader = Authorization::Reader::DSLReader.new
685
- reader.parse %|
686
- authorization do
687
- role :test_role do
688
- has_permission_on :permissions, :to => :test do
689
- if_attribute :test_attr => lte { user.test_attr }
690
- if_attribute :test_attr => 3
691
- end
692
- end
693
- end
694
- |
695
- engine = Authorization::Engine.new(reader)
696
- # object < user -> pass
697
- assert engine.permit?(:test, :context => :permissions,
698
- :user => MockUser.new(:test_role, :test_attr => 2),
699
- :object => MockDataObject.new(:test_attr => 1))
700
- # object > user && object = control -> pass
701
- assert engine.permit?(:test, :context => :permissions,
702
- :user => MockUser.new(:test_role, :test_attr => 2),
703
- :object => MockDataObject.new(:test_attr => 3))
704
- # object = user -> pass
705
- assert engine.permit?(:test, :context => :permissions,
706
- :user => MockUser.new(:test_role, :test_attr => 1),
707
- :object => MockDataObject.new(:test_attr => 1))
708
- # object > user -> fail
709
- assert((not(engine.permit?(:test, :context => :permissions,
710
- :user => MockUser.new(:test_role, :test_attr => 1),
711
- :object => MockDataObject.new(:test_attr => 2)))))
712
- end
713
-
714
- def test_attribute_gt
715
- reader = Authorization::Reader::DSLReader.new
716
- reader.parse %|
717
- authorization do
718
- role :test_role do
719
- has_permission_on :permissions, :to => :test do
720
- if_attribute :test_attr => gt { user.test_attr }
721
- if_attribute :test_attr => 3
722
- end
723
- end
724
- end
725
- |
726
- engine = Authorization::Engine.new(reader)
727
- # object > user -> pass
728
- assert engine.permit?(:test, :context => :permissions,
729
- :user => MockUser.new(:test_role, :test_attr => 1),
730
- :object => MockDataObject.new(:test_attr => 2))
731
- # object < user && object = control -> pass
732
- assert engine.permit?(:test, :context => :permissions,
733
- :user => MockUser.new(:test_role, :test_attr => 4),
734
- :object => MockDataObject.new(:test_attr => 3))
735
- # object = user -> fail
736
- assert((not(engine.permit?(:test, :context => :permissions,
737
- :user => MockUser.new(:test_role, :test_attr => 1),
738
- :object => MockDataObject.new(:test_attr => 1)))))
739
- # object < user -> fail
740
- assert((not(engine.permit?(:test, :context => :permissions,
741
- :user => MockUser.new(:test_role, :test_attr => 2),
742
- :object => MockDataObject.new(:test_attr => 1)))))
743
- end
744
-
745
- def test_attribute_gte
746
- reader = Authorization::Reader::DSLReader.new
747
- reader.parse %|
748
- authorization do
749
- role :test_role do
750
- has_permission_on :permissions, :to => :test do
751
- if_attribute :test_attr => gte { user.test_attr }
752
- if_attribute :test_attr => 3
753
- end
754
- end
755
- end
756
- |
757
- engine = Authorization::Engine.new(reader)
758
- # object > user -> pass
759
- assert engine.permit?(:test, :context => :permissions,
760
- :user => MockUser.new(:test_role, :test_attr => 1),
761
- :object => MockDataObject.new(:test_attr => 2))
762
- # object < user && object = control -> pass
763
- assert engine.permit?(:test, :context => :permissions,
764
- :user => MockUser.new(:test_role, :test_attr => 4),
765
- :object => MockDataObject.new(:test_attr => 3))
766
- # object = user -> pass
767
- assert engine.permit?(:test, :context => :permissions,
768
- :user => MockUser.new(:test_role, :test_attr => 1),
769
- :object => MockDataObject.new(:test_attr => 1))
770
- # object < user -> fail
771
- assert((not(engine.permit?(:test, :context => :permissions,
772
- :user => MockUser.new(:test_role, :test_attr => 2),
773
- :object => MockDataObject.new(:test_attr => 1)))))
774
- end
775
-
776
- def test_attribute_deep
777
- reader = Authorization::Reader::DSLReader.new
778
- reader.parse %|
779
- authorization do
780
- role :test_role do
781
- has_permission_on :permissions, :to => :test do
782
- if_attribute :test_attr_1 => {:test_attr_2 => contains { 1 }}
783
- end
784
- end
785
- end
786
- |
787
- engine = Authorization::Engine.new(reader)
788
- assert engine.permit?(:test, :context => :permissions,
789
- :user => MockUser.new(:test_role),
790
- :object => MockDataObject.new(:test_attr_1 =>
791
- MockDataObject.new(:test_attr_2 => [1,2])))
792
- assert !engine.permit?(:test, :context => :permissions,
793
- :user => MockUser.new(:test_role),
794
- :object => MockDataObject.new(:test_attr_1 =>
795
- MockDataObject.new(:test_attr_2 => [3,4])))
796
- assert_equal [{:test_attr_1 => {:test_attr_2 => [:contains, 1]}}],
797
- engine.obligations(:test, :context => :permissions,
798
- :user => MockUser.new(:test_role))
799
- end
800
-
801
- def test_attribute_has_many
802
- reader = Authorization::Reader::DSLReader.new
803
- reader.parse %|
804
- authorization do
805
- role :test_role do
806
- has_permission_on :companies, :to => :read do
807
- if_attribute :branches => {:city => is { user.city } }
808
- end
809
- end
810
- end
811
- |
812
- engine = Authorization::Engine.new(reader)
813
-
814
- company = MockDataObject.new(:branches => [
815
- MockDataObject.new(:city => 'Barcelona'),
816
- MockDataObject.new(:city => 'Paris')
817
- ])
818
- assert engine.permit!(:read, :context => :companies,
819
- :user => MockUser.new(:test_role, :city => 'Paris'),
820
- :object => company)
821
- assert !engine.permit?(:read, :context => :companies,
822
- :user => MockUser.new(:test_role, :city => 'London'),
823
- :object => company)
824
- end
825
-
826
- def test_attribute_non_block
827
- reader = Authorization::Reader::DSLReader.new
828
- reader.parse %|
829
- authorization do
830
- role :test_role do
831
- has_permission_on :permissions, :to => :test do
832
- if_attribute :test_attr => 1
833
- end
834
- end
835
- end
836
- |
837
- engine = Authorization::Engine.new(reader)
838
- assert engine.permit?(:test, :context => :permissions,
839
- :user => MockUser.new(:test_role),
840
- :object => MockDataObject.new(:test_attr => 1))
841
- assert !engine.permit?(:test, :context => :permissions,
842
- :user => MockUser.new(:test_role),
843
- :object => MockDataObject.new(:test_attr => 2))
844
- end
845
-
846
- def test_attribute_multiple
847
- reader = Authorization::Reader::DSLReader.new
848
- reader.parse %{
849
- authorization do
850
- role :test_role do
851
- has_permission_on :permissions, :to => :test do
852
- if_attribute :test_attr => 1
853
- if_attribute :test_attr => 2 # or
854
- end
855
- end
856
- end
857
- }
858
- engine = Authorization::Engine.new(reader)
859
- assert engine.permit?(:test, :context => :permissions,
860
- :user => MockUser.new(:test_role),
861
- :object => MockDataObject.new(:test_attr => 1))
862
- assert engine.permit?(:test, :context => :permissions,
863
- :user => MockUser.new(:test_role),
864
- :object => MockDataObject.new(:test_attr => 2))
865
- end
866
-
867
- class PermissionMock < MockDataObject
868
- def self.name
869
- "Permission"
870
- end
871
- end
872
- def test_attribute_with_permissions
873
- reader = Authorization::Reader::DSLReader.new
874
- reader.parse %{
875
- authorization do
876
- role :test_role do
877
- has_permission_on :permissions, :to => :test do
878
- if_attribute :test_attr => 1
879
- end
880
- has_permission_on :permission_children, :to => :test do
881
- if_permitted_to :test, :permission
882
- end
883
- end
884
- end
885
- }
886
- engine = Authorization::Engine.new(reader)
887
-
888
- perm_data_attr_1 = PermissionMock.new({:test_attr => 1})
889
- perm_data_attr_2 = PermissionMock.new({:test_attr => 2})
890
- assert engine.permit?(:test, :context => :permission_children,
891
- :user => MockUser.new(:test_role),
892
- :object => MockDataObject.new(:permission => perm_data_attr_1))
893
- assert !engine.permit?(:test, :context => :permission_children,
894
- :user => MockUser.new(:test_role),
895
- :object => MockDataObject.new(:permission => perm_data_attr_2))
896
- end
897
-
898
- def test_attribute_with_has_many_permissions
899
- reader = Authorization::Reader::DSLReader.new
900
- reader.parse %{
901
- authorization do
902
- role :test_role do
903
- has_permission_on :permissions, :to => :test do
904
- if_attribute :test_attr => 1
905
- end
906
- has_permission_on :permission_children, :to => :test do
907
- if_permitted_to :test, :permissions
908
- end
909
- end
910
- end
911
- }
912
- engine = Authorization::Engine.new(reader)
913
-
914
- perm_data_attr_1 = PermissionMock.new({:test_attr => 1})
915
- perm_data_attr_2 = PermissionMock.new({:test_attr => 2})
916
- assert engine.permit?(:test, :context => :permission_children,
917
- :user => MockUser.new(:test_role),
918
- :object => MockDataObject.new(:permissions => [perm_data_attr_1]))
919
- assert !engine.permit?(:test, :context => :permission_children,
920
- :user => MockUser.new(:test_role),
921
- :object => MockDataObject.new(:permissions => [perm_data_attr_2]))
922
- end
923
-
924
- def test_attribute_with_deep_permissions
925
- reader = Authorization::Reader::DSLReader.new
926
- reader.parse %{
927
- authorization do
928
- role :test_role do
929
- has_permission_on :permissions, :to => :test do
930
- if_attribute :test_attr => 1
931
- end
932
- has_permission_on :permission_children, :to => :test do
933
- if_permitted_to :test, :shallow_permission => :permission
934
- end
935
- end
936
- end
937
- }
938
- engine = Authorization::Engine.new(reader)
939
-
940
- perm_data_attr_1 = PermissionMock.new({:test_attr => 1})
941
- perm_data_attr_2 = PermissionMock.new({:test_attr => 2})
942
- assert engine.permit?(:test, :context => :permission_children,
943
- :user => MockUser.new(:test_role),
944
- :object => MockDataObject.new(:shallow_permission =>
945
- MockDataObject.new(:permission => perm_data_attr_1)))
946
- assert !engine.permit?(:test, :context => :permission_children,
947
- :user => MockUser.new(:test_role),
948
- :object => MockDataObject.new(:shallow_permission =>
949
- MockDataObject.new(:permission => perm_data_attr_2)))
950
- end
951
-
952
- def test_attribute_with_deep_has_many_permissions
953
- reader = Authorization::Reader::DSLReader.new
954
- reader.parse %{
955
- authorization do
956
- role :test_role do
957
- has_permission_on :permissions, :to => :test do
958
- if_attribute :test_attr => 1
959
- end
960
- has_permission_on :permission_children, :to => :test do
961
- if_permitted_to :test, :shallow_permissions => :permission
962
- end
963
- end
964
- end
965
- }
966
- engine = Authorization::Engine.new(reader)
967
-
968
- perm_data_attr_1 = PermissionMock.new({:test_attr => 1})
969
- perm_data_attr_2 = PermissionMock.new({:test_attr => 2})
970
- assert engine.permit?(:test, :context => :permission_children,
971
- :user => MockUser.new(:test_role),
972
- :object => MockDataObject.new(:shallow_permissions =>
973
- [MockDataObject.new(:permission => perm_data_attr_1)]))
974
- assert !engine.permit?(:test, :context => :permission_children,
975
- :user => MockUser.new(:test_role),
976
- :object => MockDataObject.new(:shallow_permissions =>
977
- [MockDataObject.new(:permission => perm_data_attr_2)]))
978
- end
979
-
980
- def test_attribute_with_permissions_nil
981
- reader = Authorization::Reader::DSLReader.new
982
- reader.parse %{
983
- authorization do
984
- role :test_role do
985
- has_permission_on :permissions, :to => :test do
986
- if_attribute :test_attr => 1
987
- end
988
- has_permission_on :permission_children, :to => :test do
989
- if_permitted_to :test, :permission
990
- end
991
- end
992
- end
993
- }
994
- engine = Authorization::Engine.new(reader)
995
-
996
- engine.permit?(:test, :context => :permission_children,
997
- :user => MockUser.new(:test_role),
998
- :object => MockDataObject.new(:permission => nil))
999
-
1000
- assert !engine.permit?(:test, :context => :permission_children,
1001
- :user => MockUser.new(:test_role),
1002
- :object => MockDataObject.new(:permission => nil))
1003
- end
1004
-
1005
- def test_attribute_with_permissions_on_self
1006
- reader = Authorization::Reader::DSLReader.new
1007
- reader.parse %{
1008
- authorization do
1009
- role :test_role do
1010
- has_permission_on :permissions, :to => :test do
1011
- if_attribute :test_attr => 1
1012
- end
1013
- has_permission_on :permissions, :to => :another_test do
1014
- if_permitted_to :test
1015
- end
1016
- end
1017
- end
1018
- }
1019
- engine = Authorization::Engine.new(reader)
1020
-
1021
- perm_data_attr_1 = PermissionMock.new({:test_attr => 1})
1022
- perm_data_attr_2 = PermissionMock.new({:test_attr => 2})
1023
- assert engine.permit?(:another_test, :context => :permissions,
1024
- :user => MockUser.new(:test_role),
1025
- :object => perm_data_attr_1)
1026
- assert !engine.permit?(:another_test, :context => :permissions,
1027
- :user => MockUser.new(:test_role),
1028
- :object => perm_data_attr_2)
1029
- end
1030
-
1031
- def test_attribute_with_permissions_on_self_with_context
1032
- reader = Authorization::Reader::DSLReader.new
1033
- reader.parse %{
1034
- authorization do
1035
- role :test_role do
1036
- has_permission_on :permissions, :to => :test do
1037
- if_attribute :test_attr => 1
1038
- end
1039
- has_permission_on :permissions, :to => :another_test do
1040
- if_permitted_to :test, :context => :permissions
1041
- end
1042
- end
1043
- end
1044
- }
1045
- engine = Authorization::Engine.new(reader)
1046
-
1047
- perm_data_attr_1 = PermissionMock.new({:test_attr => 1})
1048
- perm_data_attr_2 = PermissionMock.new({:test_attr => 2})
1049
- assert engine.permit?(:another_test, :context => :permissions,
1050
- :user => MockUser.new(:test_role),
1051
- :object => perm_data_attr_1)
1052
- assert !engine.permit?(:another_test, :context => :permissions,
1053
- :user => MockUser.new(:test_role),
1054
- :object => perm_data_attr_2)
1055
- end
1056
-
1057
- def test_attribute_with_permissions_and_anded_rules
1058
- reader = Authorization::Reader::DSLReader.new
1059
- reader.parse %{
1060
- authorization do
1061
- role :test_role do
1062
- has_permission_on :permissions, :to => :test do
1063
- if_attribute :test_attr => 1
1064
- end
1065
- has_permission_on :permission_children, :to => :test, :join_by => :and do
1066
- if_permitted_to :test, :permission
1067
- if_attribute :test_attr => 1
1068
- end
1069
- end
1070
- end
1071
- }
1072
- engine = Authorization::Engine.new(reader)
1073
-
1074
- perm_data_attr_1 = PermissionMock.new({:test_attr => 1})
1075
- perm_data_attr_2 = PermissionMock.new({:test_attr => 2})
1076
- assert engine.permit?(:test, :context => :permission_children,
1077
- :user => MockUser.new(:test_role),
1078
- :object => MockDataObject.new(:permission => perm_data_attr_1, :test_attr => 1))
1079
- assert !engine.permit?(:test, :context => :permission_children,
1080
- :user => MockUser.new(:test_role),
1081
- :object => MockDataObject.new(:permission => perm_data_attr_2, :test_attr => 1))
1082
- assert !engine.permit?(:test, :context => :permission_children,
1083
- :user => MockUser.new(:test_role),
1084
- :object => MockDataObject.new(:permission => perm_data_attr_1, :test_attr => 2))
1085
- end
1086
-
1087
- def test_attribute_with_anded_rules
1088
- reader = Authorization::Reader::DSLReader.new
1089
- reader.parse %{
1090
- authorization do
1091
- role :test_role do
1092
- has_permission_on :permissions, :to => :test, :join_by => :and do
1093
- if_attribute :test_attr => 1
1094
- if_attribute :test_attr_2 => 2
1095
- end
1096
- end
1097
- end
1098
- }
1099
- engine = Authorization::Engine.new(reader)
1100
-
1101
- assert engine.permit?(:test, :context => :permissions,
1102
- :user => MockUser.new(:test_role),
1103
- :object => MockDataObject.new(:test_attr => 1, :test_attr_2 => 2))
1104
- assert !engine.permit?(:test, :context => :permissions,
1105
- :user => MockUser.new(:test_role),
1106
- :object => MockDataObject.new(:test_attr => 1, :test_attr_2 => 3))
1107
- end
1108
-
1109
- def test_raise_on_if_attribute_hash_on_collection
1110
- reader = Authorization::Reader::DSLReader.new
1111
- reader.parse %{
1112
- authorization do
1113
- role :test_role do
1114
- has_permission_on :permissions, :to => :test do
1115
- if_attribute :test_attrs => {:attr => is {1}}
1116
- end
1117
- end
1118
- end
1119
- }
1120
- engine = Authorization::Engine.new(reader)
1121
- assert_raise Authorization::AuthorizationUsageError do
1122
- engine.permit?(:test, :context => :permissions,
1123
- :user => MockUser.new(:test_role),
1124
- :object => MockDataObject.new(:test_attrs => [1, 2, 3]))
1125
- end
1126
- end
1127
-
1128
- def test_role_title_description
1129
- reader = Authorization::Reader::DSLReader.new
1130
- reader.parse %{
1131
- authorization do
1132
- role :test_role, :title => 'Test Role' do
1133
- description "Test Role Description"
1134
- end
1135
- end
1136
- }
1137
- engine = Authorization::Engine.new(reader)
1138
- assert engine.roles.include?(:test_role)
1139
- assert_equal "Test Role", engine.role_titles[:test_role]
1140
- assert_equal "Test Role", engine.title_for(:test_role)
1141
- assert_nil engine.title_for(:test_role_2)
1142
- assert_equal "Test Role Description", engine.role_descriptions[:test_role]
1143
- assert_equal "Test Role Description", engine.description_for(:test_role)
1144
- assert_nil engine.description_for(:test_role_2)
1145
- end
1146
-
1147
- def test_multithread
1148
- reader = Authorization::Reader::DSLReader.new
1149
- reader.parse %{
1150
- authorization do
1151
- role :test_role do
1152
- has_permission_on :permissions, :to => :test
1153
- end
1154
- end
1155
- }
1156
-
1157
- engine = Authorization::Engine.new(reader)
1158
- Authorization.stub :current_user, MockUser.new(:test_role) do
1159
- assert engine.permit?(:test, :context => :permissions)
1160
- Thread.new do
1161
- Authorization.current_user = MockUser.new(:test_role2)
1162
- assert !engine.permit?(:test, :context => :permissions)
1163
- end
1164
- assert engine.permit?(:test, :context => :permissions)
1165
- end
1166
- end
1167
-
1168
- def test_clone
1169
- reader = Authorization::Reader::DSLReader.new
1170
- reader.parse %{
1171
- authorization do
1172
- role :test_role do
1173
- has_permission_on :permissions, :to => :test do
1174
- if_attribute :attr => { :sub_attr => is { user } }
1175
- if_permitted_to :read, :attr_2 => :attr_3
1176
- if_permitted_to :read, :attr_2
1177
- end
1178
- end
1179
- end
1180
- }
1181
-
1182
- engine = Authorization::Engine.new(reader)
1183
- cloned_engine = engine.clone
1184
- assert_not_equal engine.auth_rules.first.contexts.object_id,
1185
- cloned_engine.auth_rules.first.contexts.object_id
1186
- assert_not_equal engine.auth_rules.first.attributes.first.send(:instance_variable_get, :@conditions_hash)[:attr].object_id,
1187
- cloned_engine.auth_rules.first.attributes.first.send(:instance_variable_get, :@conditions_hash)[:attr].object_id
1188
- end
1189
- end