From 76e97d74d88553eb71a7a1a3d76116d628e411f1 Mon Sep 17 00:00:00 2001 From: LMay <67900553+LMay001@users.noreply.github.com> Date: Fri, 23 Feb 2024 19:58:41 +0800 Subject: [PATCH] fix: add 2 test cases from go to java (#383) --- .../casbin/jcasbin/main/ModelUnitTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/test/java/org/casbin/jcasbin/main/ModelUnitTest.java b/src/test/java/org/casbin/jcasbin/main/ModelUnitTest.java index ecca77b3..9ccc50f6 100644 --- a/src/test/java/org/casbin/jcasbin/main/ModelUnitTest.java +++ b/src/test/java/org/casbin/jcasbin/main/ModelUnitTest.java @@ -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");