Skip to content

Commit 76e97d7

Browse files
authored
fix: add 2 test cases from go to java (casbin#383)
1 parent 7be5584 commit 76e97d7

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/test/java/org/casbin/jcasbin/main/ModelUnitTest.java

+29
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,35 @@ public void testCommentModel(){
801801
testEnforce(e, "bob", "data2", "write", true);
802802
}
803803

804+
@Test
805+
public void testDomainMatchModel(){
806+
Enforcer e = new Enforcer("examples/rbac_with_domain_pattern_model.conf", "examples/rbac_with_domain_pattern_policy.csv");
807+
e.addNamedDomainMatchingFunc("g", "keyMatch2", BuiltInFunctions::keyMatch2);
808+
809+
testDomainEnforce(e, "alice", "domain1", "data1", "read", true);
810+
testDomainEnforce(e, "alice", "domain1", "data1", "write", true);
811+
testDomainEnforce(e, "alice", "domain1", "data2", "read", false);
812+
testDomainEnforce(e, "alice", "domain1", "data2", "write", false);
813+
testDomainEnforce(e, "alice", "domain2", "data2", "read", true);
814+
testDomainEnforce(e, "alice", "domain2", "data2", "write", true);
815+
testDomainEnforce(e, "bob", "domain2", "data1", "read", false);
816+
testDomainEnforce(e, "bob", "domain2", "data1", "write", false);
817+
testDomainEnforce(e, "bob", "domain2", "data2", "read", true);
818+
testDomainEnforce(e, "bob", "domain2", "data2", "write", true);
819+
}
820+
821+
@Test
822+
public void testAllMatchModel(){
823+
Enforcer e = new Enforcer("examples/rbac_with_all_pattern_model.conf", "examples/rbac_with_all_pattern_policy.csv");
824+
e.addNamedMatchingFunc("g", "keyMatch2", BuiltInFunctions::keyMatch2);
825+
e.addNamedDomainMatchingFunc("g", "keyMatch2", BuiltInFunctions::keyMatch2);
826+
827+
testDomainEnforce(e, "alice", "domain1", "/book/1", "read", true);
828+
testDomainEnforce(e, "alice", "domain1", "/book/1", "write", false);
829+
testDomainEnforce(e, "alice", "domain2", "/book/1", "read", false);
830+
testDomainEnforce(e, "alice", "domain2", "/book/1", "write", true);
831+
}
832+
804833
@Test
805834
public void testSubjectPriorityWithDomain() {
806835
Enforcer e = new Enforcer("examples/subject_priority_model_with_domain.conf", "examples/subject_priority_policy_with_domain.csv");

0 commit comments

Comments
 (0)