Ejemplo n.º 1
0
    def test_casbin_js_get_permission_for_user(self):
        e = casbin.SyncedEnforcer(
            get_examples("rbac_model.conf"),
            get_examples("rbac_with_hierarchy_policy.csv"),
        )
        received = json.loads(casbin.casbin_js_get_permission_for_user(e, "alice"))
        with open(get_examples("rbac_model.conf"), "r") as file:
            expected_model_str = file.read()
        self.assertEqual(received["m"], re.sub("\n+", "\n", expected_model_str))

        with open(get_examples("rbac_with_hierarchy_policy.csv"), "r") as file:
            expected_policies_str = file.read()
        expected_policy_item = re.split(r",|\n", expected_policies_str)
        i = 0
        for s_arr in received["p"]:
            for s in s_arr:
                self.assertEqual(s.strip(), expected_policy_item[i].strip())
                i += 1
Ejemplo n.º 2
0
 def get_enforcer(self, model=None, adapter=None, enable_log=False):
     return casbin.SyncedEnforcer(
         model,
         adapter,
         enable_log,
     )
Ejemplo n.º 3
0
 def get_enforcer(self, model=None, adapter=None):
     return casbin.SyncedEnforcer(
         model,
         adapter,
     )