Skip to content

Commit

Permalink
feat: fix the test case
Browse files Browse the repository at this point in the history
  • Loading branch information
tx2002 committed Dec 2, 2024
1 parent d3113c8 commit 55d1efa
Showing 1 changed file with 9 additions and 30 deletions.
39 changes: 9 additions & 30 deletions src/test/java/org/casbin/jcasbin/main/AbacAPIUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package org.casbin.jcasbin.main;

import org.casbin.jcasbin.util.Util;
import org.junit.Test;

import java.util.ArrayList;
Expand All @@ -24,7 +23,6 @@

import static org.casbin.jcasbin.main.TestUtil.testDomainEnforce;
import static org.casbin.jcasbin.main.TestUtil.testEnforce;
import static org.junit.Assert.*;

public class AbacAPIUnitTest {
@Test
Expand All @@ -46,6 +44,15 @@ public void testEval() {
alice.setAge(60);
testEnforce(e, alice, "/data2", "read", false);
testEnforce(e, alice, "/data2", "write", false);

List<String> rule = new ArrayList<>();
rule.add("\"r.sub.name == 'alice,green'\"");
rule.add("data1");
rule.add("read");
e.addPolicy(rule);

TestEvalRule aliceGreen = new TestEvalRule("alice,green", 18);
testEnforce(e, aliceGreen, "data1", "read", true);
}

@Test
Expand All @@ -61,34 +68,6 @@ public void testEvalWithDomain() {
testDomainEnforce(e, "bob", "domain2", "data2", "read", true);
}

@Test
public void testEvalWithComma() {
Enforcer e = new Enforcer("examples/abac_rule_model.conf");
List<String> rule = new ArrayList<>();
rule.add("\"let test=seq.set('alice','bob');include(test,r.sub.name)\"");
rule.add("data1");
rule.add("read");
List<String> newRule = new ArrayList<>();
newRule.add("\"let test=seq.set('bob');include(test,r.sub.name)\"");
newRule.add("data1");
newRule.add("read");
assertTrue(e.addPolicy(rule));
assertFalse(e.addPolicy(rule));

Map<String, Object> sub = new HashMap<>();
sub.put("name", "alice");

testEnforce(e, sub, "data1", "read", true);

assertTrue(e.updatePolicy("p", "p", rule, newRule));
testEnforce(e, sub, "data1", "read", false);
sub.put("name", "bob");
testEnforce(e, sub, "data1", "read", true);

assertTrue(e.removePolicy(newRule));
testEnforce(e, sub, "data1", "read", false);
}

@Test
public void testABACMapRequest() {
Enforcer e = new Enforcer("examples/abac_rule_map_model.conf");
Expand Down

0 comments on commit 55d1efa

Please sign in to comment.