rails-acu 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.project +18 -0
- data/.rspec +3 -0
- data/.travis.yml +30 -0
- data/Gemfile +30 -0
- data/Gemfile.lock +169 -0
- data/MIT-LICENSE +20 -0
- data/README.md +221 -0
- data/Rakefile +26 -0
- data/bin/rails +13 -0
- data/lib/acu/configs.rb +30 -0
- data/lib/acu/engine.rb +9 -0
- data/lib/acu/errors.rb +37 -0
- data/lib/acu/helpers/helpers.rb +9 -0
- data/lib/acu/injectors.rb +15 -0
- data/lib/acu/listeners.rb +18 -0
- data/lib/acu/monitor.rb +201 -0
- data/lib/acu/rules.rb +134 -0
- data/lib/acu/utilities.rb +14 -0
- data/lib/acu/version.rb +3 -0
- data/lib/generators/acu/install_generator.rb +20 -0
- data/lib/generators/templates/rules.rb +34 -0
- data/lib/generators/templates/setup.rb +30 -0
- data/lib/rails-acu.rb +26 -0
- data/rails-acu-1.2.0.gem +0 -0
- data/rails-acu.gemspec +23 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +5 -0
- data/spec/dummy/app/assets/javascripts/admin/manage.js +2 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/javascripts/books.js +2 -0
- data/spec/dummy/app/assets/javascripts/cable.js +12 -0
- data/spec/dummy/app/assets/javascripts/comments.js +2 -0
- data/spec/dummy/app/assets/javascripts/home.js +2 -0
- data/spec/dummy/app/assets/stylesheets/admin/manage.css +4 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/assets/stylesheets/books.css +4 -0
- data/spec/dummy/app/assets/stylesheets/comments.css +4 -0
- data/spec/dummy/app/assets/stylesheets/home.css +4 -0
- data/spec/dummy/app/assets/stylesheets/scaffold.css +84 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/admin/manage_controller.rb +19 -0
- data/spec/dummy/app/controllers/application_controller.rb +4 -0
- data/spec/dummy/app/controllers/home_controller.rb +7 -0
- data/spec/dummy/app/helpers/admin/manage_helper.rb +2 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/home_helper.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/user.rb +8 -0
- data/spec/dummy/app/models/user_type.rb +3 -0
- data/spec/dummy/app/views/admin/manage/add.html.erb +2 -0
- data/spec/dummy/app/views/admin/manage/delete.html.erb +2 -0
- data/spec/dummy/app/views/admin/manage/index.html.erb +2 -0
- data/spec/dummy/app/views/admin/manage/list.html.erb +2 -0
- data/spec/dummy/app/views/admin/manage/prove.html.erb +2 -0
- data/spec/dummy/app/views/admin/manage/show.html.erb +2 -0
- data/spec/dummy/app/views/home/contact.html.erb +2 -0
- data/spec/dummy/app/views/home/index.html.erb +21 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +34 -0
- data/spec/dummy/bin/update +29 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/config/application.rb +23 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +9 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +54 -0
- data/spec/dummy/config/environments/production.rb +86 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/acu_rules.rb +31 -0
- data/spec/dummy/config/initializers/acu_setup.rb +14 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/devise.rb +277 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/new_framework_defaults.rb +24 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/devise.en.yml +64 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/puma.rb +47 -0
- data/spec/dummy/config/routes.rb +19 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/db/migrate/20170329111257_create_books.rb +9 -0
- data/spec/dummy/db/migrate/20170329111323_create_comments.rb +10 -0
- data/spec/dummy/db/migrate/20170329114943_devise_create_users.rb +42 -0
- data/spec/dummy/db/migrate/20170329120950_create_admin_user_types.rb +15 -0
- data/spec/dummy/db/migrate/20170329121612_add_user_type_id_to_users.rb +5 -0
- data/spec/dummy/db/schema.rb +59 -0
- data/spec/dummy/db/seeds.rb +39 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/spec/controllers/admin/manage_controller_spec.rb +72 -0
- data/spec/dummy/spec/controllers/application_controller_spec.rb +14 -0
- data/spec/dummy/spec/controllers/home_controller_spec.rb +560 -0
- data/spec/rails_helper.rb +59 -0
- data/spec/spec_helper.rb +104 -0
- metadata +268 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe Admin::ManageController, type: :controller do
|
4
|
+
|
5
|
+
before(:each) {
|
6
|
+
# reset rules
|
7
|
+
Acu::Rules.reset
|
8
|
+
# reset configs
|
9
|
+
Acu.setup do |config|
|
10
|
+
config.base_controller = :ApplicationController
|
11
|
+
config.allow_by_default = false
|
12
|
+
config.audit_log_file = '/tmp/acu-rspec.log'
|
13
|
+
end
|
14
|
+
}
|
15
|
+
|
16
|
+
it "should work with namespaces" do
|
17
|
+
Acu::Rules.define do
|
18
|
+
whois :everyone { true }
|
19
|
+
allow :everyone
|
20
|
+
end
|
21
|
+
get :index
|
22
|
+
|
23
|
+
Acu::Rules.define do
|
24
|
+
namespace do
|
25
|
+
controller :home do
|
26
|
+
deny :everyone, on: [:index, :contact]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
# we filtered the default namespace not this
|
31
|
+
get :index
|
32
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="index".*as `:everyone`/
|
33
|
+
|
34
|
+
Acu::Rules.define do
|
35
|
+
namespace :admin, except: [:posts] do
|
36
|
+
deny :everyone, on: [:show, :list]
|
37
|
+
end
|
38
|
+
namespace :admin, only: [:manage] do
|
39
|
+
deny :everyone, on: [:index]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
43
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*as `:everyone`/
|
44
|
+
expect {get :show}.to raise_error(Acu::Errors::AccessDenied)
|
45
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="show".*as `:everyone`/
|
46
|
+
expect {get :list}.to raise_error(Acu::Errors::AccessDenied)
|
47
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="list".*as `:everyone`/
|
48
|
+
end
|
49
|
+
it '[local-global & args]' do
|
50
|
+
Acu::Rules.define do
|
51
|
+
whois :admin, args: [:c] { |c| c == :admin }
|
52
|
+
whois :client, args: [:c] { |c| c == :client }
|
53
|
+
namespace :admin do
|
54
|
+
allow :admin
|
55
|
+
controller :manage, only: [:show] do
|
56
|
+
allow :client
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
Acu::Monitor.by c: :admin
|
61
|
+
get :index
|
62
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="index".*as `:admin`/
|
63
|
+
Acu::Monitor.by c: :client
|
64
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
65
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*\[autherized by :allow_by_default\]/
|
66
|
+
|
67
|
+
[:client, :admin].each do |cc|
|
68
|
+
Acu::Monitor.by c: cc
|
69
|
+
get :show
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe ApplicationController, type: :controller do
|
4
|
+
context 'database' do
|
5
|
+
it 'validate database' do
|
6
|
+
expect(User.count).to be 10
|
7
|
+
expect(UserType.count).to be 10
|
8
|
+
User.all.each do |u|
|
9
|
+
expect(u.user_type).not_to be_nil
|
10
|
+
expect(u.user_type.id == u.id).to be true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,560 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe HomeController, type: :controller do
|
4
|
+
|
5
|
+
before(:each) {
|
6
|
+
# reset rules
|
7
|
+
Acu::Rules.reset
|
8
|
+
# reset configs
|
9
|
+
Acu.setup do |config|
|
10
|
+
config.base_controller = :ApplicationController
|
11
|
+
config.allow_by_default = false
|
12
|
+
config.audit_log_file = '/tmp/acu-rspec.log'
|
13
|
+
config.use_cache = false
|
14
|
+
config.cache_namespace = 'acu'
|
15
|
+
config.cache_expires_in = nil
|
16
|
+
config.cache_race_condition_ttl = nil
|
17
|
+
end
|
18
|
+
}
|
19
|
+
|
20
|
+
def setup **kwargs
|
21
|
+
kwargs.each do |k, v|
|
22
|
+
Acu.setup { |c| eval("c.#{k} = #{v}") }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'Acu::Config' do
|
27
|
+
it '.base_controller' do
|
28
|
+
setup base_controller: ":FooBarController"
|
29
|
+
expect {get :index}.to raise_error(NameError)
|
30
|
+
end
|
31
|
+
|
32
|
+
it '.allow_by_default = false' do
|
33
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
34
|
+
end
|
35
|
+
|
36
|
+
it '.allow_by_default = true' do
|
37
|
+
begin
|
38
|
+
setup allow_by_default: true
|
39
|
+
get :index
|
40
|
+
rescue Acu::Errors::AccessDenied
|
41
|
+
fail "didn't expect to get Acu::Errors::AccessDenied, but got one!"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
it '.audit_log_file' do
|
45
|
+
setup audit_log_file: "'/tmp/acu-rspec.log'"
|
46
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
47
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to .* \[autherized by :allow_by_default\]/
|
48
|
+
setup allow_by_default: true
|
49
|
+
get :index
|
50
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to .* \[autherized by :allow_by_default\]/
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "Acu::Rules" do
|
55
|
+
context "[globals]" do
|
56
|
+
it "[single rule]" do
|
57
|
+
Acu::Rules.define do
|
58
|
+
whois :everyone { true }
|
59
|
+
allow :everyone
|
60
|
+
end
|
61
|
+
get :index
|
62
|
+
end
|
63
|
+
it "[multiple rules]" do
|
64
|
+
Acu::Rules.define do
|
65
|
+
whois :everyone { true }
|
66
|
+
whois :client { true }
|
67
|
+
allow :everyone
|
68
|
+
allow :client
|
69
|
+
end
|
70
|
+
expect(Acu::Rules.rules.length).to be 1
|
71
|
+
expect(Acu::Rules.rules[{}].length).to be 2
|
72
|
+
get :index
|
73
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="index".*as `:everyone, :client`/
|
74
|
+
end
|
75
|
+
it "{ one of rules failed = AccessDenied }" do
|
76
|
+
Acu::Rules.define do
|
77
|
+
whois :everyone { true }
|
78
|
+
whois :client { true }
|
79
|
+
# every request is :everyone
|
80
|
+
allow :everyone
|
81
|
+
# every reqyest is also :client
|
82
|
+
deny :client
|
83
|
+
end
|
84
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
85
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*as `:everyone, :client`/
|
86
|
+
|
87
|
+
Acu::Rules.define do
|
88
|
+
whois :client { false }
|
89
|
+
# every reqyest is also :client
|
90
|
+
deny :client
|
91
|
+
end
|
92
|
+
get :index
|
93
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="index".*as `:everyone`/
|
94
|
+
end
|
95
|
+
end
|
96
|
+
context "[levels]" do
|
97
|
+
context "[namespace]" do
|
98
|
+
it "[default]" do
|
99
|
+
Acu::Rules.define do
|
100
|
+
whois :everyone { true }
|
101
|
+
whois :client { false }
|
102
|
+
namespace do
|
103
|
+
allow :everyone
|
104
|
+
end
|
105
|
+
end
|
106
|
+
get :index
|
107
|
+
Acu::Rules.define do
|
108
|
+
namespace do
|
109
|
+
deny :everyone
|
110
|
+
end
|
111
|
+
end
|
112
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
113
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*as `:everyone`/
|
114
|
+
Acu::Rules.define do
|
115
|
+
namespace do
|
116
|
+
allow :everyone
|
117
|
+
end
|
118
|
+
namespace :FooBar do
|
119
|
+
deny :everyone
|
120
|
+
end
|
121
|
+
end
|
122
|
+
get :index
|
123
|
+
end
|
124
|
+
it "[default & global]" do
|
125
|
+
Acu::Rules.define do
|
126
|
+
whois :everyone { true }
|
127
|
+
whois :client { false }
|
128
|
+
|
129
|
+
namespace do
|
130
|
+
allow :everyone
|
131
|
+
end
|
132
|
+
|
133
|
+
deny :everyone
|
134
|
+
end
|
135
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
136
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*as `:everyone`/
|
137
|
+
end
|
138
|
+
it "[with only]" do
|
139
|
+
Acu::Rules.define do
|
140
|
+
whois :everyone { true }
|
141
|
+
namespace only: [:home] do
|
142
|
+
allow :everyone
|
143
|
+
end
|
144
|
+
end
|
145
|
+
get :index
|
146
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="index".*as `:everyone`/
|
147
|
+
|
148
|
+
Acu::Rules.define do
|
149
|
+
whois :everyone { true }
|
150
|
+
# override previous one
|
151
|
+
namespace only: [:home] do
|
152
|
+
deny :everyone
|
153
|
+
end
|
154
|
+
namespace only: [:foobar] do
|
155
|
+
allow :everyone
|
156
|
+
end
|
157
|
+
end
|
158
|
+
# by override
|
159
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
160
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*as `:everyone`/
|
161
|
+
end
|
162
|
+
it "[with except]" do
|
163
|
+
Acu::Rules.define do
|
164
|
+
whois :everyone { true }
|
165
|
+
namespace except: [:home] do
|
166
|
+
allow :everyone
|
167
|
+
end
|
168
|
+
end
|
169
|
+
# by default
|
170
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
171
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to .* \[autherized by :allow_by_default\]/
|
172
|
+
|
173
|
+
Acu::Rules.define do
|
174
|
+
whois :everyone { true }
|
175
|
+
namespace except: [:foobar] do
|
176
|
+
allow :everyone
|
177
|
+
end
|
178
|
+
end
|
179
|
+
get :index
|
180
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="index".*as `:everyone`/
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context "[controller]" do
|
185
|
+
it "[solo]" do
|
186
|
+
Acu::Rules.define do
|
187
|
+
whois :everyone { true }
|
188
|
+
controller :home do
|
189
|
+
end
|
190
|
+
end
|
191
|
+
# deny by default
|
192
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
193
|
+
|
194
|
+
Acu::Rules.define do
|
195
|
+
controller :home do
|
196
|
+
allow :everyone
|
197
|
+
end
|
198
|
+
end
|
199
|
+
get :index
|
200
|
+
end
|
201
|
+
it "[with only]" do
|
202
|
+
Acu::Rules.define do
|
203
|
+
whois :everyone { true }
|
204
|
+
controller :home, only: [:contact] do
|
205
|
+
end
|
206
|
+
end
|
207
|
+
# deny by default
|
208
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
209
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*\[autherized by :allow_by_default\]/
|
210
|
+
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
211
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="contact".*\[autherized by :allow_by_default\]/
|
212
|
+
|
213
|
+
Acu::Rules.define do
|
214
|
+
controller :home, only: [:contact] do
|
215
|
+
allow :everyone
|
216
|
+
end
|
217
|
+
end
|
218
|
+
get :contact
|
219
|
+
# deny by default
|
220
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
221
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*\[autherized by :allow_by_default\]/
|
222
|
+
|
223
|
+
# the rules won't override with above, this will give us the needed flexibility for multi-dimentional rules
|
224
|
+
Acu::Rules.define do
|
225
|
+
controller :home, only: [:index] do
|
226
|
+
allow :everyone
|
227
|
+
end
|
228
|
+
end
|
229
|
+
get :index
|
230
|
+
get :contact
|
231
|
+
Acu::Rules.define do
|
232
|
+
controller :home, only: [:index] do
|
233
|
+
deny :everyone
|
234
|
+
end
|
235
|
+
end
|
236
|
+
get :contact
|
237
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
238
|
+
end
|
239
|
+
it "[with except]" do
|
240
|
+
Acu::Rules.define do
|
241
|
+
whois :everyone { true }
|
242
|
+
controller :home, except: [:contact] do
|
243
|
+
end
|
244
|
+
end
|
245
|
+
# deny by default
|
246
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
247
|
+
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
248
|
+
|
249
|
+
Acu::Rules.define do
|
250
|
+
controller :home, except: [:contact] do
|
251
|
+
allow :everyone
|
252
|
+
end
|
253
|
+
end
|
254
|
+
get :index
|
255
|
+
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
256
|
+
|
257
|
+
# this will override the previous excepts
|
258
|
+
Acu::Rules.define do
|
259
|
+
controller :home, only: [:index] do
|
260
|
+
deny :everyone
|
261
|
+
end
|
262
|
+
end
|
263
|
+
# we have rule for this
|
264
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
265
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*as `:everyone`/
|
266
|
+
# and this is by detailt
|
267
|
+
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
268
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="contact".*\[autherized by :allow_by_default\]/
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
context "[action]" do
|
273
|
+
it "[parent: namespace]" do
|
274
|
+
Acu::Rules.define do
|
275
|
+
whois :everyone { true }
|
276
|
+
namespace do
|
277
|
+
action :index { allow :everyone }
|
278
|
+
action :contact { allow :everyone }
|
279
|
+
end
|
280
|
+
end
|
281
|
+
get :index
|
282
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="index".*as `:everyone`/
|
283
|
+
get :contact
|
284
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="contact".*as `:everyone`/
|
285
|
+
|
286
|
+
Acu::Rules.define do
|
287
|
+
namespace do
|
288
|
+
action :index { allow :everyone }
|
289
|
+
action :contact { deny :everyone }
|
290
|
+
end
|
291
|
+
end
|
292
|
+
get :index
|
293
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="index".*as `:everyone`/
|
294
|
+
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
295
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="contact".*as `:everyone`/
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
it "[parent: controller]" do
|
300
|
+
Acu::Rules.define do
|
301
|
+
whois :everyone { true }
|
302
|
+
controller :home do
|
303
|
+
end
|
304
|
+
end
|
305
|
+
# deny by default
|
306
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
307
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*\[autherized by :allow_by_default\]/
|
308
|
+
|
309
|
+
Acu::Rules.define do
|
310
|
+
controller :home do
|
311
|
+
action :contact { allow :everyone }
|
312
|
+
end
|
313
|
+
end
|
314
|
+
get :contact
|
315
|
+
# deny by default
|
316
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
317
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*\[autherized by :allow_by_default\]/
|
318
|
+
|
319
|
+
Acu::Rules.define do
|
320
|
+
controller :home do
|
321
|
+
action :index { allow :everyone }
|
322
|
+
action :contact { deny :everyone }
|
323
|
+
end
|
324
|
+
end
|
325
|
+
get :index
|
326
|
+
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
327
|
+
end
|
328
|
+
|
329
|
+
it "[parent: namespace, controller]" do
|
330
|
+
Acu::Rules.define do
|
331
|
+
whois :everyone { true }
|
332
|
+
namespace do
|
333
|
+
controller :home do
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|
337
|
+
# deny by default
|
338
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
339
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*\[autherized by :allow_by_default\]/
|
340
|
+
|
341
|
+
Acu::Rules.define do
|
342
|
+
namespace do
|
343
|
+
controller :home do
|
344
|
+
action :contact { allow :everyone }
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|
348
|
+
get :contact
|
349
|
+
# deny by default
|
350
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
351
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*\[autherized by :allow_by_default\]/
|
352
|
+
|
353
|
+
Acu::Rules.define do
|
354
|
+
namespace do
|
355
|
+
controller :home do
|
356
|
+
action :index { allow :everyone }
|
357
|
+
action :contact { deny :everyone }
|
358
|
+
end
|
359
|
+
end
|
360
|
+
end
|
361
|
+
get :index
|
362
|
+
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
363
|
+
|
364
|
+
# reset to change namespace
|
365
|
+
Acu::Rules.reset
|
366
|
+
Acu::Rules.define do
|
367
|
+
whois :everyone { true }
|
368
|
+
namespace :foobar do
|
369
|
+
controller :home do
|
370
|
+
action :index { allow :everyone }
|
371
|
+
action :contact { deny :everyone }
|
372
|
+
end
|
373
|
+
end
|
374
|
+
end
|
375
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
376
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*\[autherized by :allow_by_default\]/
|
377
|
+
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
378
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="contact".*\[autherized by :allow_by_default\]/
|
379
|
+
end
|
380
|
+
it '[local-global]' do
|
381
|
+
Acu::Rules.define do
|
382
|
+
whois :everyone { true }
|
383
|
+
namespace do
|
384
|
+
allow :everyone
|
385
|
+
controller :home, only: [:index] do
|
386
|
+
deny :everyone
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end
|
390
|
+
get :contact
|
391
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="contact".*as `:everyone`/
|
392
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
393
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*as `:everyone`/
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
context "[allow/deny]" do
|
398
|
+
it "[allow]" do
|
399
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
400
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*\[autherized by :allow_by_default\]/
|
401
|
+
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
402
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="contact".*\[autherized by :allow_by_default\]/
|
403
|
+
|
404
|
+
Acu::Rules.define do
|
405
|
+
whois :everyone { true }
|
406
|
+
namespace do
|
407
|
+
controller :home do
|
408
|
+
allow :everyone, on: [:index, :contact]
|
409
|
+
end
|
410
|
+
end
|
411
|
+
end
|
412
|
+
get :index
|
413
|
+
get :contact
|
414
|
+
end
|
415
|
+
it "[deny]" do
|
416
|
+
Acu::Rules.define do
|
417
|
+
whois :everyone { true }
|
418
|
+
allow :everyone
|
419
|
+
end
|
420
|
+
get :index
|
421
|
+
get :contact
|
422
|
+
|
423
|
+
Acu::Rules.define do
|
424
|
+
whois :everyone { true }
|
425
|
+
namespace do
|
426
|
+
controller :home do
|
427
|
+
deny :everyone, on: [:index, :contact]
|
428
|
+
end
|
429
|
+
end
|
430
|
+
end
|
431
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
432
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*as `:everyone`/
|
433
|
+
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
434
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="contact".*as `:everyone`/
|
435
|
+
end
|
436
|
+
it "[bulk settings]" do
|
437
|
+
Acu::Rules.define do
|
438
|
+
whois :everyone { true }
|
439
|
+
whois :client { false }
|
440
|
+
namespace do
|
441
|
+
controller :home do
|
442
|
+
allow [:everyone, :client], on: [:index, :contact]
|
443
|
+
end
|
444
|
+
end
|
445
|
+
end
|
446
|
+
get :index
|
447
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="index".*as `:everyone`/
|
448
|
+
get :contact
|
449
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="contact".*as `:everyone`/
|
450
|
+
Acu::Rules.define { whois :client { true } }
|
451
|
+
get :index
|
452
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="index".*as `:everyone, :client`/
|
453
|
+
get :contact
|
454
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="contact".*as `:everyone, :client`/
|
455
|
+
Acu::Rules.define do
|
456
|
+
namespace do
|
457
|
+
controller :home do
|
458
|
+
action :index { deny [:everyone, :client] }
|
459
|
+
end
|
460
|
+
end
|
461
|
+
end
|
462
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
463
|
+
# the first rule that failed is going to mention
|
464
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*as `:everyone, :client`/
|
465
|
+
get :contact
|
466
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="contact".*as `:everyone, :client`/
|
467
|
+
end
|
468
|
+
end
|
469
|
+
end
|
470
|
+
end
|
471
|
+
context "Acu::Helpers" do
|
472
|
+
it "acu_is?" do
|
473
|
+
Acu::Rules.define do
|
474
|
+
whois :everyone { true }
|
475
|
+
whois :client { false }
|
476
|
+
end
|
477
|
+
expect(acu_is? :everyone).to be true
|
478
|
+
expect(acu_is? :client).to be false
|
479
|
+
end
|
480
|
+
it "acu_do" do
|
481
|
+
Acu::Rules.define do
|
482
|
+
whois :everyone { true }
|
483
|
+
whois :client { false }
|
484
|
+
end
|
485
|
+
acu_as :everyone do
|
486
|
+
# a valid syntax
|
487
|
+
expect(false).not_to be true
|
488
|
+
end
|
489
|
+
acu_as :client do
|
490
|
+
# an invalid syntax, this should never run
|
491
|
+
expect(true).to be false
|
492
|
+
end
|
493
|
+
# the :everyone should get true
|
494
|
+
acu_as [:client, :everyone] do
|
495
|
+
expect(acu_is? :everyone).to be true
|
496
|
+
end
|
497
|
+
end
|
498
|
+
end
|
499
|
+
context 'caching' do
|
500
|
+
it '[Rails.cache]' do
|
501
|
+
# make we didn't used the caching until now!
|
502
|
+
expect(Acu::Configs.get :use_cache).to be false
|
503
|
+
Rails.cache.delete :FooBar
|
504
|
+
expect(Rails.cache.exist? :FooBar).to be false
|
505
|
+
Rails.cache.write :FooBar, __FILE__
|
506
|
+
expect(Rails.cache.exist? :FooBar).to be true
|
507
|
+
end
|
508
|
+
it '[caches?]' do
|
509
|
+
Acu::Rules.define do
|
510
|
+
whois :everyone { true }
|
511
|
+
namespace do
|
512
|
+
controller :home do
|
513
|
+
action :index { allow :everyone }
|
514
|
+
action :contact { deny :everyone }
|
515
|
+
end
|
516
|
+
end
|
517
|
+
end
|
518
|
+
# it shouldn't use cache because we haven't told it yet
|
519
|
+
5.times do
|
520
|
+
get :index
|
521
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /\[-\] access GRANTED to.*action="index".*as `:everyone`/
|
522
|
+
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
523
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /\[x\] access DENIED to.*action="contact".*as `:everyone`/
|
524
|
+
end
|
525
|
+
|
526
|
+
setup use_cache: true
|
527
|
+
Acu::Monitor.clear_cache
|
528
|
+
|
529
|
+
# make intial accesses, and cache
|
530
|
+
get :index
|
531
|
+
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
532
|
+
|
533
|
+
# both request should be ruled by cache now!
|
534
|
+
5.times do
|
535
|
+
get :index
|
536
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /\[-\]\[c\] access GRANTED to.*action="index".*as `:everyone`/
|
537
|
+
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
538
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /\[x\]\[c\] access DENIED to.*action="contact".*as `:everyone`/
|
539
|
+
end
|
540
|
+
end
|
541
|
+
it '[maintains cache]' do
|
542
|
+
setup use_cache: true
|
543
|
+
Acu::Rules.define do
|
544
|
+
whois :everyone { true }
|
545
|
+
namespace do
|
546
|
+
controller :home do
|
547
|
+
action :index { allow :everyone }
|
548
|
+
action :contact { deny :everyone }
|
549
|
+
end
|
550
|
+
end
|
551
|
+
end
|
552
|
+
5.times do
|
553
|
+
get :index
|
554
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /\[-\]\[c\] access GRANTED to.*action="index".*as `:everyone`/
|
555
|
+
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
556
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /\[x\]\[c\] access DENIED to.*action="contact".*as `:everyone`/
|
557
|
+
end
|
558
|
+
end
|
559
|
+
end
|
560
|
+
end
|