rails-acu 2.0.0 → 2.1.0
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +20 -9
- data/lib/acu/rules.rb +27 -18
- data/lib/acu/version.rb +1 -1
- data/lib/generators/templates/rules.rb +22 -10
- data/spec/dummy/spec/controllers/admin/manage_controller_spec.rb +6 -6
- data/spec/dummy/spec/controllers/home_controller_spec.rb +143 -88
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a7d60b156e3659b6855ebf7aaf31408b27d7cca
|
4
|
+
data.tar.gz: 3348325c341c48d2a4a24019882caca888f44d49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab06cba37ec9e9ee51a7f8c7d339e1d98906f4abb6521d616132411322c3de435017a51faeb816ac22a2a6af64d6473a9d3362e51c2d500d4e3ddd7bd4ebc261
|
7
|
+
data.tar.gz: 54381599563969a2a81af8f4d8a92e853f0667b4b30fe34aed5f7fb3e8cea53da2b517cbf6eb62750007ebd736824eda5419c81acefece4a5266fefbd6aba511
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -49,21 +49,33 @@ Acu::Rules.define do
|
|
49
49
|
|
50
50
|
whois :admin, args: [:user] { |c| c and c.user_type == :ADMIN.to_s }
|
51
51
|
|
52
|
-
whois :client, args: [:user] { |c| c and c.user_type == :
|
52
|
+
whois :client, args: [:user] { |c| c and c.user_type == :PUBLIC.to_s }
|
53
|
+
|
54
|
+
# admin can access to everywhere
|
55
|
+
allow :admin
|
53
56
|
|
54
57
|
# the default namespace
|
55
|
-
namespace do
|
56
|
-
|
57
|
-
|
58
|
+
namespace do
|
59
|
+
# assume anyone can access, your default namespace
|
60
|
+
allow :everyone
|
61
|
+
controller :home, :shop do
|
62
|
+
allow :admin, :client, on: [:some_secret_action1, :some_secret_action2]
|
63
|
+
# OR
|
64
|
+
# action :some_secret_action1, :some_secret_action2 do
|
65
|
+
# allow :admin, :client
|
66
|
+
# end
|
58
67
|
end
|
59
|
-
|
60
|
-
|
68
|
+
end
|
69
|
+
|
70
|
+
# allow every get access to public controller in 3 [default(the `nil`), admin]
|
71
|
+
namespace nil, :admin do
|
72
|
+
controller :public do
|
73
|
+
allow :everyone
|
61
74
|
end
|
62
75
|
end
|
63
76
|
|
64
77
|
# the admin namespace
|
65
78
|
namespace :admin do
|
66
|
-
allow :admin
|
67
79
|
|
68
80
|
controller :contact, only: [:send_message] do
|
69
81
|
allow :everyone
|
@@ -83,8 +95,7 @@ As we define our rules at the first line, we have to say who are the entities? _
|
|
83
95
|
Once we defined our entities we can set their binary access permissions at namespace/controller/action levels using `allow` and `deny` helpers. **that is it, we are done tutorialing; from now on is just tiny details. :)**
|
84
96
|
|
85
97
|
> **Scenario:** We have a *public* site which serves to its client's; we have 2 namespaces on this site, one is the _default_ namespace with _home_ controller in it, and the second namespace belongs to the _admin_ of site which has many controllers and also a _contact_ controller.<br />
|
86
|
-
We want to grant access to everyone for all of _home_ controller actions in _default_ namespace **except** the `
|
87
|
-
By default only `:admin` can access to the _admin_ namespace, but we made an exception for 2 actions in the `Admin::ContactController` which everyone can `send_message` to the admin and only clients can ask for `support`.<br />
|
98
|
+
We want to grant access to everyone for all of _home_ controller actions in _default_ namespace **except** the `some_secret_action1` and `some_secret_action2`; but these `some_secret_action*` can be accessed via the `:admin` and `:client` entities. By default only `:admin` can access to everywhere, but in namespace `admin` we made an exception for 2 actions in the `Admin::ContactController` which everyone can `send_message` to the admin and only clients can ask for `support`. Finally we want to grant access to everyone for _public_ controllers in our 2 namespaces _the default_ and _admin_. <br />
|
88
99
|
If you back trace it in the above example you can easily find this scenario in the rules, plain and simple.
|
89
100
|
|
90
101
|
### Gaurding the requests
|
data/lib/acu/rules.rb
CHANGED
@@ -30,32 +30,41 @@ module Acu
|
|
30
30
|
|
31
31
|
# only: only the defined `controllers` in the `namespace`
|
32
32
|
# except: except the defined `controllers` in the `namespace`
|
33
|
-
def namespace
|
33
|
+
def namespace *names, except: nil, only: nil
|
34
|
+
names = [nil] if names.empty?
|
34
35
|
only = nil if only and not (only.kind_of?(Array) or only.length == 0)
|
35
36
|
except = nil if except and not (except.kind_of?(Array) or except.length == 0)
|
36
|
-
raise Errors::AmbiguousRule.new('cannot have both `only` and `except` options at the same time for namespace `%s`' %
|
37
|
-
|
38
|
-
|
37
|
+
raise Errors::AmbiguousRule.new('cannot have both `only` and `except` options at the same time for namespace(s) `%s`' %names.join(', ')) if only and except
|
38
|
+
names.each do |name|
|
39
|
+
pass namespace: { name: name ? name.downcase : name, except: except, only: only } do
|
40
|
+
yield
|
41
|
+
end
|
39
42
|
end
|
40
43
|
end
|
41
44
|
|
42
45
|
# only: only the defined `actions` in the `controller`
|
43
46
|
# except: except the defined `actions` in the `controller`
|
44
|
-
def controller
|
47
|
+
def controller *names, except: nil, only: nil
|
48
|
+
names = [names].flatten if name
|
45
49
|
only = nil if only and not (only.kind_of?(Array) or only.length == 0)
|
46
50
|
except = nil if except and not (except.kind_of?(Array) or except.length == 0)
|
47
51
|
raise Errors::AmbiguousRule.new("there is already an `except` or `only` constraints defined in container namespace `#{@_params[:namespace][:name]}`") if @_params[:namespace] and (@_params[:namespace][:except] || @_params[:namespace][:only])
|
48
|
-
raise Errors::AmbiguousRule.new('cannot have both `only` and `except` options at the same time for controller `%s`' %
|
49
|
-
|
50
|
-
|
52
|
+
raise Errors::AmbiguousRule.new('cannot have both `only` and `except` options at the same time for controller(s) `%s`' %names.join(', ')) if only and except
|
53
|
+
names.each do |name|
|
54
|
+
pass controller: { name: name.downcase, except: except, only: only } do
|
55
|
+
yield
|
56
|
+
end
|
51
57
|
end
|
52
58
|
end
|
53
59
|
|
54
|
-
def action
|
60
|
+
def action *names
|
61
|
+
names = [names].flatten if name
|
55
62
|
raise Errors::AmbiguousRule.new("at least one of the parent `controller` or `namespace` needs to be defined for the this action") if not (@_params[:namespace] || @_params[:controller])
|
56
|
-
raise Errors::AmbiguousRule.new("there is already an `except` or `only` constraints defined in container controller `#{@_params[:controller][:name]}`") if @_params[:controller] and (@_params[:controller][:except] || @_params[:controller][:only])
|
57
|
-
|
58
|
-
|
63
|
+
raise Errors::AmbiguousRule.new("there is already an `except` or `only` constraints defined in container controller(s) `#{@_params[:controller][:name]}`") if @_params[:controller] and (@_params[:controller][:except] || @_params[:controller][:only])
|
64
|
+
names.each do |name|
|
65
|
+
pass action: { name: name.downcase } do
|
66
|
+
yield
|
67
|
+
end
|
59
68
|
end
|
60
69
|
end
|
61
70
|
|
@@ -80,20 +89,20 @@ module Acu
|
|
80
89
|
# at this point we assign the class varible rules #
|
81
90
|
###################################################
|
82
91
|
|
83
|
-
def allow symbol, on: []
|
84
|
-
op symbol, @GRANT_SYMBOL, on
|
92
|
+
def allow *symbol, on: []
|
93
|
+
op *symbol, @GRANT_SYMBOL, on
|
85
94
|
end
|
86
95
|
|
87
|
-
def deny symbol, on: []
|
88
|
-
op symbol, @DENY_SYMBOL, on
|
96
|
+
def deny *symbol, on: []
|
97
|
+
op *symbol, @DENY_SYMBOL, on
|
89
98
|
end
|
90
99
|
|
91
100
|
################### end of ops ####################
|
92
101
|
|
93
102
|
protected
|
94
103
|
|
95
|
-
def op symbol, opr, on
|
96
|
-
symbol =
|
104
|
+
def op *symbol, opr, on
|
105
|
+
symbol = symbol.flatten
|
97
106
|
raise Errors::InvalidData.new("invalid argument") if not symbol or symbol.to_s.blank? or opr.to_s.blank?
|
98
107
|
raise Errors::AmbiguousRule.new("cannot have `on` argument inside the action `#{@_params[:action][:name]}`") if not on.empty? and @_params[:action]
|
99
108
|
raise Errors::InvalidData.new("the symbol `#{symbol}` is not defined by `whois`") if not symbol.all? { |s| @entities.include? s }
|
data/lib/acu/version.rb
CHANGED
@@ -1,25 +1,37 @@
|
|
1
1
|
# This is an examble, modify it as well
|
2
2
|
Acu::Rules.define do
|
3
|
-
# anyone
|
3
|
+
# anyone makes a request could be count as everyone!
|
4
4
|
whois :everyone { true }
|
5
5
|
|
6
6
|
# whois :admin, args: [:user] { |c| c and c.user_type.symbol == :ADMIN.to_s }
|
7
7
|
# whois :client, args: [:user] { |c| c and c.user_type.symbol == :PUBLIC.to_s }
|
8
8
|
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# allow :everyone
|
9
|
+
# admin can access anywhere
|
10
|
+
# allow :admin
|
12
11
|
|
13
|
-
# the default namespace
|
14
|
-
# namespace do
|
15
|
-
#
|
16
|
-
#
|
12
|
+
# # the default namespace
|
13
|
+
# namespace do
|
14
|
+
# # assume anyone can access, your default namespace
|
15
|
+
# allow :everyone
|
16
|
+
#
|
17
|
+
# controller :home, :shop do
|
18
|
+
# allow :admin, :client, on: [:some_secret_action1, :some_secret_action2]
|
19
|
+
# # OR
|
20
|
+
# # action :some_secret_action1, :some_secret_action2 do
|
21
|
+
# # allow :admin, :client
|
22
|
+
# # end
|
17
23
|
# end
|
18
24
|
# end
|
19
25
|
|
20
|
-
# the admin
|
26
|
+
# # allow every get access to public controller in 3 [default(the `nil`), admin, emplyee]
|
27
|
+
# namespace nil, :admin, :emplyee do
|
28
|
+
# controller :public do
|
29
|
+
# allow :everyone
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
|
33
|
+
# # the admin namespace
|
21
34
|
# namespace :admin do
|
22
|
-
# allow :admin
|
23
35
|
|
24
36
|
# controller :contact, only: [:send_message] do
|
25
37
|
# allow :everyone
|
@@ -28,7 +28,7 @@ RSpec.describe Admin::ManageController, type: :controller do
|
|
28
28
|
end
|
29
29
|
# we filtered the default namespace not this
|
30
30
|
get :index
|
31
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="index".*as `:everyone`/
|
31
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*namespace="admin".*controller="manage".*action="index".*as `:everyone`/
|
32
32
|
|
33
33
|
Acu::Rules.define do
|
34
34
|
namespace :admin, except: [:posts] do
|
@@ -39,11 +39,11 @@ RSpec.describe Admin::ManageController, type: :controller do
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
42
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*as `:everyone`/
|
42
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace="admin".*controller="manage".*action="index".*as `:everyone`/
|
43
43
|
expect {get :show}.to raise_error(Acu::Errors::AccessDenied)
|
44
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="show".*as `:everyone`/
|
44
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace="admin".*controller="manage".*action="show".*as `:everyone`/
|
45
45
|
expect {get :list}.to raise_error(Acu::Errors::AccessDenied)
|
46
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="list".*as `:everyone`/
|
46
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace="admin".*controller="manage".*action="list".*as `:everyone`/
|
47
47
|
end
|
48
48
|
it '[local-global & args]' do
|
49
49
|
Acu::Rules.define do
|
@@ -58,10 +58,10 @@ RSpec.describe Admin::ManageController, type: :controller do
|
|
58
58
|
end
|
59
59
|
Acu::Monitor.args c: :admin
|
60
60
|
get :index
|
61
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="index".*as `:admin`/
|
61
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*namespace="admin".*controller="manage".*action="index".*as `:admin`/
|
62
62
|
Acu::Monitor.args c: :client
|
63
63
|
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
64
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*\[autherized by :allow_by_default\]/
|
64
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace="admin".*controller="manage".*action="index".*\[autherized by :allow_by_default\]/
|
65
65
|
|
66
66
|
[:client, :admin].each do |cc|
|
67
67
|
Acu::Monitor.args c: cc
|
@@ -14,6 +14,7 @@ RSpec.describe HomeController, type: :controller do
|
|
14
14
|
config.cache_expires_in = nil
|
15
15
|
config.cache_race_condition_ttl = nil
|
16
16
|
end
|
17
|
+
@controller = HomeController.new
|
17
18
|
}
|
18
19
|
|
19
20
|
def setup **kwargs
|
@@ -64,7 +65,7 @@ RSpec.describe HomeController, type: :controller do
|
|
64
65
|
expect(Acu::Rules.rules.length).to be 1
|
65
66
|
expect(Acu::Rules.rules[{}].length).to be 2
|
66
67
|
get :index
|
67
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="index".*as `:everyone, :client`/
|
68
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*namespace=nil.*controller="home".*action="index".*as `:everyone, :client`/
|
68
69
|
end
|
69
70
|
it "{ one of rules failed = AccessDenied }" do
|
70
71
|
Acu::Rules.define do
|
@@ -76,7 +77,7 @@ RSpec.describe HomeController, type: :controller do
|
|
76
77
|
deny :client
|
77
78
|
end
|
78
79
|
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
79
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*as `:everyone, :client`/
|
80
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="index".*as `:everyone, :client`/
|
80
81
|
|
81
82
|
Acu::Rules.define do
|
82
83
|
whois :client { false }
|
@@ -84,7 +85,7 @@ RSpec.describe HomeController, type: :controller do
|
|
84
85
|
deny :client
|
85
86
|
end
|
86
87
|
get :index
|
87
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="index".*as `:everyone`/
|
88
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*namespace=nil.*controller="home".*action="index".*as `:everyone`/
|
88
89
|
end
|
89
90
|
end
|
90
91
|
context "[levels]" do
|
@@ -104,7 +105,7 @@ RSpec.describe HomeController, type: :controller do
|
|
104
105
|
end
|
105
106
|
end
|
106
107
|
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
107
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*as `:everyone`/
|
108
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="index".*as `:everyone`/
|
108
109
|
Acu::Rules.define do
|
109
110
|
namespace do
|
110
111
|
allow :everyone
|
@@ -127,7 +128,7 @@ RSpec.describe HomeController, type: :controller do
|
|
127
128
|
deny :everyone
|
128
129
|
end
|
129
130
|
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
130
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*as `:everyone`/
|
131
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="index".*as `:everyone`/
|
131
132
|
end
|
132
133
|
it "[with only]" do
|
133
134
|
Acu::Rules.define do
|
@@ -137,7 +138,7 @@ RSpec.describe HomeController, type: :controller do
|
|
137
138
|
end
|
138
139
|
end
|
139
140
|
get :index
|
140
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="index".*as `:everyone`/
|
141
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*namespace=nil.*controller="home".*action="index".*as `:everyone`/
|
141
142
|
|
142
143
|
Acu::Rules.define do
|
143
144
|
whois :everyone { true }
|
@@ -151,7 +152,7 @@ RSpec.describe HomeController, type: :controller do
|
|
151
152
|
end
|
152
153
|
# by override
|
153
154
|
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
154
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*as `:everyone`/
|
155
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="index".*as `:everyone`/
|
155
156
|
end
|
156
157
|
it "[with except]" do
|
157
158
|
Acu::Rules.define do
|
@@ -171,7 +172,7 @@ RSpec.describe HomeController, type: :controller do
|
|
171
172
|
end
|
172
173
|
end
|
173
174
|
get :index
|
174
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="index".*as `:everyone`/
|
175
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*namespace=nil.*controller="home".*action="index".*as `:everyone`/
|
175
176
|
end
|
176
177
|
end
|
177
178
|
|
@@ -200,9 +201,9 @@ RSpec.describe HomeController, type: :controller do
|
|
200
201
|
end
|
201
202
|
# deny by default
|
202
203
|
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
203
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*\[autherized by :allow_by_default\]/
|
204
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="index".*\[autherized by :allow_by_default\]/
|
204
205
|
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
205
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="contact".*\[autherized by :allow_by_default\]/
|
206
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="contact".*\[autherized by :allow_by_default\]/
|
206
207
|
|
207
208
|
Acu::Rules.define do
|
208
209
|
controller :home, only: [:contact] do
|
@@ -212,7 +213,7 @@ RSpec.describe HomeController, type: :controller do
|
|
212
213
|
get :contact
|
213
214
|
# deny by default
|
214
215
|
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
215
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*\[autherized by :allow_by_default\]/
|
216
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="index".*\[autherized by :allow_by_default\]/
|
216
217
|
|
217
218
|
# the rules won't override with above, this will give us the needed flexibility for multi-dimentional rules
|
218
219
|
Acu::Rules.define do
|
@@ -256,10 +257,10 @@ RSpec.describe HomeController, type: :controller do
|
|
256
257
|
end
|
257
258
|
# we have rule for this
|
258
259
|
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
259
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*as `:everyone`/
|
260
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="index".*as `:everyone`/
|
260
261
|
# and this is by detailt
|
261
262
|
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
262
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="contact".*\[autherized by :allow_by_default\]/
|
263
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="contact".*\[autherized by :allow_by_default\]/
|
263
264
|
end
|
264
265
|
end
|
265
266
|
|
@@ -273,9 +274,9 @@ RSpec.describe HomeController, type: :controller do
|
|
273
274
|
end
|
274
275
|
end
|
275
276
|
get :index
|
276
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="index".*as `:everyone`/
|
277
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*namespace=nil.*controller="home".*action="index".*as `:everyone`/
|
277
278
|
get :contact
|
278
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="contact".*as `:everyone`/
|
279
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*namespace=nil.*controller="home".*action="contact".*as `:everyone`/
|
279
280
|
|
280
281
|
Acu::Rules.define do
|
281
282
|
namespace do
|
@@ -284,9 +285,9 @@ RSpec.describe HomeController, type: :controller do
|
|
284
285
|
end
|
285
286
|
end
|
286
287
|
get :index
|
287
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="index".*as `:everyone`/
|
288
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*namespace=nil.*controller="home".*action="index".*as `:everyone`/
|
288
289
|
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
289
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="contact".*as `:everyone`/
|
290
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="contact".*as `:everyone`/
|
290
291
|
|
291
292
|
end
|
292
293
|
|
@@ -298,7 +299,7 @@ RSpec.describe HomeController, type: :controller do
|
|
298
299
|
end
|
299
300
|
# deny by default
|
300
301
|
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
301
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*\[autherized by :allow_by_default\]/
|
302
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="index".*\[autherized by :allow_by_default\]/
|
302
303
|
|
303
304
|
Acu::Rules.define do
|
304
305
|
controller :home do
|
@@ -308,7 +309,7 @@ RSpec.describe HomeController, type: :controller do
|
|
308
309
|
get :contact
|
309
310
|
# deny by default
|
310
311
|
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
311
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*\[autherized by :allow_by_default\]/
|
312
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="index".*\[autherized by :allow_by_default\]/
|
312
313
|
|
313
314
|
Acu::Rules.define do
|
314
315
|
controller :home do
|
@@ -330,7 +331,7 @@ RSpec.describe HomeController, type: :controller do
|
|
330
331
|
end
|
331
332
|
# deny by default
|
332
333
|
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
333
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*\[autherized by :allow_by_default\]/
|
334
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="index".*\[autherized by :allow_by_default\]/
|
334
335
|
|
335
336
|
Acu::Rules.define do
|
336
337
|
namespace do
|
@@ -342,7 +343,7 @@ RSpec.describe HomeController, type: :controller do
|
|
342
343
|
get :contact
|
343
344
|
# deny by default
|
344
345
|
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
345
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*\[autherized by :allow_by_default\]/
|
346
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="index".*\[autherized by :allow_by_default\]/
|
346
347
|
|
347
348
|
Acu::Rules.define do
|
348
349
|
namespace do
|
@@ -367,9 +368,9 @@ RSpec.describe HomeController, type: :controller do
|
|
367
368
|
end
|
368
369
|
end
|
369
370
|
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
370
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*\[autherized by :allow_by_default\]/
|
371
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="index".*\[autherized by :allow_by_default\]/
|
371
372
|
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
372
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="contact".*\[autherized by :allow_by_default\]/
|
373
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="contact".*\[autherized by :allow_by_default\]/
|
373
374
|
end
|
374
375
|
it '[local-global]' do
|
375
376
|
Acu::Rules.define do
|
@@ -382,83 +383,137 @@ RSpec.describe HomeController, type: :controller do
|
|
382
383
|
end
|
383
384
|
end
|
384
385
|
get :contact
|
385
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="contact".*as `:everyone`/
|
386
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*namespace=nil.*controller="home".*action="contact".*as `:everyone`/
|
386
387
|
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
387
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*as `:everyone`/
|
388
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="index".*as `:everyone`/
|
388
389
|
end
|
389
390
|
end
|
391
|
+
end
|
392
|
+
context "[allow/deny]" do
|
393
|
+
it "[allow]" do
|
394
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
395
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="index".*\[autherized by :allow_by_default\]/
|
396
|
+
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
397
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="contact".*\[autherized by :allow_by_default\]/
|
390
398
|
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
399
|
+
Acu::Rules.define do
|
400
|
+
whois :everyone { true }
|
401
|
+
namespace do
|
402
|
+
controller :home do
|
403
|
+
allow :everyone, on: [:index, :contact]
|
404
|
+
end
|
405
|
+
end
|
406
|
+
end
|
407
|
+
get :index
|
408
|
+
get :contact
|
409
|
+
end
|
410
|
+
it "[deny]" do
|
411
|
+
Acu::Rules.define do
|
412
|
+
whois :everyone { true }
|
413
|
+
allow :everyone
|
414
|
+
end
|
415
|
+
get :index
|
416
|
+
get :contact
|
397
417
|
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
end
|
418
|
+
Acu::Rules.define do
|
419
|
+
whois :everyone { true }
|
420
|
+
namespace do
|
421
|
+
controller :home do
|
422
|
+
deny :everyone, on: [:index, :contact]
|
404
423
|
end
|
405
424
|
end
|
406
|
-
get :index
|
407
|
-
get :contact
|
408
425
|
end
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
426
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
427
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="index".*as `:everyone`/
|
428
|
+
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
429
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="contact".*as `:everyone`/
|
430
|
+
end
|
431
|
+
end
|
432
|
+
context "[bulk settings]" do
|
433
|
+
it "[allow/deny]" do
|
434
|
+
Acu::Rules.define do
|
435
|
+
whois :everyone { true }
|
436
|
+
whois :client { false }
|
437
|
+
namespace do
|
438
|
+
controller :home do
|
439
|
+
allow [:everyone, :client], on: [:index, :contact]
|
440
|
+
end
|
413
441
|
end
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
442
|
+
end
|
443
|
+
get :index
|
444
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*namespace=nil.*controller="home".*action="index".*as `:everyone`/
|
445
|
+
get :contact
|
446
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*namespace=nil.*controller="home".*action="contact".*as `:everyone`/
|
447
|
+
Acu::Rules.define { whois :client { true } }
|
448
|
+
get :index
|
449
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*namespace=nil.*controller="home".*action="index".*as `:everyone, :client`/
|
450
|
+
get :contact
|
451
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*namespace=nil.*controller="home".*action="contact".*as `:everyone, :client`/
|
452
|
+
Acu::Rules.define do
|
453
|
+
namespace do
|
454
|
+
controller :home do
|
455
|
+
action :index { deny [:everyone, :client] }
|
423
456
|
end
|
424
457
|
end
|
425
|
-
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
426
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*as `:everyone`/
|
427
|
-
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
428
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="contact".*as `:everyone`/
|
429
458
|
end
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
459
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
460
|
+
# the first rule that failed is going to mention
|
461
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="index".*as `:everyone, :client`/
|
462
|
+
get :contact
|
463
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*namespace=nil.*controller="home".*action="contact".*as `:everyone, :client`/
|
464
|
+
end
|
465
|
+
it "[namespace/controller]" do
|
466
|
+
Acu::Rules.define do
|
467
|
+
whois :everyone { true }
|
468
|
+
namespace nil, :admin do
|
469
|
+
allow :everyone
|
470
|
+
controller :home, :manage, only: [:index] do
|
471
|
+
deny :everyone
|
438
472
|
end
|
439
473
|
end
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
474
|
+
end
|
475
|
+
get :contact
|
476
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*namespace=nil.*controller="home".*action="contact".*as `:everyone`/
|
477
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
478
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="index".*as `:everyone`/
|
479
|
+
|
480
|
+
@controller = Admin::ManageController.new
|
481
|
+
|
482
|
+
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
483
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace="admin".*controller="manage".*action="index".*as `:everyone`/
|
484
|
+
|
485
|
+
[:show, :list, :delete, :add, :prove].each do |action|
|
486
|
+
get action
|
487
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*namespace="admin".*controller="manage".*action="#{action.to_s}".*as `:everyone`/
|
488
|
+
end
|
489
|
+
end
|
490
|
+
it "[action]" do
|
491
|
+
Acu::Rules.define do
|
492
|
+
whois :everyone { true }
|
493
|
+
namespace do
|
494
|
+
allow :everyone
|
495
|
+
end
|
496
|
+
end
|
497
|
+
[:index, :contact].each do |action|
|
498
|
+
get action
|
499
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*namespace=nil.*controller="home".*action="#{action.to_s}".*as `:everyone`/
|
500
|
+
end
|
501
|
+
|
502
|
+
Acu::Rules.define do
|
503
|
+
namespace do
|
504
|
+
controller :home do
|
505
|
+
action :index, :contact do
|
506
|
+
deny :everyone
|
453
507
|
end
|
454
508
|
end
|
455
509
|
end
|
456
|
-
expect {get :index}.to raise_error(Acu::Errors::AccessDenied)
|
457
|
-
# the first rule that failed is going to mention
|
458
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*action="index".*as `:everyone, :client`/
|
459
|
-
get :contact
|
460
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access GRANTED to.*action="contact".*as `:everyone, :client`/
|
461
510
|
end
|
511
|
+
|
512
|
+
[:index, :contact].each do |action|
|
513
|
+
expect {get action}.to raise_error(Acu::Errors::AccessDenied)
|
514
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /access DENIED to.*namespace=nil.*controller="home".*action="#{action.to_s}".*as `:everyone`/
|
515
|
+
end
|
516
|
+
|
462
517
|
end
|
463
518
|
end
|
464
519
|
end
|
@@ -512,9 +567,9 @@ RSpec.describe HomeController, type: :controller do
|
|
512
567
|
# it shouldn't use cache because we haven't told it yet
|
513
568
|
5.times do
|
514
569
|
get :index
|
515
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /\[-\] access GRANTED to.*action="index".*as `:everyone`/
|
570
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /\[-\] access GRANTED to.*namespace=nil.*controller="home".*action="index".*as `:everyone`/
|
516
571
|
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
517
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /\[x\] access DENIED to.*action="contact".*as `:everyone`/
|
572
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /\[x\] access DENIED to.*namespace=nil.*controller="home".*action="contact".*as `:everyone`/
|
518
573
|
end
|
519
574
|
|
520
575
|
setup use_cache: true
|
@@ -527,9 +582,9 @@ RSpec.describe HomeController, type: :controller do
|
|
527
582
|
# both request should be ruled by cache now!
|
528
583
|
5.times do
|
529
584
|
get :index
|
530
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /\[-\]\[c\] access GRANTED to.*action="index".*as `:everyone`/
|
585
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /\[-\]\[c\] access GRANTED to.*namespace=nil.*controller="home".*action="index".*as `:everyone`/
|
531
586
|
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
532
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /\[x\]\[c\] access DENIED to.*action="contact".*as `:everyone`/
|
587
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /\[x\]\[c\] access DENIED to.*namespace=nil.*controller="home".*action="contact".*as `:everyone`/
|
533
588
|
end
|
534
589
|
end
|
535
590
|
it '[maintains cache]' do
|
@@ -545,9 +600,9 @@ RSpec.describe HomeController, type: :controller do
|
|
545
600
|
end
|
546
601
|
5.times do
|
547
602
|
get :index
|
548
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /\[-\]\[c\] access GRANTED to.*action="index".*as `:everyone`/
|
603
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /\[-\]\[c\] access GRANTED to.*namespace=nil.*controller="home".*action="index".*as `:everyone`/
|
549
604
|
expect {get :contact}.to raise_error(Acu::Errors::AccessDenied)
|
550
|
-
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /\[x\]\[c\] access DENIED to.*action="contact".*as `:everyone`/
|
605
|
+
expect(`tail -n 1 #{Acu::Configs.get :audit_log_file}`).to match /\[x\]\[c\] access DENIED to.*namespace=nil.*controller="home".*action="contact".*as `:everyone`/
|
551
606
|
end
|
552
607
|
end
|
553
608
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-acu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dariush Hasanpour
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|