Skip to content

Commit 5d80e1f

Browse files
committed
bug: added tests case for problematic issue with subjectPriority and loadPolicy
1 parent 7aedfcf commit 5d80e1f

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
p, group, data1, read, deny
2+
p, user, data1, read, allow
3+
g, user, group

test/enforcer.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,42 @@ test('TestSubjectPriority', async () => {
733733
testEnforceEx(e, 'alice', 'data1', 'read', [true, ['alice', 'data1', 'read', 'allow']]);
734734
});
735735

736+
test('TestSubjectPriority with CSV converted to addPolicy/addGroupingPolicy', async () => {
737+
const e = await newEnforcer('examples/subject_priority_model.conf');
738+
739+
await e.addPolicy('root', 'data1', 'read', 'deny');
740+
await e.addPolicy('admin', 'data1', 'read', 'deny');
741+
await e.addPolicy('editor', 'data1', 'read', 'deny');
742+
await e.addPolicy('subscriber', 'data1', 'read', 'deny');
743+
await e.addPolicy('jane', 'data1', 'read', 'allow');
744+
await e.addPolicy('alice', 'data1', 'read', 'allow');
745+
746+
await e.addGroupingPolicy('admin', 'root');
747+
await e.addGroupingPolicy('editor', 'admin');
748+
await e.addGroupingPolicy('subscriber', 'admin');
749+
await e.addGroupingPolicy('jane', 'editor');
750+
await e.addGroupingPolicy('alice', 'subscriber');
751+
752+
testEnforceEx(e, 'jane', 'data1', 'read', [true, ['jane', 'data1', 'read', 'allow']]);
753+
testEnforceEx(e, 'alice', 'data1', 'read', [true, ['alice', 'data1', 'read', 'allow']]);
754+
});
755+
756+
test('TestSubjectPriority simpler with CSV', async () => {
757+
const e = await newEnforcer('examples/subject_priority_model.conf', 'examples/subject_priority_policy_simple.csv');
758+
759+
testEnforceEx(e, 'user', 'data1', 'read', [true, ['user', 'data1', 'read', 'allow']]);
760+
});
761+
762+
test('TestSubjectPriority simpler with addPolicy', async () => {
763+
const e = await newEnforcer('examples/subject_priority_model.conf');
764+
765+
await e.addPolicy('group', 'data1', 'read', 'deny');
766+
await e.addPolicy('user', 'data1', 'read', 'allow');
767+
await e.addGroupingPolicy('user', 'group');
768+
769+
testEnforceEx(e, 'user', 'data1', 'read', [true, ['user', 'data1', 'read', 'allow']]);
770+
});
771+
736772
test('TestSubjectPriorityWithDomain', async () => {
737773
const e = await newEnforcer('examples/subject_priority_model_with_domain.conf', 'examples/subject_priority_policy_with_domain.csv');
738774
testEnforceEx(e, 'alice', 'data1', 'write', [true, ['alice', 'data1', 'domain1', 'write', 'allow']], 'domain1');

0 commit comments

Comments
 (0)