casbin-ruby 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +242 -0
- data/lib/casbin-ruby.rb +11 -0
- data/lib/casbin-ruby/config/config.rb +115 -0
- data/lib/casbin-ruby/core_enforcer.rb +356 -0
- data/lib/casbin-ruby/effect/allow_and_deny_effector.rb +23 -0
- data/lib/casbin-ruby/effect/allow_override_effector.rb +23 -0
- data/lib/casbin-ruby/effect/default_effector.rb +37 -0
- data/lib/casbin-ruby/effect/deny_override_effector.rb +23 -0
- data/lib/casbin-ruby/effect/effector.rb +18 -0
- data/lib/casbin-ruby/effect/priority_effector.rb +25 -0
- data/lib/casbin-ruby/enforcer.rb +189 -0
- data/lib/casbin-ruby/internal_enforcer.rb +73 -0
- data/lib/casbin-ruby/management_enforcer.rb +297 -0
- data/lib/casbin-ruby/model/assertion.rb +33 -0
- data/lib/casbin-ruby/model/function_map.rb +30 -0
- data/lib/casbin-ruby/model/model.rb +80 -0
- data/lib/casbin-ruby/model/policy.rb +161 -0
- data/lib/casbin-ruby/persist/adapter.rb +39 -0
- data/lib/casbin-ruby/persist/adapters/file_adapter.rb +53 -0
- data/lib/casbin-ruby/persist/batch_adapter.rb +16 -0
- data/lib/casbin-ruby/persist/filtered_adapter.rb +17 -0
- data/lib/casbin-ruby/rbac/default_role_manager/role.rb +54 -0
- data/lib/casbin-ruby/rbac/default_role_manager/role_manager.rb +146 -0
- data/lib/casbin-ruby/rbac/role_manager.rb +22 -0
- data/lib/casbin-ruby/synced_enforcer.rb +39 -0
- data/lib/casbin-ruby/util.rb +80 -0
- data/lib/casbin-ruby/util/builtin_operators.rb +105 -0
- data/lib/casbin-ruby/util/evaluator.rb +27 -0
- data/lib/casbin-ruby/util/thread_lock.rb +19 -0
- data/lib/casbin-ruby/version.rb +5 -0
- data/spec/casbin/config/config_spec.rb +66 -0
- data/spec/casbin/core_enforcer_spec.rb +473 -0
- data/spec/casbin/enforcer_spec.rb +302 -0
- data/spec/casbin/model/function_map_spec.rb +28 -0
- data/spec/casbin/rbac/default_role_manager/role_manager_spec.rb +131 -0
- data/spec/casbin/rbac/default_role_manager/role_spec.rb +84 -0
- data/spec/casbin/util/builtin_operators_spec.rb +205 -0
- data/spec/casbin/util_spec.rb +98 -0
- data/spec/support/model_helper.rb +9 -0
- metadata +51 -3
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'casbin-ruby/rbac/default_role_manager/role'
|
4
|
+
|
5
|
+
describe Casbin::Rbac::DefaultRoleManager::Role do
|
6
|
+
let(:role) { described_class.new('test_role') }
|
7
|
+
let(:new_role) { described_class.new('new_role') }
|
8
|
+
|
9
|
+
describe '#add_role' do
|
10
|
+
it 'when new role' do
|
11
|
+
role.add_role(new_role)
|
12
|
+
expect(role.roles).to match_array([new_role])
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'when role exist' do
|
16
|
+
role.add_role(new_role)
|
17
|
+
role.add_role(new_role)
|
18
|
+
expect(role.roles).to match_array([new_role])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it '#delete_role' do
|
23
|
+
role.add_role(new_role)
|
24
|
+
expect(role.roles).not_to be_empty
|
25
|
+
|
26
|
+
role.delete_role(new_role)
|
27
|
+
expect(role.roles).to be_empty
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#has_role' do
|
31
|
+
it 'when root name' do
|
32
|
+
expect(role.has_role(role.name, 1)).to be_truthy
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'when hierarchy_level incorrect' do
|
36
|
+
role.add_role(new_role)
|
37
|
+
expect(role.has_role(new_role.name, 0)).to be_falsey
|
38
|
+
expect(role.has_role(new_role.name, -1)).to be_falsey
|
39
|
+
expect(role.has_role(new_role.name, 'text')).to be_falsey
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'when role deep' do
|
43
|
+
deep_role = described_class.new('depp_role')
|
44
|
+
new_role.add_role(deep_role)
|
45
|
+
role.add_role(new_role)
|
46
|
+
expect(role.has_role(new_role.name, 1)).to be_truthy
|
47
|
+
expect(role.has_role(deep_role.name, 1)).to be_falsey
|
48
|
+
expect(role.has_role(deep_role.name, 2)).to be_truthy
|
49
|
+
expect(role.has_role(deep_role.name, 5)).to be_truthy
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it '#get_roles' do
|
54
|
+
deep_role = described_class.new('depp_role')
|
55
|
+
new_role.add_role(deep_role)
|
56
|
+
role.add_role(new_role)
|
57
|
+
expect(role.get_roles).to match_array([new_role.name])
|
58
|
+
end
|
59
|
+
|
60
|
+
it '#has_direct_role' do
|
61
|
+
role.add_role(new_role)
|
62
|
+
expect(role.has_direct_role(new_role.name)).to be_truthy
|
63
|
+
expect(role.has_direct_role('not_exist')).to be_falsey
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#to_string' do
|
67
|
+
it 'when roles empty' do
|
68
|
+
expect(role.to_string).to be_nil
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'when one role' do
|
72
|
+
role.add_role(new_role)
|
73
|
+
expect(role.to_string).to eq "#{role.name} < #{new_role.name}"
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'when many role' do
|
77
|
+
first_role = described_class.new('first_role')
|
78
|
+
second_role = described_class.new('second_role')
|
79
|
+
role.add_role(first_role)
|
80
|
+
role.add_role(second_role)
|
81
|
+
expect(role.to_string).to eq "#{role.name} < (#{first_role.name}, #{second_role.name})"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,205 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'casbin-ruby/util/builtin_operators'
|
4
|
+
require 'casbin-ruby/rbac/default_role_manager/role_manager'
|
5
|
+
|
6
|
+
describe Casbin::Util::BuiltinOperators do
|
7
|
+
it '.key_match_func' do
|
8
|
+
expect(described_class.key_match_func('/foo', '/foo')).to be_truthy
|
9
|
+
expect(described_class.key_match_func('/foo', '/foo*')).to be_truthy
|
10
|
+
expect(described_class.key_match_func('/foo', '/foo/*')).to be_falsey
|
11
|
+
expect(described_class.key_match_func('/foo/bar', '/foo')).to be_falsey
|
12
|
+
expect(described_class.key_match_func('/foo/bar', '/foo*')).to be_truthy
|
13
|
+
expect(described_class.key_match_func('/foo/bar', '/foo/*')).to be_truthy
|
14
|
+
expect(described_class.key_match_func('/foobar', '/foo')).to be_falsey
|
15
|
+
expect(described_class.key_match_func('/foobar', '/foo*')).to be_truthy
|
16
|
+
expect(described_class.key_match_func('/foobar', '/foo/*')).to be_falsey
|
17
|
+
end
|
18
|
+
|
19
|
+
it '.key_match2_func' do
|
20
|
+
expect(described_class.key_match2_func('/foo', '/foo')).to be_truthy
|
21
|
+
expect(described_class.key_match2_func('/foo', '/foo*')).to be_truthy
|
22
|
+
expect(described_class.key_match2_func('/foo', '/foo/*')).to be_falsey
|
23
|
+
expect(described_class.key_match2_func('/foo/bar', '/foo')).to be_falsey
|
24
|
+
expect(described_class.key_match2_func('/foo/bar', '/foo*')).to be_falsey # different with key_match_func.
|
25
|
+
expect(described_class.key_match2_func('/foo/bar', '/foo/*')).to be_truthy
|
26
|
+
expect(described_class.key_match2_func('/foobar', '/foo')).to be_falsey
|
27
|
+
expect(described_class.key_match2_func('/foobar', '/foo*')).to be_falsey # different with key_match_func.
|
28
|
+
expect(described_class.key_match2_func('/foobar', '/foo/*')).to be_falsey
|
29
|
+
|
30
|
+
expect(described_class.key_match2_func('/', '/:resource')).to be_falsey
|
31
|
+
expect(described_class.key_match2_func('/resource1', '/:resource')).to be_truthy
|
32
|
+
expect(described_class.key_match2_func('/myid', '/:id/using/:resId')).to be_falsey
|
33
|
+
expect(described_class.key_match2_func('/myid/using/myresid', '/:id/using/:resId')).to be_truthy
|
34
|
+
|
35
|
+
expect(described_class.key_match2_func('/proxy/myid', '/proxy/:id/*')).to be_falsey
|
36
|
+
expect(described_class.key_match2_func('/proxy/myid/', '/proxy/:id/*')).to be_truthy
|
37
|
+
expect(described_class.key_match2_func('/proxy/myid/res', '/proxy/:id/*')).to be_truthy
|
38
|
+
expect(described_class.key_match2_func('/proxy/myid/res/res2', '/proxy/:id/*')).to be_truthy
|
39
|
+
expect(described_class.key_match2_func('/proxy/myid/res/res2/res3', '/proxy/:id/*')).to be_truthy
|
40
|
+
expect(described_class.key_match2_func('/proxy/', '/proxy/:id/*')).to be_falsey
|
41
|
+
|
42
|
+
expect(described_class.key_match2_func('/alice', '/:id')).to be_truthy
|
43
|
+
expect(described_class.key_match2_func('/alice/all', '/:id/all')).to be_truthy
|
44
|
+
expect(described_class.key_match2_func('/alice', '/:id/all')).to be_falsey
|
45
|
+
expect(described_class.key_match2_func('/alice/all', '/:id')).to be_falsey
|
46
|
+
|
47
|
+
expect(described_class.key_match2_func('/alice/all', '/:/all')).to be_falsey
|
48
|
+
end
|
49
|
+
|
50
|
+
it '.key_match3_func' do
|
51
|
+
# .key_match3_func is similar with .key_match2_func, except using "/proxy/{id}" instead of "/proxy/:id".
|
52
|
+
expect(described_class.key_match3_func('/foo', '/foo')).to be_truthy
|
53
|
+
expect(described_class.key_match3_func('/foo', '/foo*')).to be_truthy
|
54
|
+
expect(described_class.key_match3_func('/foo', '/foo/*')).to be_falsey
|
55
|
+
expect(described_class.key_match3_func('/foo/bar', '/foo')).to be_falsey
|
56
|
+
expect(described_class.key_match3_func('/foo/bar', '/foo*')).to be_falsey
|
57
|
+
expect(described_class.key_match3_func('/foo/bar', '/foo/*')).to be_truthy
|
58
|
+
expect(described_class.key_match3_func('/foobar', '/foo')).to be_falsey
|
59
|
+
expect(described_class.key_match3_func('/foobar', '/foo*')).to be_falsey
|
60
|
+
expect(described_class.key_match3_func('/foobar', '/foo/*')).to be_falsey
|
61
|
+
|
62
|
+
expect(described_class.key_match3_func('/', '/{resource}')).to be_falsey
|
63
|
+
expect(described_class.key_match3_func('/resource1', '/{resource}')).to be_truthy
|
64
|
+
expect(described_class.key_match3_func('/myid', '/{id}/using/{resId}')).to be_falsey
|
65
|
+
expect(described_class.key_match3_func('/myid/using/myresid', '/{id}/using/{resId}')).to be_truthy
|
66
|
+
|
67
|
+
expect(described_class.key_match3_func('/proxy/myid', '/proxy/{id}/*')).to be_falsey
|
68
|
+
expect(described_class.key_match3_func('/proxy/myid/', '/proxy/{id}/*')).to be_truthy
|
69
|
+
expect(described_class.key_match3_func('/proxy/myid/res', '/proxy/{id}/*')).to be_truthy
|
70
|
+
expect(described_class.key_match3_func('/proxy/myid/res/res2', '/proxy/{id}/*')).to be_truthy
|
71
|
+
expect(described_class.key_match3_func('/proxy/myid/res/res2/res3', '/proxy/{id}/*')).to be_truthy
|
72
|
+
expect(described_class.key_match3_func('/proxy/', '/proxy/{id}/*')).to be_falsey
|
73
|
+
|
74
|
+
expect(described_class.key_match3_func('/myid/using/myresid', '/{id/using/{resId}')).to be_falsey
|
75
|
+
end
|
76
|
+
|
77
|
+
it '.regex_match_func' do
|
78
|
+
expect(described_class.regex_match_func('/topic/create', '/topic/create')).to be_truthy
|
79
|
+
expect(described_class.regex_match_func('/topic/create/123', '/topic/create')).to be_truthy
|
80
|
+
expect(described_class.regex_match_func('/topic/delete', '/topic/create')).to be_falsey
|
81
|
+
expect(described_class.regex_match_func('/topic/edit', '/topic/edit/[0-9]+')).to be_falsey
|
82
|
+
expect(described_class.regex_match_func('/topic/edit/123', '/topic/edit/[0-9]+')).to be_truthy
|
83
|
+
expect(described_class.regex_match_func('/topic/edit/abc', '/topic/edit/[0-9]+')).to be_falsey
|
84
|
+
expect(described_class.regex_match_func('/foo/delete/123', '/topic/delete/[0-9]+')).to be_falsey
|
85
|
+
expect(described_class.regex_match_func('/topic/delete/0', '/topic/delete/[0-9]+')).to be_truthy
|
86
|
+
expect(described_class.regex_match_func('/topic/edit/123s', '/topic/delete/[0-9]+')).to be_falsey
|
87
|
+
end
|
88
|
+
|
89
|
+
it '.glob_match_func' do
|
90
|
+
expect(described_class.glob_match_func('/foo', '/foo')).to be_truthy
|
91
|
+
expect(described_class.glob_match_func('/foo', '/foo*')).to be_truthy
|
92
|
+
expect(described_class.glob_match_func('/foo', '/foo/*')).to be_falsey
|
93
|
+
expect(described_class.glob_match_func('/foo/bar', '/foo')).to be_falsey
|
94
|
+
expect(described_class.glob_match_func('/foo/bar', '/foo*')).to be_falsey
|
95
|
+
expect(described_class.glob_match_func('/foo/bar', '/foo/*')).to be_truthy
|
96
|
+
expect(described_class.glob_match_func('/foobar', '/foo')).to be_falsey
|
97
|
+
expect(described_class.glob_match_func('/foobar', '/foo*')).to be_truthy
|
98
|
+
expect(described_class.glob_match_func('/foobar', '/foo/*')).to be_falsey
|
99
|
+
|
100
|
+
expect(described_class.glob_match_func('/foo', '*/foo')).to be_truthy
|
101
|
+
expect(described_class.glob_match_func('/foo', '*/foo*')).to be_truthy
|
102
|
+
expect(described_class.glob_match_func('/foo', '*/foo/*')).to be_falsey
|
103
|
+
expect(described_class.glob_match_func('/foo/bar', '*/foo')).to be_falsey
|
104
|
+
expect(described_class.glob_match_func('/foo/bar', '*/foo*')).to be_falsey
|
105
|
+
expect(described_class.glob_match_func('/foo/bar', '*/foo/*')).to be_truthy
|
106
|
+
expect(described_class.glob_match_func('/foobar', '*/foo')).to be_falsey
|
107
|
+
expect(described_class.glob_match_func('/foobar', '*/foo*')).to be_truthy
|
108
|
+
expect(described_class.glob_match_func('/foobar', '*/foo/*')).to be_falsey
|
109
|
+
|
110
|
+
expect(described_class.glob_match_func('/prefix/foo', '*/foo')).to be_falsey
|
111
|
+
expect(described_class.glob_match_func('/prefix/foo', '*/foo*')).to be_falsey
|
112
|
+
expect(described_class.glob_match_func('/prefix/foo', '*/foo/*')).to be_falsey
|
113
|
+
expect(described_class.glob_match_func('/prefix/foo/bar', '*/foo')).to be_falsey
|
114
|
+
expect(described_class.glob_match_func('/prefix/foo/bar', '*/foo*')).to be_falsey
|
115
|
+
expect(described_class.glob_match_func('/prefix/foo/bar', '*/foo/*')).to be_falsey
|
116
|
+
expect(described_class.glob_match_func('/prefix/foobar', '*/foo')).to be_falsey
|
117
|
+
expect(described_class.glob_match_func('/prefix/foobar', '*/foo*')).to be_falsey
|
118
|
+
expect(described_class.glob_match_func('/prefix/foobar', '*/foo/*')).to be_falsey
|
119
|
+
|
120
|
+
expect(described_class.glob_match_func('/prefix/subprefix/foo', '*/foo')).to be_falsey
|
121
|
+
expect(described_class.glob_match_func('/prefix/subprefix/foo', '*/foo*')).to be_falsey
|
122
|
+
expect(described_class.glob_match_func('/prefix/subprefix/foo', '*/foo/*')).to be_falsey
|
123
|
+
expect(described_class.glob_match_func('/prefix/subprefix/foo/bar', '*/foo')).to be_falsey
|
124
|
+
expect(described_class.glob_match_func('/prefix/subprefix/foo/bar', '*/foo*')).to be_falsey
|
125
|
+
expect(described_class.glob_match_func('/prefix/subprefix/foo/bar', '*/foo/*')).to be_falsey
|
126
|
+
expect(described_class.glob_match_func('/prefix/subprefix/foobar', '*/foo')).to be_falsey
|
127
|
+
expect(described_class.glob_match_func('/prefix/subprefix/foobar', '*/foo*')).to be_falsey
|
128
|
+
expect(described_class.glob_match_func('/prefix/subprefix/foobar', '*/foo/*')).to be_falsey
|
129
|
+
end
|
130
|
+
|
131
|
+
it '.ip_match_func' do
|
132
|
+
expect(described_class.ip_match_func('192.168.2.123', '192.168.2.0/24')).to be_truthy
|
133
|
+
expect(described_class.ip_match_func('192.168.2.123', '192.168.3.0/24')).to be_falsey
|
134
|
+
expect(described_class.ip_match_func('192.168.2.123', '192.168.2.0/16')).to be_truthy
|
135
|
+
expect(described_class.ip_match_func('192.168.2.123', '192.168.2.123')).to be_truthy
|
136
|
+
expect(described_class.ip_match_func('192.168.2.123', '192.168.2.123/32')).to be_truthy
|
137
|
+
expect(described_class.ip_match_func('10.0.0.11', '10.0.0.0/8')).to be_truthy
|
138
|
+
expect(described_class.ip_match_func('11.0.0.123', '10.0.0.0/8')).to be_falsey
|
139
|
+
end
|
140
|
+
|
141
|
+
describe '#generate_g_function' do
|
142
|
+
subject { described_class.generate_g_function(rm).call name1, name2 }
|
143
|
+
|
144
|
+
let(:name1) { 'abc' }
|
145
|
+
let(:name2) { 'cde' }
|
146
|
+
|
147
|
+
context 'without role manager' do
|
148
|
+
let(:rm) { nil }
|
149
|
+
|
150
|
+
context 'when same names' do
|
151
|
+
let(:name2) { 'abc' }
|
152
|
+
|
153
|
+
it { is_expected.to be_truthy }
|
154
|
+
end
|
155
|
+
|
156
|
+
context 'when different names' do
|
157
|
+
it { is_expected.to be_falsey }
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'with role manager' do
|
162
|
+
let(:rm) { Casbin::Rbac::DefaultRoleManager::RoleManager.new(1) }
|
163
|
+
|
164
|
+
context 'without domain' do
|
165
|
+
before do
|
166
|
+
expect(rm).to(receive(:has_link).with(name1, name2).and_return(has_link))
|
167
|
+
end
|
168
|
+
|
169
|
+
context 'when has link' do
|
170
|
+
let(:has_link) { true }
|
171
|
+
|
172
|
+
it { is_expected.to be_truthy }
|
173
|
+
end
|
174
|
+
|
175
|
+
context 'when has not link' do
|
176
|
+
let(:has_link) { false }
|
177
|
+
|
178
|
+
it { is_expected.to be_falsey }
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context 'with domain' do
|
183
|
+
subject { described_class.generate_g_function(rm).call name1, name2, domain }
|
184
|
+
|
185
|
+
let(:domain) { 'domain' }
|
186
|
+
|
187
|
+
before do
|
188
|
+
expect(rm).to(receive(:has_link).with(name1, name2, domain).and_return(has_link))
|
189
|
+
end
|
190
|
+
|
191
|
+
context 'when has link' do
|
192
|
+
let(:has_link) { true }
|
193
|
+
|
194
|
+
it { is_expected.to be_truthy }
|
195
|
+
end
|
196
|
+
|
197
|
+
context 'when has not link' do
|
198
|
+
let(:has_link) { false }
|
199
|
+
|
200
|
+
it { is_expected.to be_falsey }
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'casbin-ruby/util'
|
4
|
+
|
5
|
+
describe Casbin::Util do
|
6
|
+
it '.remove_comments' do
|
7
|
+
expect(described_class.remove_comments('r.act == p.act # comments')).to eq 'r.act == p.act'
|
8
|
+
expect(described_class.remove_comments('r.act == p.act#comments')).to eq 'r.act == p.act'
|
9
|
+
expect(described_class.remove_comments('r.act == p.act###')).to eq 'r.act == p.act'
|
10
|
+
expect(described_class.remove_comments('### comments')).to eq ''
|
11
|
+
expect(described_class.remove_comments('r.act == p.act')).to eq 'r.act == p.act'
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#escape_assertion' do
|
15
|
+
subject { described_class.escape_assertion(value) }
|
16
|
+
|
17
|
+
context 'without attributes' do
|
18
|
+
let(:value) { 'm = r.sub == p.sub && r.obj == p.obj && r.act == p.act' }
|
19
|
+
|
20
|
+
it { is_expected.to eq 'm = r_sub == p_sub && r_obj == p_obj && r_act == p_act' }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'with attributes' do
|
24
|
+
context 'with latin identifier' do
|
25
|
+
let(:value) { 'm = r.sub.Chief == r.obj.Owner' }
|
26
|
+
|
27
|
+
it { is_expected.to eq "m = r_sub['Chief'] == r_obj['Owner']" }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with underscore' do
|
31
|
+
let(:value) { 'm = r.sub == r.obj._Owner' }
|
32
|
+
|
33
|
+
it { is_expected.to eq "m = r_sub == r_obj['_Owner']" }
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'with unicode identifier' do
|
37
|
+
let(:value) { 'm = r.sub == r.obj.Идентификатор1' }
|
38
|
+
|
39
|
+
it { is_expected.to eq "m = r_sub == r_obj['Идентификатор1']" }
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'with nested identifiers' do
|
43
|
+
let(:value) { 'm = r.sub == r.obj.Owner.Position' }
|
44
|
+
|
45
|
+
it { is_expected.to eq "m = r_sub == r_obj['Owner']['Position']" }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it '.array_remove_duplicates' do
|
51
|
+
expect(described_class.array_remove_duplicates(%w[data data1 data2 data1 data2 data3]))
|
52
|
+
.to match_array(%w[data data1 data2 data3])
|
53
|
+
end
|
54
|
+
|
55
|
+
it '.array_to_string' do
|
56
|
+
expect(described_class.array_to_string(%w[data data1 data2 data3])).to eq 'data, data1, data2, data3'
|
57
|
+
end
|
58
|
+
|
59
|
+
it '.params_to_string' do
|
60
|
+
expect(described_class.params_to_string('data', 'data1', 'data2', 'data3')).to eq 'data, data1, data2, data3'
|
61
|
+
end
|
62
|
+
|
63
|
+
it '.has_eval' do
|
64
|
+
expect(described_class.has_eval('eval() && a && b && c')).to be_truthy
|
65
|
+
expect(described_class.has_eval('a && b && eval(c)')).to be_truthy
|
66
|
+
expect(described_class.has_eval('eval) && a && b && c')).to be_falsey
|
67
|
+
expect(described_class.has_eval('eval)( && a && b && c')).to be_falsey
|
68
|
+
expect(described_class.has_eval('eval(c * (a + b)) && a && b && c')).to be_truthy
|
69
|
+
expect(described_class.has_eval('xeval() && a && b && c')).to be_falsey
|
70
|
+
expect(described_class.has_eval('eval(a) && eval(b) && a && b && c')).to be_truthy
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#replace_eval' do
|
74
|
+
subject { described_class.replace_eval(expr, rules) }
|
75
|
+
|
76
|
+
context 'with eval in the beginning' do
|
77
|
+
let(:expr) { 'eval(a) && eval(b) && c' }
|
78
|
+
let(:rules) { { 'a' => '1 + 1', 'b' => 'a + 1' } }
|
79
|
+
|
80
|
+
it { is_expected.to eq '(1 + 1) && (a + 1) && c' }
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'with eval in the end' do
|
84
|
+
let(:expr) { 'a && eval(b) && eval(c)' }
|
85
|
+
let(:rules) { { 'b' => '1', 'c' => '(a + 1) + c' } }
|
86
|
+
|
87
|
+
it { is_expected.to eq 'a && (1) && ((a + 1) + c)' }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it '.get_eval_value' do
|
92
|
+
expect(described_class.get_eval_value('eval(a) && a && b && c')).to match_array(['a'])
|
93
|
+
expect(described_class.get_eval_value('a && eval(a) && b && c')).to match_array(['a'])
|
94
|
+
expect(described_class.get_eval_value('eval(a) && eval(b) && a && b && c')).to match_array(%w[a b])
|
95
|
+
expect(described_class.get_eval_value('eval(p.sub_rule) || p.obj == r.obj && eval(p.domain_rule)'))
|
96
|
+
.to match_array(%w[p.sub_rule p.domain_rule])
|
97
|
+
end
|
98
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: casbin-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Kutyavin
|
@@ -75,7 +75,46 @@ email:
|
|
75
75
|
executables: []
|
76
76
|
extensions: []
|
77
77
|
extra_rdoc_files: []
|
78
|
-
files:
|
78
|
+
files:
|
79
|
+
- README.md
|
80
|
+
- lib/casbin-ruby.rb
|
81
|
+
- lib/casbin-ruby/config/config.rb
|
82
|
+
- lib/casbin-ruby/core_enforcer.rb
|
83
|
+
- lib/casbin-ruby/effect/allow_and_deny_effector.rb
|
84
|
+
- lib/casbin-ruby/effect/allow_override_effector.rb
|
85
|
+
- lib/casbin-ruby/effect/default_effector.rb
|
86
|
+
- lib/casbin-ruby/effect/deny_override_effector.rb
|
87
|
+
- lib/casbin-ruby/effect/effector.rb
|
88
|
+
- lib/casbin-ruby/effect/priority_effector.rb
|
89
|
+
- lib/casbin-ruby/enforcer.rb
|
90
|
+
- lib/casbin-ruby/internal_enforcer.rb
|
91
|
+
- lib/casbin-ruby/management_enforcer.rb
|
92
|
+
- lib/casbin-ruby/model/assertion.rb
|
93
|
+
- lib/casbin-ruby/model/function_map.rb
|
94
|
+
- lib/casbin-ruby/model/model.rb
|
95
|
+
- lib/casbin-ruby/model/policy.rb
|
96
|
+
- lib/casbin-ruby/persist/adapter.rb
|
97
|
+
- lib/casbin-ruby/persist/adapters/file_adapter.rb
|
98
|
+
- lib/casbin-ruby/persist/batch_adapter.rb
|
99
|
+
- lib/casbin-ruby/persist/filtered_adapter.rb
|
100
|
+
- lib/casbin-ruby/rbac/default_role_manager/role.rb
|
101
|
+
- lib/casbin-ruby/rbac/default_role_manager/role_manager.rb
|
102
|
+
- lib/casbin-ruby/rbac/role_manager.rb
|
103
|
+
- lib/casbin-ruby/synced_enforcer.rb
|
104
|
+
- lib/casbin-ruby/util.rb
|
105
|
+
- lib/casbin-ruby/util/builtin_operators.rb
|
106
|
+
- lib/casbin-ruby/util/evaluator.rb
|
107
|
+
- lib/casbin-ruby/util/thread_lock.rb
|
108
|
+
- lib/casbin-ruby/version.rb
|
109
|
+
- spec/casbin/config/config_spec.rb
|
110
|
+
- spec/casbin/core_enforcer_spec.rb
|
111
|
+
- spec/casbin/enforcer_spec.rb
|
112
|
+
- spec/casbin/model/function_map_spec.rb
|
113
|
+
- spec/casbin/rbac/default_role_manager/role_manager_spec.rb
|
114
|
+
- spec/casbin/rbac/default_role_manager/role_spec.rb
|
115
|
+
- spec/casbin/util/builtin_operators_spec.rb
|
116
|
+
- spec/casbin/util_spec.rb
|
117
|
+
- spec/support/model_helper.rb
|
79
118
|
homepage: https://github.com/evrone/casbin-ruby
|
80
119
|
licenses:
|
81
120
|
- Apache License 2.0
|
@@ -100,4 +139,13 @@ rubygems_version: 2.7.6.3
|
|
100
139
|
signing_key:
|
101
140
|
specification_version: 4
|
102
141
|
summary: Casbin in Ruby
|
103
|
-
test_files:
|
142
|
+
test_files:
|
143
|
+
- spec/casbin/core_enforcer_spec.rb
|
144
|
+
- spec/casbin/enforcer_spec.rb
|
145
|
+
- spec/casbin/model/function_map_spec.rb
|
146
|
+
- spec/casbin/rbac/default_role_manager/role_spec.rb
|
147
|
+
- spec/casbin/rbac/default_role_manager/role_manager_spec.rb
|
148
|
+
- spec/casbin/config/config_spec.rb
|
149
|
+
- spec/casbin/util/builtin_operators_spec.rb
|
150
|
+
- spec/casbin/util_spec.rb
|
151
|
+
- spec/support/model_helper.rb
|