acl9 0.12.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +21 -7
- data/.travis.yml +19 -0
- data/Appraisals +8 -0
- data/CONTRIBUTING.md +58 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +88 -32
- data/LICENSE +9 -0
- data/README.md +156 -0
- data/Rakefile +6 -3
- data/acl9.gemspec +10 -13
- data/gemfiles/rails_4.0.gemfile +8 -0
- data/gemfiles/rails_4.1.gemfile +8 -0
- data/lib/acl9/model_extensions/for_subject.rb +5 -1
- data/lib/acl9/model_extensions.rb +3 -24
- data/lib/acl9/version.rb +1 -1
- data/lib/acl9.rb +1 -1
- data/test/controller_extensions/actions_test.rb +167 -0
- data/test/controller_extensions/anon_test.rb +39 -0
- data/test/controller_extensions/base.rb +96 -0
- data/test/controller_extensions/basics_test.rb +44 -0
- data/test/controller_extensions/conditions_test.rb +48 -0
- data/test/controller_extensions/method_test.rb +50 -0
- data/test/controller_extensions/multi_match_test.rb +142 -0
- data/test/controller_extensions/multiple_role_arguments_test.rb +135 -0
- data/test/controller_extensions/prepositions_test.rb +99 -0
- data/test/controller_extensions/pseudo_role_test.rb +26 -0
- data/test/controller_extensions/role_test.rb +75 -0
- data/test/controllers/acl_action_override_test.rb +24 -0
- data/test/controllers/acl_arguments_test.rb +5 -0
- data/test/controllers/acl_block_test.rb +5 -0
- data/test/controllers/acl_boolean_method_test.rb +5 -0
- data/test/controllers/acl_helper_method_test.rb +26 -0
- data/test/controllers/acl_ivars_test.rb +15 -0
- data/test/controllers/acl_method2_test.rb +6 -0
- data/test/controllers/acl_method_test.rb +6 -0
- data/test/controllers/acl_object_hash_test.rb +18 -0
- data/test/controllers/acl_query_method_named_test.rb +9 -0
- data/test/controllers/acl_query_method_test.rb +9 -0
- data/test/controllers/acl_query_method_with_lambda_test.rb +9 -0
- data/test/controllers/acl_query_mixin.rb +51 -0
- data/test/controllers/acl_subject_method_test.rb +15 -0
- data/test/controllers/arguments_checking_test.rb +43 -0
- data/test/dummy/app/controllers/acl_action_override.rb +15 -0
- data/test/dummy/app/controllers/acl_arguments.rb +10 -0
- data/test/dummy/app/controllers/acl_block.rb +6 -0
- data/test/dummy/app/controllers/acl_boolean_method.rb +23 -0
- data/test/dummy/app/controllers/acl_helper_method.rb +11 -0
- data/test/dummy/app/controllers/acl_ivars.rb +17 -0
- data/test/dummy/app/controllers/acl_method.rb +6 -0
- data/test/dummy/app/controllers/acl_method2.rb +6 -0
- data/test/dummy/app/controllers/acl_objects_hash.rb +10 -0
- data/test/dummy/app/controllers/acl_query_method.rb +9 -0
- data/test/dummy/app/controllers/acl_query_method_named.rb +13 -0
- data/test/dummy/app/controllers/acl_query_method_with_lambda.rb +9 -0
- data/test/dummy/app/controllers/acl_subject_method.rb +16 -0
- data/test/dummy/app/controllers/application_controller.rb +7 -0
- data/test/dummy/app/controllers/empty_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/some_helper.rb +8 -0
- data/test/dummy/app/models/.keep +0 -0
- data/test/dummy/app/models/access.rb +3 -0
- data/test/dummy/app/models/account.rb +3 -0
- data/test/dummy/app/models/bar.rb +3 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/models/foo.rb +3 -0
- data/test/dummy/app/models/foo_bar.rb +3 -0
- data/test/dummy/app/models/other/foo.rb +5 -0
- data/test/dummy/app/models/other/role.rb +5 -0
- data/test/dummy/app/models/other/user.rb +5 -0
- data/test/dummy/app/models/role.rb +3 -0
- data/test/dummy/app/models/user.rb +3 -0
- data/test/dummy/app/models/uuid.rb +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +4 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +78 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/assets.rb +8 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/secrets.rb +1 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/migrate/20141117132218_create_tables.rb +102 -0
- data/test/helpers/helper_test.rb +89 -0
- data/test/models/roles_test.rb +251 -0
- data/test/models/roles_with_custom_association_names_test.rb +28 -0
- data/test/models/roles_with_custom_class_names_test.rb +28 -0
- data/test/models/system_roles_test.rb +16 -0
- data/test/models/users_roles_and_subjects_with_namespaced_class_names_test.rb +30 -0
- data/test/test_helper.rb +76 -23
- data/test/version_test.rb +2 -2
- metadata +190 -74
- data/README.textile +0 -921
- data/VERSION.yml +0 -5
- data/init.rb +0 -1
- data/test/access_control_test.rb +0 -338
- data/test/dsl_base_test.rb +0 -795
- data/test/helpers_test.rb +0 -133
- data/test/roles_test.rb +0 -370
- data/test/support/controllers.rb +0 -207
- data/test/support/models.rb +0 -59
- data/test/support/schema.rb +0 -93
@@ -0,0 +1,135 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
module ControllerExtensions
|
4
|
+
class MultipleRoleArgumentsTest < Base
|
5
|
+
test "#allow should be able to receive a role list (global roles)" do
|
6
|
+
assert ( bzz = User.create ).has_role! :bzz
|
7
|
+
assert ( whoa = User.create ).has_role! :whoa
|
8
|
+
|
9
|
+
@tester.acl_block! do
|
10
|
+
allow :bzz, :whoa
|
11
|
+
end
|
12
|
+
assert_permitted bzz
|
13
|
+
assert_permitted whoa
|
14
|
+
assert_forbidden nil
|
15
|
+
assert_forbidden User.create
|
16
|
+
end
|
17
|
+
|
18
|
+
test "#allow should be able to receive a role list (object roles)" do
|
19
|
+
assert foo = Foo.create
|
20
|
+
assert foo_too = Foo.create
|
21
|
+
|
22
|
+
assert ( maker = User.create ).has_role! :maker, foo
|
23
|
+
assert ( faker = User.create ).has_role! :faker, foo_too
|
24
|
+
|
25
|
+
@tester.acl_block! do
|
26
|
+
allow :maker, :faker, :of => :foo
|
27
|
+
end
|
28
|
+
|
29
|
+
assert_permitted maker, :foo => foo
|
30
|
+
assert_forbidden maker, :foo => foo_too
|
31
|
+
assert_permitted faker, :foo => foo_too
|
32
|
+
assert_forbidden faker, :foo => foo
|
33
|
+
|
34
|
+
assert other = User.create
|
35
|
+
assert_forbidden other, :foo => foo
|
36
|
+
assert_forbidden other, :foo => foo_too
|
37
|
+
assert_forbidden nil
|
38
|
+
end
|
39
|
+
|
40
|
+
test "#allow should be able to receive a role list (class roles)" do
|
41
|
+
assert ( frooble = User.create ).has_role! :frooble, Foo
|
42
|
+
assert ( oombigle = User.create ).has_role! :oombigle, Foo
|
43
|
+
assert ( lame_frooble = User.create ).has_role! :frooble
|
44
|
+
|
45
|
+
@tester.acl_block! do
|
46
|
+
allow :frooble, :oombigle, :by => Foo
|
47
|
+
end
|
48
|
+
assert_permitted frooble
|
49
|
+
assert_permitted oombigle
|
50
|
+
assert_forbidden lame_frooble
|
51
|
+
assert_forbidden nil
|
52
|
+
end
|
53
|
+
|
54
|
+
test "#deny should be able to receive a role list (global roles)" do
|
55
|
+
assert ( bzz = User.create ).has_role! :bzz
|
56
|
+
assert ( whoa = User.create ).has_role! :whoa
|
57
|
+
|
58
|
+
@tester.acl_block! do
|
59
|
+
default :allow
|
60
|
+
deny :bzz, :whoa
|
61
|
+
end
|
62
|
+
|
63
|
+
assert_forbidden bzz
|
64
|
+
assert_forbidden whoa
|
65
|
+
assert_permitted nil
|
66
|
+
assert_permitted User.create
|
67
|
+
end
|
68
|
+
|
69
|
+
test "#deny should be able to receive a role list (object roles)" do
|
70
|
+
assert foo = Foo.create
|
71
|
+
assert foo_too = Foo.create
|
72
|
+
|
73
|
+
assert ( maker = User.create ).has_role! :maker, foo
|
74
|
+
assert ( faker = User.create ).has_role! :faker, foo_too
|
75
|
+
|
76
|
+
@tester.acl_block! do
|
77
|
+
default :allow
|
78
|
+
deny :maker, :faker, :of => :foo
|
79
|
+
end
|
80
|
+
|
81
|
+
assert_forbidden maker, :foo => foo
|
82
|
+
assert_permitted maker, :foo => foo_too
|
83
|
+
assert_forbidden faker, :foo => foo_too
|
84
|
+
assert_permitted faker, :foo => foo
|
85
|
+
|
86
|
+
assert other = User.create
|
87
|
+
assert_permitted other, :foo => foo
|
88
|
+
assert_permitted other, :foo => foo_too
|
89
|
+
assert_permitted nil
|
90
|
+
end
|
91
|
+
|
92
|
+
test "#deny should be able to receive a role list (class roles)" do
|
93
|
+
assert ( frooble = User.create ).has_role! :frooble, Foo
|
94
|
+
assert ( oombigle = User.create ).has_role! :oombigle, Foo
|
95
|
+
assert ( lame_frooble = User.create ).has_role! :frooble
|
96
|
+
|
97
|
+
@tester.acl_block! do
|
98
|
+
default :allow
|
99
|
+
deny :frooble, :oombigle, :by => Foo
|
100
|
+
end
|
101
|
+
|
102
|
+
assert_forbidden frooble
|
103
|
+
assert_forbidden oombigle
|
104
|
+
assert_permitted lame_frooble
|
105
|
+
assert_permitted nil
|
106
|
+
end
|
107
|
+
|
108
|
+
test "should also respect :to and :except" do
|
109
|
+
assert foo = Foo.create
|
110
|
+
|
111
|
+
assert ( foo = User.create ).has_role! :foo
|
112
|
+
assert ( joo = User.create ).has_role! :joo, foo
|
113
|
+
assert ( qoo = User.create ).has_role! :qoo, Bar
|
114
|
+
|
115
|
+
@tester.acl_block! do
|
116
|
+
allow :foo, :boo, :to => [:index, :show]
|
117
|
+
allow :zoo, :joo, :by => :foo, :to => [:edit, :update]
|
118
|
+
allow :qoo, :woo, :of => Bar
|
119
|
+
deny :qoo, :woo, :of => Bar, :except => [:delete, :destroy]
|
120
|
+
end
|
121
|
+
|
122
|
+
assert_permitted foo, 'index'
|
123
|
+
assert_permitted foo, 'show'
|
124
|
+
assert_forbidden foo, 'edit'
|
125
|
+
assert_permitted joo, 'edit', :foo => foo
|
126
|
+
assert_permitted joo, 'update', :foo => foo
|
127
|
+
assert_forbidden joo, 'show', :foo => foo
|
128
|
+
assert_forbidden joo, 'show'
|
129
|
+
assert_permitted qoo, 'delete'
|
130
|
+
assert_permitted qoo, 'destroy'
|
131
|
+
assert_forbidden qoo, 'edit'
|
132
|
+
assert_forbidden qoo, 'show'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
module ControllerExtensions
|
4
|
+
class PrepositionsTest < Base
|
5
|
+
|
6
|
+
%i[of for in on at by].each do |prep|
|
7
|
+
test "allow :#{prep} => :foo checks @foo" do
|
8
|
+
assert @foo = Foo.first_or_create
|
9
|
+
assert ( user = User.create ).has_role! :manager, @foo
|
10
|
+
|
11
|
+
@tester.acl_block! do
|
12
|
+
allow :manager, prep => :foo
|
13
|
+
end
|
14
|
+
|
15
|
+
assert other_foo = Foo.create
|
16
|
+
|
17
|
+
assert_permitted user, :foo => @foo
|
18
|
+
assert_forbidden user, :foo => other_foo
|
19
|
+
assert_forbidden user, :foo => Foo
|
20
|
+
assert_forbidden nil, :foo => @foo
|
21
|
+
assert_forbidden User.create, :foo => @foo
|
22
|
+
end
|
23
|
+
|
24
|
+
test "invalid allow :#{prep} arg raises ArgumentError" do
|
25
|
+
assert_raise ArgumentError do
|
26
|
+
@tester.acl_block! { allow :hom, :by => 1 }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
test "allow class role allowed" do
|
32
|
+
assert ( user = User.create ).has_role! :owner, Foo
|
33
|
+
|
34
|
+
@tester.acl_block! do
|
35
|
+
allow :owner, :of => Foo
|
36
|
+
end
|
37
|
+
|
38
|
+
assert_permitted user
|
39
|
+
assert_forbidden nil
|
40
|
+
assert_forbidden User.create
|
41
|
+
end
|
42
|
+
|
43
|
+
%i[of for in on at by].each do |prep|
|
44
|
+
test "deny :#{prep} => :foo checks @foo" do
|
45
|
+
assert @foo = Foo.first_or_create
|
46
|
+
assert ( user = User.create ).has_role! :thief, @foo
|
47
|
+
|
48
|
+
@tester.acl_block! do
|
49
|
+
default :allow
|
50
|
+
deny :thief, prep => :foo
|
51
|
+
end
|
52
|
+
|
53
|
+
assert_forbidden user, :foo => @foo
|
54
|
+
assert_permitted user, :foo => Foo.create
|
55
|
+
assert_permitted user, :foo => Foo
|
56
|
+
assert_permitted nil, :foo => @foo
|
57
|
+
assert_permitted User.create, :foo => @foo
|
58
|
+
end
|
59
|
+
|
60
|
+
test "invalid deny :#{prep} arg raises ArgumentError" do
|
61
|
+
assert_raise ArgumentError do
|
62
|
+
@tester.acl_block! { deny :her, :for => "him" }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
test "deny class role denied" do
|
68
|
+
assert ( user = User.create ).has_role! :ignorant, Foo
|
69
|
+
|
70
|
+
@tester.acl_block! do
|
71
|
+
default :allow
|
72
|
+
deny :ignorant, :of => Foo
|
73
|
+
end
|
74
|
+
|
75
|
+
assert_forbidden user, Foo
|
76
|
+
assert_permitted nil
|
77
|
+
assert_permitted User.create
|
78
|
+
end
|
79
|
+
|
80
|
+
test "> 1 allow prepositions raises ArgumentError" do
|
81
|
+
assert_raise ArgumentError do
|
82
|
+
@tester.acl_block! { allow :some, :by => :one, :for => :another }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
test "> 1 deny prepositions raises ArgumentError" do
|
87
|
+
assert_raise ArgumentError do
|
88
|
+
@tester.acl_block! { deny :some, :in => :here, :on => :today }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
test "should raise an ArgumentError when both :to and :except are specified" do
|
93
|
+
assert_raise ArgumentError do
|
94
|
+
@tester.acl_block! { allow all, :to => :index, :except => ['show', 'edit'] }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
module ControllerExtensions
|
4
|
+
class PseudoRoleTest < Base
|
5
|
+
%i[all everyone everybody anyone].each do |pseudorole|
|
6
|
+
test "allow #{pseudorole} allows all" do
|
7
|
+
@tester.acl_block! do
|
8
|
+
allow send pseudorole
|
9
|
+
end
|
10
|
+
|
11
|
+
assert_equal :deny, @tester.default_action
|
12
|
+
assert_all_permitted
|
13
|
+
end
|
14
|
+
|
15
|
+
test "deny #{pseudorole} denies all" do
|
16
|
+
@tester.acl_block! do
|
17
|
+
default :allow
|
18
|
+
deny send pseudorole
|
19
|
+
end
|
20
|
+
|
21
|
+
assert_equal :allow, @tester.default_action
|
22
|
+
assert_all_forbidden
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
module ControllerExtensions
|
4
|
+
class RoleTest < Base
|
5
|
+
test "allows admin implicit default" do
|
6
|
+
@tester.acl_block! { allow :admin }
|
7
|
+
|
8
|
+
assert_admins_permitted
|
9
|
+
assert_forbidden nil
|
10
|
+
|
11
|
+
assert ( user = User.create ).has_role! :cool
|
12
|
+
assert_forbidden user
|
13
|
+
end
|
14
|
+
|
15
|
+
test "allow plural admins implicit default" do
|
16
|
+
@tester.acl_block! do
|
17
|
+
allow :admins
|
18
|
+
end
|
19
|
+
|
20
|
+
assert_admins_permitted
|
21
|
+
assert_forbidden nil
|
22
|
+
|
23
|
+
assert ( user = User.create ).has_role! :cool
|
24
|
+
assert_forbidden user
|
25
|
+
end
|
26
|
+
|
27
|
+
test "allow with several roles" do
|
28
|
+
assert ( cool1_user = User.create ).has_role! :cool
|
29
|
+
assert ( cool2_user = User.create ).has_role! :cool
|
30
|
+
assert ( super_user = User.create ).has_role! :super
|
31
|
+
|
32
|
+
@tester.acl_block! do
|
33
|
+
allow :admin
|
34
|
+
allow :cool
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_admins_permitted
|
38
|
+
|
39
|
+
assert_permitted cool1_user
|
40
|
+
assert_permitted cool2_user
|
41
|
+
|
42
|
+
assert_forbidden nil
|
43
|
+
assert_forbidden super_user
|
44
|
+
end
|
45
|
+
|
46
|
+
test "deny plural admins" do
|
47
|
+
@tester.acl_block! do
|
48
|
+
default :allow
|
49
|
+
deny :admins
|
50
|
+
end
|
51
|
+
|
52
|
+
assert_permitted nil
|
53
|
+
assert_permitted User.create
|
54
|
+
assert_admins_forbidden
|
55
|
+
end
|
56
|
+
|
57
|
+
test "deny several roles" do
|
58
|
+
assert ( cool1_user = User.create ).has_role! :cool
|
59
|
+
assert ( cool2_user = User.create ).has_role! :cool
|
60
|
+
assert ( super_user = User.create ).has_role! :super
|
61
|
+
|
62
|
+
@tester.acl_block! do
|
63
|
+
default :allow
|
64
|
+
deny :admin
|
65
|
+
deny :cool
|
66
|
+
end
|
67
|
+
|
68
|
+
assert_permitted nil
|
69
|
+
assert_admins_forbidden
|
70
|
+
assert_forbidden cool1_user
|
71
|
+
assert_forbidden cool2_user
|
72
|
+
assert_permitted super_user
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ACLActionOverrideTest < ActionController::TestCase
|
4
|
+
test "anon can index" do
|
5
|
+
assert get :check_allow, :_action => :index
|
6
|
+
assert_response :ok
|
7
|
+
end
|
8
|
+
|
9
|
+
test "anon can't show" do
|
10
|
+
assert get :check_allow, :_action => :show
|
11
|
+
assert_response :unauthorized
|
12
|
+
end
|
13
|
+
|
14
|
+
test "normal user can't edit" do
|
15
|
+
assert get :check_allow_with_foo, :_action => :edit, :user_id => User.create.id
|
16
|
+
assert_response :unauthorized
|
17
|
+
end
|
18
|
+
|
19
|
+
test "foo owner can edit" do
|
20
|
+
assert ( user = User.create ).has_role! :owner, Foo.first_or_create
|
21
|
+
assert get :check_allow_with_foo, :_action => :edit, :user_id => user.id
|
22
|
+
assert_response :ok
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ACLHelperMethodTest < ActionController::TestCase
|
4
|
+
setup do
|
5
|
+
assert @user = User.create
|
6
|
+
end
|
7
|
+
|
8
|
+
test "foo owner allowed" do
|
9
|
+
assert @user.has_role! :owner, Foo.first_or_create
|
10
|
+
|
11
|
+
assert get :allow, :user_id => @user.id
|
12
|
+
assert_select 'div', 'OK'
|
13
|
+
end
|
14
|
+
|
15
|
+
test "another user denied" do
|
16
|
+
assert @user.has_role! :owner
|
17
|
+
|
18
|
+
assert get :allow, :user_id => @user.id
|
19
|
+
assert_select 'div', 'OK'
|
20
|
+
end
|
21
|
+
|
22
|
+
test "anon denied" do
|
23
|
+
assert get :allow
|
24
|
+
assert_select 'div', 'AccessDenied'
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ACLIvarsTest < ActionController::TestCase
|
4
|
+
test "owner of foo destroys" do
|
5
|
+
assert ( user = User.create ).has_role! :owner, Bar
|
6
|
+
assert delete :destroy, :id => 1, :user_id => user.id
|
7
|
+
assert_response :ok
|
8
|
+
end
|
9
|
+
|
10
|
+
test "bartender at Foo destroys" do
|
11
|
+
assert ( user = User.create ).has_role! :bartender, Foo
|
12
|
+
assert delete :destroy, :id => 1, :user_id => user.id
|
13
|
+
assert_response :ok
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ACLObjectsHashTest < ActionController::TestCase
|
4
|
+
setup do
|
5
|
+
assert @user = User.create
|
6
|
+
assert @user.has_role! :owner, Foo.first_or_create
|
7
|
+
end
|
8
|
+
|
9
|
+
test "objects hash preferred to @ivar" do
|
10
|
+
assert get :allow, :user_id => @user.id
|
11
|
+
assert_response :ok
|
12
|
+
end
|
13
|
+
|
14
|
+
test "unauthed for no user" do
|
15
|
+
assert get :allow
|
16
|
+
assert_response :unauthorized
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module ACLQueryMixin
|
4
|
+
def self.included base
|
5
|
+
base.class_eval do
|
6
|
+
setup do
|
7
|
+
( @editor = User.create ).has_role! :editor
|
8
|
+
( @viewer = User.create ).has_role! :viewer
|
9
|
+
( @owneroffoo = User.create ).has_role! :owner, Foo.first_or_create
|
10
|
+
end
|
11
|
+
|
12
|
+
%i[edit update destroy].each do |meth|
|
13
|
+
test "should return true for editor/#{meth}" do
|
14
|
+
assert @controller.current_user = @editor
|
15
|
+
assert @controller.acl? meth
|
16
|
+
assert @controller.acl? meth.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
test "should return false for viewer/#{meth}" do
|
20
|
+
assert @controller.current_user = @viewer
|
21
|
+
refute @controller.acl? meth
|
22
|
+
refute @controller.acl? meth.to_s
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
%i[index show].each do |meth|
|
27
|
+
test "should return false for editor/#{meth}" do
|
28
|
+
assert @controller.current_user = @editor
|
29
|
+
refute @controller.acl? meth
|
30
|
+
refute @controller.acl? meth.to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
test "should return true for viewer/#{meth}" do
|
34
|
+
assert @controller.current_user = @viewer
|
35
|
+
assert @controller.acl? meth
|
36
|
+
assert @controller.acl? meth.to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
test "should return false for editor/fooize" do
|
41
|
+
assert @controller.current_user = @editor
|
42
|
+
refute @controller.acl? :fooize
|
43
|
+
end
|
44
|
+
|
45
|
+
test "should return true for foo owner" do
|
46
|
+
assert @controller.current_user = @owneroffoo
|
47
|
+
assert @controller.acl? :fooize, :foo => Foo.first
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ACLSubjectMethodTest < ActionController::TestCase
|
4
|
+
test "allow the only user to index" do
|
5
|
+
assert ( user = User.create ).has_role! :the_only_one
|
6
|
+
assert get :index, :user_id => user.id
|
7
|
+
assert_response :ok
|
8
|
+
end
|
9
|
+
|
10
|
+
test "deny anonymous to index" do
|
11
|
+
assert_raises Acl9::AccessDenied do
|
12
|
+
assert get :index
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ArgumentsCheckingTest < ActionController::TestCase
|
4
|
+
test "raise ArgumentError without a block" do
|
5
|
+
assert_raise ArgumentError do
|
6
|
+
class FailureController < ApplicationController
|
7
|
+
access_control
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
test "raise ArgumentError with 1st argument which is not a symbol" do
|
13
|
+
assert_raise ArgumentError do
|
14
|
+
class FailureController < ApplicationController
|
15
|
+
access_control 123 do end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
test "raise ArgumentError with more than 1 positional argument" do
|
21
|
+
assert_raise ArgumentError do
|
22
|
+
class FailureController < ApplicationController
|
23
|
+
access_control :foo, :bar do end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
test "raise ArgumentError with :helper => true and no method name" do
|
29
|
+
assert_raise ArgumentError do
|
30
|
+
class FailureController < ApplicationController
|
31
|
+
access_control :helper => true do end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
test "raise ArgumentError with :helper => :method and a method name" do
|
37
|
+
assert_raise ArgumentError do
|
38
|
+
class FailureController < ApplicationController
|
39
|
+
access_control :meth, :helper => :another_meth do end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class ACLActionOverride < ApplicationController
|
2
|
+
access_control :allowed?, :filter => false do
|
3
|
+
allow all, :to => :index
|
4
|
+
deny all, :to => :show
|
5
|
+
allow :owner, :of => :foo, :to => :edit
|
6
|
+
end
|
7
|
+
|
8
|
+
def check_allow
|
9
|
+
head allowed?(params[:_action]) ? :ok : :unauthorized
|
10
|
+
end
|
11
|
+
|
12
|
+
def check_allow_with_foo
|
13
|
+
head allowed?(params[:_action], :foo => Foo.first) ? :ok : :unauthorized
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class ACLBooleanMethod < EmptyController
|
2
|
+
access_control :acl, :filter => false do
|
3
|
+
allow all, :to => [:index, :show], :if => :true_meth
|
4
|
+
allow :admin, :unless => :false_meth
|
5
|
+
allow all, :if => :false_meth
|
6
|
+
allow all, :unless => :true_meth
|
7
|
+
end
|
8
|
+
|
9
|
+
before_filter :check_acl
|
10
|
+
|
11
|
+
def check_acl
|
12
|
+
if self.acl
|
13
|
+
true
|
14
|
+
else
|
15
|
+
raise Acl9::AccessDenied
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def true_meth; true end
|
22
|
+
def false_meth; false end
|
23
|
+
end
|