@@ -85,8 +85,8 @@ public void TestEnforceSubjectPriority()
85
85
TestModelFixture . SubjectPriorityModelText ,
86
86
TestModelFixture . SubjectPriorityPolicyText ) ) ;
87
87
88
- TestEnforce ( e , "jane" , "data1" , "read" , true ) ;
89
- TestEnforce ( e , "alice" , "data1" , "read" , true ) ;
88
+ Assert . True ( e . Enforce ( "jane" , "data1" , "read" ) ) ;
89
+ Assert . True ( e . Enforce ( "alice" , "data1" , "read" ) ) ;
90
90
}
91
91
92
92
[ Fact ]
@@ -96,16 +96,8 @@ public void TestEnforceSubjectPriorityWithDomain()
96
96
Path . Combine ( "Examples" , "subject_priority_model_with_domain.conf" ) ,
97
97
Path . Combine ( "Examples" , "subject_priority_policy_with_domain.csv" ) ) ;
98
98
99
- Assert . True ( e . Enforce (
100
- "alice" ,
101
- "data1" ,
102
- "domain1" ,
103
- "write" ) ) ;
104
- Assert . True ( e . Enforce (
105
- "bob" ,
106
- "data2" ,
107
- "domain2" ,
108
- "write" ) ) ;
99
+ Assert . True ( e . Enforce ( "alice" , "data1" , "domain1" , "write" ) ) ;
100
+ Assert . True ( e . Enforce ( "bob" , "data2" , "domain2" , "write" ) ) ;
109
101
}
110
102
111
103
#region In memory model
@@ -701,6 +693,28 @@ public async Task TestInitEmptyAsync()
701
693
await TestEnforceAsync ( e , "alice" , "/alice_data/resource1" , "GET" , true ) ;
702
694
}
703
695
696
+ [ Fact ]
697
+ public void TestInitEmptyByInputStream ( )
698
+ {
699
+ Enforcer e = new ( ) ;
700
+
701
+ IModel m = DefaultModel . Create ( ) ;
702
+ m . AddDef ( "r" , "r" , "sub, obj, act" ) ;
703
+ m . AddDef ( "p" , "p" , "sub, obj, act" ) ;
704
+ m . AddDef ( "e" , "e" , "some(where (p.eft == allow))" ) ;
705
+ m . AddDef ( "m" , "m" , "r.sub == p.sub && keyMatch(r.obj, p.obj) && regexMatch(r.act, p.act)" ) ;
706
+
707
+ using ( FileStream fs = new ( "Examples/keymatch_policy.csv" , FileMode . Open , FileAccess . Read ,
708
+ FileShare . ReadWrite ) )
709
+ {
710
+ FileAdapter a = new ( fs ) ;
711
+ e . SetModel ( m ) ;
712
+ e . SetAdapter ( a ) ;
713
+ e . LoadPolicy ( ) ;
714
+
715
+ TestEnforce ( e , "alice" , "/alice_data/resource1" , "GET" , true ) ;
716
+ }
717
+ }
704
718
705
719
[ Fact ]
706
720
public async Task TestInitEmptyByInputStreamAsync ( )
@@ -1001,48 +1015,6 @@ public async Task TestGetAndSetAdapterInMemAsync()
1001
1015
await TestEnforceAsync ( e , "alice" , "data1" , "write" , true ) ;
1002
1016
}
1003
1017
1004
- [ Fact ]
1005
- public void TestSetAdapterFromFile ( )
1006
- {
1007
- Enforcer e = new ( "Examples/basic_model.conf" ) ;
1008
-
1009
- TestEnforce ( e , "alice" , "data1" , "read" , false ) ;
1010
-
1011
- FileAdapter a = new ( "Examples/basic_policy.csv" ) ;
1012
- e . SetAdapter ( a ) ;
1013
- e . LoadPolicy ( ) ;
1014
- TestEnforce ( e , "alice" , "data1" , "read" , true ) ;
1015
- e . ClearPolicy ( ) ;
1016
- e . ClearCache ( ) ;
1017
-
1018
- var policyBytes = Encoding . UTF8 . GetBytes ( File . ReadAllText ( TestModelFixture . GetTestFile ( "basic_policy.csv" ) ) ) ;
1019
- StreamAdapter b = new ( new MemoryStream ( policyBytes , false ) , new MemoryStream ( policyBytes , true ) ) ;
1020
- e . SetAdapter ( b ) ;
1021
- e . LoadPolicy ( ) ;
1022
- TestEnforce ( e , "alice" , "data1" , "read" , true ) ;
1023
- }
1024
-
1025
- [ Fact ]
1026
- public async Task TestSetAdapterFromFileAsync ( )
1027
- {
1028
- Enforcer e = new ( "Examples/basic_model.conf" ) ;
1029
-
1030
- await TestEnforceAsync ( e , "alice" , "data1" , "read" , false ) ;
1031
-
1032
- FileAdapter a = new ( "Examples/basic_policy_for_async_adapter_test.csv" ) ;
1033
- e . SetAdapter ( a ) ;
1034
- await e . LoadPolicyAsync ( ) ;
1035
- await TestEnforceAsync ( e , "alice" , "data1" , "read" , true ) ;
1036
- e . ClearPolicy ( ) ;
1037
- e . ClearCache ( ) ;
1038
-
1039
- var policyBytes = Encoding . UTF8 . GetBytes ( File . ReadAllText ( TestModelFixture . GetTestFile ( "basic_policy.csv" ) ) ) ;
1040
- StreamAdapter b = new ( new MemoryStream ( policyBytes , false ) , new MemoryStream ( policyBytes , true ) ) ;
1041
- e . SetAdapter ( b ) ;
1042
- await e . LoadPolicyAsync ( ) ;
1043
- await TestEnforceAsync ( e , "alice" , "data1" , "read" , true ) ;
1044
- }
1045
-
1046
1018
[ Fact ]
1047
1019
public void TestEnforceExApi ( )
1048
1020
{
0 commit comments