Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: *matcher result should be boolean or number* for KeyGet2 (#347) * fix: *matcher result should be boolean or number* for KeyGet2 * fix: updated error hint * fix: basic keyGet2 test * fix: basic_keyget2_policy.csv (cherry picked from commit 0257078) Signed-off-by: Zxilly <zhouxinyu1001@gmail.com> * feat(rbac): add `getUsersForRoleInDomain` & `getRolesForUserInDomain` (#351) Documentation indicates that there is existance of `getUsersForRoleInDomain` and `getRolesForUserInDomain` api, but it does not yet exists. This commit implements these functions, by aliasing them to existing rbac function that had already cater for domain apis, to increase and improve dev experience. re #304 (cherry picked from commit 4896ca2) * feat: #357 Support keyMatch5 (#359) (cherry picked from commit e6a6d8a) * test: use new utils Signed-off-by: Zxilly <zhouxinyu1001@gmail.com> Co-authored-by: Shivansh Yadav <yadavshivansh@gmail.com> Co-authored-by: Chen Wen Kang <23054115+cwkang1998@users.noreply.github.com> Co-authored-by: ZCDC_Ren <kuanglong0312@sina.com>
- Loading branch information
1 parent
ba9c988
commit 645ee4d
Showing
8 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[request_definition] | ||
r = sub, obj | ||
|
||
[policy_definition] | ||
p = sub, obj | ||
|
||
[policy_effect] | ||
e = some(where (p.eft == allow)) | ||
|
||
[matchers] | ||
m = keyGet2(r.obj, p.obj, 'id') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
p, alice, /data/:id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2019 The Casbin Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { newEnforcer } from '../src'; | ||
import { getEnforcerWithPath } from './utils'; | ||
|
||
test('test getRolesForUserInDomain', async () => { | ||
const e = await getEnforcerWithPath('examples/rbac_with_domains_model.conf', 'examples/rbac_with_domains_policy.csv'); | ||
expect(await e.getRolesForUserInDomain('alice', 'domain1')).toEqual(['admin']); | ||
expect(await e.getRolesForUserInDomain('alice', 'domain2')).toEqual([]); | ||
expect(await e.getRolesForUserInDomain('bob', 'domain1')).toEqual([]); | ||
expect(await e.getRolesForUserInDomain('bob', 'domain2')).toEqual(['admin']); | ||
}); | ||
|
||
test('test getUsersForRoleInDomain', async () => { | ||
const e = await getEnforcerWithPath('examples/rbac_with_domains_model.conf', 'examples/rbac_with_domains_policy.csv'); | ||
expect(await e.getUsersForRoleInDomain('admin', 'domain1')).toEqual(['alice']); | ||
expect(await e.getUsersForRoleInDomain('admin', 'domain2')).toEqual(['bob']); | ||
expect(await e.getUsersForRoleInDomain('superadmin', 'domain1')).toEqual([]); | ||
expect(await e.getUsersForRoleInDomain('superadmin', 'domain2')).toEqual([]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters