Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] priority_policy_explicit does not respect priority #248

Closed
paul4156 opened this issue Mar 17, 2021 · 3 comments · Fixed by #250
Closed

[Bug] priority_policy_explicit does not respect priority #248

paul4156 opened this issue Mar 17, 2021 · 3 comments · Fixed by #250
Assignees
Labels
enhancement New feature or request

Comments

@paul4156
Copy link

Describe the bug
priority_policy_explicit is still positional, not respecting priority.

To Reproduce
Steps to reproduce the behavior:

  1. Use nodejs
  2. Use example files for explicit priority: examples/priority_model_explicit.conf and examples/priority_policy_explicit.csv
  3. Run script:
const { newEnforcer } = require('casbin');

newEnforcer(
  `${__dirname}/priority_model_explicit.conf`,
  `${__dirname}/priority_policy_explicit.csv`
)
  .then(enforcer => enforcer.enforce('bob', 'data2', 'read'))
  .then(console.log);
  1. Got true
  2. Swap line 1-4 and line 7-9 in priority_policy_explicit.csv:
p, 1, alice, data1, write, allow
p, 1, alice, data1, read, allow
p, 1, bob, data2, read, deny

p, 10, data1_deny_group, data1, read, deny
p, 10, data1_deny_group, data1, write, deny
p, 10, data2_allow_group, data2, read, allow
p, 10, data2_allow_group, data2, write, allow

g, bob, data2_allow_group
g, alice, data1_deny_group

  1. Run the script again
  2. Got false

Expected behavior
The priority based policy should work regardless of the order of adding policies and be consistent to true ("allow"), due to bob is in data2_allow_group which has a higher priority.

Screenshots

image

Desktop (please complete the following information):

  • OS: macOS Big Sur 11.2.3
  • Browser: nodejs
  • Version: node v12.21.0

Additional context
None

@hsluoyz hsluoyz transferred this issue from casbin/casbin Mar 17, 2021
@hsluoyz hsluoyz added the bug Something isn't working label Mar 17, 2021
@hsluoyz
Copy link
Member

hsluoyz commented Mar 17, 2021

@Zxilly

@Zxilly
Copy link
Contributor

Zxilly commented Mar 17, 2021

working on this

@Zxilly
Copy link
Contributor

Zxilly commented Mar 17, 2021

Currently pycasbin didn't supoort explicit priority enforce. I'll implement it.

@Zxilly Zxilly self-assigned this Mar 17, 2021
@hsluoyz hsluoyz added enhancement New feature or request and removed bug Something isn't working labels Mar 17, 2021
hsluoyz pushed a commit that referenced this issue Mar 23, 2021
* test: add unit tests for explicit priority model

Signed-off-by: Zxilly <zhouxinyu1001@gmail.com>

* feat: add priority_policy_explicit support

#248
Signed-off-by: Zxilly <zhouxinyu1001@gmail.com>

* perf: enhance batch action performance

Signed-off-by: Zxilly <zhouxinyu1001@gmail.com>

* style: small fix

Signed-off-by: Zxilly <zhouxinyu1001@gmail.com>

* fix: change function argument

Signed-off-by: Zxilly <zhouxinyu1001@gmail.com>

* fix: fix incorrect implement

Signed-off-by: Zxilly <zhouxinyu1001@gmail.com>

* refactor: refactor priority index

Signed-off-by: Zxilly <zhouxinyu1001@gmail.com>

* feat: add update priority unittest

Signed-off-by: Zxilly <zhouxinyu1001@gmail.com>

* perf: priority performance enhanced

Signed-off-by: Zxilly <zhouxinyu1001@gmail.com>

* refactor: refactor updatePolicy()

throw error when new rule and old rule didn't have same priority

Signed-off-by: Zxilly <zhouxinyu1001@gmail.com>
@hsluoyz hsluoyz removed this from Node-Casbin Easy Tasks in Casbin Easy Tasks for Beginners/Student Applicants Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants