Skip to content

Commit

Permalink
feat: port the test case of add_function() example to pycasbin (#217)
Browse files Browse the repository at this point in the history
Signed-off-by: sallycaoyu <[email protected]>
  • Loading branch information
sallycaoyu authored Nov 20, 2021
1 parent 01e8b2c commit c19d065
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/test_enforcer.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,23 @@ def test_enforce_key_match2(self):
self.assertTrue(e.enforce("alice", "/alice_data/resource", "GET"))
self.assertTrue(e.enforce("alice", "/alice_data2/123/using/456", "GET"))

def test_enforce_key_match_custom_model(self):
e = self.get_enforcer(
get_examples('keymatch_custom_model.conf'), get_examples('keymatch2_policy.csv')
)

def custom_function(key1, key2):
if key1 == "/alice_data2/myid/using/res_id" and key2 == "/alice_data/:resource":
return True
elif key1 == "/alice_data2/myid/using/res_id" and key2 == "/alice_data2/:id/using/:resId":
return True
return False

e.add_function("keyMatchCustom", custom_function)

self.assertFalse(e.enforce("alice", "/alice_data2/myid", "GET"))
self.assertTrue(e.enforce("alice", "/alice_data2/myid/using/res_id", "GET"))

def test_enforce_priority(self):
e = self.get_enforcer(
get_examples("priority_model.conf"), get_examples("priority_policy.csv")
Expand Down

0 comments on commit c19d065

Please sign in to comment.