Skip to content

Commit

Permalink
fix: add 2 test cases from go to java (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
LMay001 authored Feb 23, 2024
1 parent 7be5584 commit 76e97d7
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/test/java/org/casbin/jcasbin/main/ModelUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,35 @@ public void testCommentModel(){
testEnforce(e, "bob", "data2", "write", true);
}

@Test
public void testDomainMatchModel(){
Enforcer e = new Enforcer("examples/rbac_with_domain_pattern_model.conf", "examples/rbac_with_domain_pattern_policy.csv");
e.addNamedDomainMatchingFunc("g", "keyMatch2", BuiltInFunctions::keyMatch2);

testDomainEnforce(e, "alice", "domain1", "data1", "read", true);
testDomainEnforce(e, "alice", "domain1", "data1", "write", true);
testDomainEnforce(e, "alice", "domain1", "data2", "read", false);
testDomainEnforce(e, "alice", "domain1", "data2", "write", false);
testDomainEnforce(e, "alice", "domain2", "data2", "read", true);
testDomainEnforce(e, "alice", "domain2", "data2", "write", true);
testDomainEnforce(e, "bob", "domain2", "data1", "read", false);
testDomainEnforce(e, "bob", "domain2", "data1", "write", false);
testDomainEnforce(e, "bob", "domain2", "data2", "read", true);
testDomainEnforce(e, "bob", "domain2", "data2", "write", true);
}

@Test
public void testAllMatchModel(){
Enforcer e = new Enforcer("examples/rbac_with_all_pattern_model.conf", "examples/rbac_with_all_pattern_policy.csv");
e.addNamedMatchingFunc("g", "keyMatch2", BuiltInFunctions::keyMatch2);
e.addNamedDomainMatchingFunc("g", "keyMatch2", BuiltInFunctions::keyMatch2);

testDomainEnforce(e, "alice", "domain1", "/book/1", "read", true);
testDomainEnforce(e, "alice", "domain1", "/book/1", "write", false);
testDomainEnforce(e, "alice", "domain2", "/book/1", "read", false);
testDomainEnforce(e, "alice", "domain2", "/book/1", "write", true);
}

@Test
public void testSubjectPriorityWithDomain() {
Enforcer e = new Enforcer("examples/subject_priority_model_with_domain.conf", "examples/subject_priority_policy_with_domain.csv");
Expand Down

0 comments on commit 76e97d7

Please sign in to comment.