@@ -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+
736772test ( '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