casbin-ruby 1.0.9 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/casbin-ruby/management_enforcer.rb +3 -3
- data/lib/casbin-ruby/version.rb +1 -1
- data/spec/casbin/enforcer_spec.rb +126 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88e68e3c8f15c55fbeba3bf37683124c9d2fb17a8d2dd408f3ed7d36a430fe95
|
4
|
+
data.tar.gz: 124e945552b694c89ef488a71d286d6171118281041c2823db896efb56ec0d83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10b12e4a479b2c3d4f7b70f33750d604292f15aaae6441968559a7d7ae195e4a5b291a3ce69fe553e7c976020218fa1b2dd2dcb86c58a9483868c30eef38842c
|
7
|
+
data.tar.gz: 225eaf757fbaab699f3a4c832020b9ca527e2b53e2f03c843631dadf81a1f199c0135447cc9a41bc96f509712011feca18970c02949fa037543e1a1c77aa08c1
|
@@ -102,7 +102,7 @@ module Casbin
|
|
102
102
|
if params.size == 1 && params[0].is_a?(Array)
|
103
103
|
model.has_policy('p', ptype, params[0])
|
104
104
|
else
|
105
|
-
model.has_policy('p', ptype,
|
105
|
+
model.has_policy('p', ptype, params)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
@@ -206,7 +206,7 @@ module Casbin
|
|
206
206
|
if params.size == 1 && params[0].is_a?(Array)
|
207
207
|
model.has_policy('g', ptype, params[0])
|
208
208
|
else
|
209
|
-
model.has_policy('g', ptype,
|
209
|
+
model.has_policy('g', ptype, params)
|
210
210
|
end
|
211
211
|
end
|
212
212
|
|
@@ -271,7 +271,7 @@ module Casbin
|
|
271
271
|
rule_added = if params.size == 1 && params[0].is_a?(Array)
|
272
272
|
parent_remove_policy('g', ptype, params[0])
|
273
273
|
else
|
274
|
-
parent_remove_policy('g', ptype,
|
274
|
+
parent_remove_policy('g', ptype, params)
|
275
275
|
end
|
276
276
|
|
277
277
|
auto_build_role_links ? build_role_links : rule_added
|
data/lib/casbin-ruby/version.rb
CHANGED
@@ -64,6 +64,42 @@ describe Casbin::Enforcer do
|
|
64
64
|
enf.remove_policy(%w[alice data3 read])
|
65
65
|
expect(enf.enforce('alice', 'data3', 'read')).to be_falsey
|
66
66
|
end
|
67
|
+
|
68
|
+
# rubocop:disable RSpec/RepeatedExample
|
69
|
+
it '#delete_permission' do
|
70
|
+
# TODO: Add support this method
|
71
|
+
# expect(enf.enforce('bob', 'data2', 'write')).to be_truthy
|
72
|
+
# expect(enf.enforce('data2_admin', 'data2', 'read')).to be_truthy
|
73
|
+
# expect(enf.enforce('data2_admin', 'data2', 'write')).to be_truthy
|
74
|
+
# expect(enf.delete_permission('data2')).to be_truthy
|
75
|
+
# expect(enf.enforce('bob', 'data2', 'write')).to be_falsey
|
76
|
+
# expect(enf.enforce('data2_admin', 'data2', 'read')).to be_falsey
|
77
|
+
# expect(enf.enforce('data2_admin', 'data2', 'write')).to be_falsey
|
78
|
+
end
|
79
|
+
|
80
|
+
it '#delete_permissions_for_user' do
|
81
|
+
# TODO: Add support this method
|
82
|
+
# expect(enf.enforce('alice', 'data1', 'read')).to be_truthy
|
83
|
+
# expect(enf.delete_permissions_for_user('alice')).to be_truthy
|
84
|
+
# expect(enf.enforce('alice', 'data1', 'read')).to be_falsey
|
85
|
+
end
|
86
|
+
|
87
|
+
it '#get_permissions_for_user' do
|
88
|
+
# TODO: Add support this method
|
89
|
+
# expect(enf.get_permissions_for_user('alice')).to match_array([%w[alice data1 read],
|
90
|
+
# %w[data2_admin data2 read],
|
91
|
+
# %w[data2_admin data2 write]])
|
92
|
+
end
|
93
|
+
# rubocop:enable RSpec/RepeatedExample
|
94
|
+
|
95
|
+
it '#has_permission_for_user' do
|
96
|
+
expect(enf.has_permission_for_user('alice', 'data1', 'read')).to be_truthy
|
97
|
+
expect(enf.has_permission_for_user('alice', 'data1', 'write')).to be_falsey
|
98
|
+
end
|
99
|
+
|
100
|
+
it '#get_implicit_permissions_for_user' do
|
101
|
+
expect(enf.get_implicit_permissions_for_user('alice')).to match_array([%w[alice data1 read]])
|
102
|
+
end
|
67
103
|
end
|
68
104
|
|
69
105
|
describe 'basic without spaces' do
|
@@ -188,6 +224,68 @@ describe Casbin::Enforcer do
|
|
188
224
|
expect(enf.enforce('alice', 'data4', 'read')).to be_truthy
|
189
225
|
expect(enf.enforce('bob', 'data4', 'read')).to be_falsey
|
190
226
|
end
|
227
|
+
|
228
|
+
it '#get_roles_for_user' do
|
229
|
+
expect(enf.get_roles_for_user('alice')).to match_array(['data2_admin'])
|
230
|
+
expect(enf.get_roles_for_user('bob')).to match_array([])
|
231
|
+
end
|
232
|
+
|
233
|
+
it '#get_users_for_role' do
|
234
|
+
expect(enf.get_users_for_role('data2_admin')).to match_array(['alice'])
|
235
|
+
expect(enf.get_users_for_role('data1_admin')).to match_array([])
|
236
|
+
end
|
237
|
+
|
238
|
+
it '#has_role_for_user' do
|
239
|
+
expect(enf.has_role_for_user('alice', 'data2_admin')).to be_truthy
|
240
|
+
expect(enf.has_role_for_user('bob', 'data2_admin')).to be_falsey
|
241
|
+
end
|
242
|
+
|
243
|
+
it '#add_role_for_user' do
|
244
|
+
expect(enf.has_role_for_user('alice', 'manager')).to be_falsey
|
245
|
+
expect(enf.add_role_for_user('alice', 'manager')).to be_truthy
|
246
|
+
expect(enf.has_role_for_user('alice', 'manager')).to be_truthy
|
247
|
+
end
|
248
|
+
|
249
|
+
it '#delete_role_for_user' do
|
250
|
+
expect(enf.has_role_for_user('alice', 'data2_admin')).to be_truthy
|
251
|
+
expect(enf.delete_role_for_user('alice', 'data2_admin')).to be_truthy
|
252
|
+
expect(enf.has_role_for_user('alice', 'data2_admin')).to be_falsey
|
253
|
+
end
|
254
|
+
|
255
|
+
it '#delete_roles_for_user' do
|
256
|
+
enf.add_grouping_policy('alice', 'base')
|
257
|
+
expect(enf.delete_roles_for_user('alice')).to be_truthy
|
258
|
+
expect(enf.get_roles_for_user('alice')).to match_array([])
|
259
|
+
end
|
260
|
+
|
261
|
+
it '#delete_user' do
|
262
|
+
expect(enf.enforce('alice', 'data1', 'read')).to be_truthy
|
263
|
+
expect(enf.has_role_for_user('alice', 'data2_admin')).to be_truthy
|
264
|
+
expect(enf.delete_user('alice')).to be_truthy
|
265
|
+
expect(enf.enforce('alice', 'data1', 'read')).to be_falsey
|
266
|
+
expect(enf.has_role_for_user('alice', 'data2_admin')).to be_falsey
|
267
|
+
end
|
268
|
+
|
269
|
+
it '#delete_role' do
|
270
|
+
expect(enf.enforce('data2_admin', 'data2', 'read')).to be_truthy
|
271
|
+
expect(enf.has_role_for_user('alice', 'data2_admin')).to be_truthy
|
272
|
+
expect(enf.delete_role('data2_admin')).to be_truthy
|
273
|
+
expect(enf.enforce('data2_admin', 'data2', 'read')).to be_falsey
|
274
|
+
expect(enf.has_role_for_user('alice', 'data2_admin')).to be_falsey
|
275
|
+
end
|
276
|
+
|
277
|
+
# rubocop:disable RSpec/RepeatedExample
|
278
|
+
it '#get_implicit_roles_for_user' do
|
279
|
+
# TODO: Add support this method
|
280
|
+
# enf.add_role_for_user('data2_admin', 'super_admin')
|
281
|
+
# expect(enf.get_implicit_roles_for_user('alice')).to match_array(%w[data2_admin super_admin])
|
282
|
+
end
|
283
|
+
|
284
|
+
it '#get_implicit_users_for_permission' do
|
285
|
+
# TODO: Add support this method
|
286
|
+
# expect(enf.get_implicit_users_for_permission('data2', 'write')).to match_array(%w[alice bob])
|
287
|
+
end
|
288
|
+
# rubocop:enable RSpec/RepeatedExample
|
191
289
|
end
|
192
290
|
|
193
291
|
describe 'rbac empty policy' do
|
@@ -227,6 +325,34 @@ describe Casbin::Enforcer do
|
|
227
325
|
expect(enf.enforce('bob', 'domain2', 'data2', 'read')).to be_truthy
|
228
326
|
expect(enf.enforce('bob', 'domain2', 'data2', 'write')).to be_truthy
|
229
327
|
end
|
328
|
+
|
329
|
+
it '#get_roles_for_user_in_domain' do
|
330
|
+
expect(enf.get_roles_for_user_in_domain('alice', 'domain1')).to match_array(%w[admin])
|
331
|
+
expect(enf.get_roles_for_user_in_domain('bob', 'domain2')).to match_array(%w[admin])
|
332
|
+
end
|
333
|
+
|
334
|
+
it '#get_users_for_role_in_domain' do
|
335
|
+
expect(enf.get_users_for_role_in_domain('admin', 'domain1')).to match_array(%w[alice])
|
336
|
+
expect(enf.get_users_for_role_in_domain('admin', 'domain2')).to match_array(%w[bob])
|
337
|
+
end
|
338
|
+
|
339
|
+
it '#delete_roles_for_user_in_domain' do
|
340
|
+
enf.delete_roles_for_user_in_domain('alice', 'admin', 'domain1')
|
341
|
+
expect(enf.get_roles_for_user_in_domain('alice', 'domain1')).to match_array(%w[])
|
342
|
+
end
|
343
|
+
|
344
|
+
it '#get_permissions_for_user_in_domain' do
|
345
|
+
expect(enf.get_permissions_for_user_in_domain('admin', 'domain1'))
|
346
|
+
.to match_array([%w[admin domain1 data1 read],
|
347
|
+
%w[admin domain1 data1 write],
|
348
|
+
%w[admin domain2 data2 read],
|
349
|
+
%w[admin domain2 data2 write]])
|
350
|
+
expect(enf.get_permissions_for_user_in_domain('admin', 'domain2'))
|
351
|
+
.to match_array([%w[admin domain1 data1 read],
|
352
|
+
%w[admin domain1 data1 write],
|
353
|
+
%w[admin domain2 data2 read],
|
354
|
+
%w[admin domain2 data2 write]])
|
355
|
+
end
|
230
356
|
end
|
231
357
|
|
232
358
|
describe 'rbac with not deny' do
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Kutyavin
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-09-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: keisan
|