diff --git a/casbin/internal_api.cpp b/casbin/internal_api.cpp index 94a3ef00..164f6f52 100644 --- a/casbin/internal_api.cpp +++ b/casbin/internal_api.cpp @@ -35,7 +35,7 @@ bool Enforcer::addPolicy(const std::string& sec, const std::string& p_type, cons return rule_added; if (sec == "g") { - PoliciesValues rules{rule}; + PoliciesValues rules({rule}); this->BuildIncrementalRoleLinks(policy_add, p_type, rules); } @@ -85,7 +85,7 @@ bool Enforcer::removePolicy(const std::string& sec, const std::string& p_type, c return rule_removed; if (sec == "g") { - PoliciesValues rules{rule}; + PoliciesValues rules({rule}); this->BuildIncrementalRoleLinks(policy_add, p_type, rules); } @@ -163,8 +163,8 @@ bool Enforcer::updatePolicy(const std::string& sec, const std::string& p_type, c return false; if (sec == "g") { - this->BuildIncrementalRoleLinks(policy_remove, p_type, {oldRule}); - this->BuildIncrementalRoleLinks(policy_add, p_type, {newRule}); + this->BuildIncrementalRoleLinks(policy_remove, p_type, PoliciesValues({oldRule})); + this->BuildIncrementalRoleLinks(policy_add, p_type, PoliciesValues({newRule})); } if (m_watcher && m_auto_notify_watcher) { if (IsInstanceOf(m_watcher.get())) { diff --git a/casbin/management_api.cpp b/casbin/management_api.cpp index 770db806..927280f8 100644 --- a/casbin/management_api.cpp +++ b/casbin/management_api.cpp @@ -241,7 +241,7 @@ bool Enforcer ::AddNamedGroupingPolicy(const std::string& p_type, const std::vec } if (m_auto_build_role_links) - this->BuildIncrementalRoleLinks(policy_add, p_type, {params}); + this->BuildIncrementalRoleLinks(policy_add, p_type, PoliciesValues({params})); // this->BuildRoleLinks(); return rule_added; diff --git a/casbin/selected_policies.cpp b/casbin/selected_policies.cpp index e412ecf5..c90afc8d 100644 --- a/casbin/selected_policies.cpp +++ b/casbin/selected_policies.cpp @@ -46,7 +46,7 @@ PoliciesValues& SelectedPolicies::operator*() { auto& policies = model->m["p"].assertion_map["p"]->policy; if (policies.is_hash()) { if (auto policy_it = policies.find(requestedPolicy()); policy_it != policies.end()) { - selected_policies = PoliciesValues{*policy_it}; + selected_policies = PoliciesValues({*policy_it}); } return selected_policies; } diff --git a/tests/benchmarks/enforcer_cached_b.cpp b/tests/benchmarks/enforcer_cached_b.cpp index bc314ef2..727e853d 100644 --- a/tests/benchmarks/enforcer_cached_b.cpp +++ b/tests/benchmarks/enforcer_cached_b.cpp @@ -21,7 +21,7 @@ #include "config_path.h" -static const PoliciesValues s_policy = {{"alice", "data1", "read"}, {"bob", "data2", "write"}}; +static const PoliciesValues s_policy({{"alice", "data1", "read"}, {"bob", "data2", "write"}}); static bool rawEnforce(const std::string& sub, const std::string& obj, const std::string& act) { for (const auto& rule : s_policy) { diff --git a/tests/benchmarks/model_b.cpp b/tests/benchmarks/model_b.cpp index 9170d3dc..0a2f285d 100644 --- a/tests/benchmarks/model_b.cpp +++ b/tests/benchmarks/model_b.cpp @@ -21,7 +21,7 @@ #include "config_path.h" -static const PoliciesValues s_policy = {{"alice", "data1", "read"}, {"bob", "data2", "write"}}; +static const PoliciesValues s_policy({{"alice", "data1", "read"}, {"bob", "data2", "write"}}); static bool rawEnforce(const std::string& sub, const std::string& obj, const std::string& act) { for (const auto& rule : s_policy) { diff --git a/tests/management_api_test.cpp b/tests/management_api_test.cpp index b98caa6c..21b69a2a 100644 --- a/tests/management_api_test.cpp +++ b/tests/management_api_test.cpp @@ -81,34 +81,34 @@ void TestHasGroupingPolicy(casbin::Enforcer& e, const std::vector& TEST(TestManagementAPI, TestGetPolicyAPI) { casbin::Enforcer e(rbac_model_path, rbac_policy_path); - TestGetPolicy(e, {{"alice", "data1", "read"}, {"bob", "data2", "write"}, {"data2_admin", "data2", "read"}, {"data2_admin", "data2", "write"}}); + TestGetPolicy(e, PoliciesValues({{"alice", "data1", "read"}, {"bob", "data2", "write"}, {"data2_admin", "data2", "read"}, {"data2_admin", "data2", "write"}})); - TestGetFilteredPolicy(e, 0, {{"alice", "data1", "read"}}, {"alice"}); - TestGetFilteredPolicy(e, 0, {{"bob", "data2", "write"}}, {"bob"}); - TestGetFilteredPolicy(e, 0, {{"data2_admin", "data2", "read"}, {"data2_admin", "data2", "write"}}, {"data2_admin"}); - TestGetFilteredPolicy(e, 1, {{"alice", "data1", "read"}}, {"data1"}); - TestGetFilteredPolicy(e, 1, {{"bob", "data2", "write"}, {"data2_admin", "data2", "read"}, {"data2_admin", "data2", "write"}}, {"data2"}); - TestGetFilteredPolicy(e, 2, {{"alice", "data1", "read"}, {"data2_admin", "data2", "read"}}, {"read"}); - TestGetFilteredPolicy(e, 2, {{"bob", "data2", "write"}, {"data2_admin", "data2", "write"}}, {"write"}); + TestGetFilteredPolicy(e, 0, PoliciesValues({{"alice", "data1", "read"}}), {"alice"}); + TestGetFilteredPolicy(e, 0, PoliciesValues({{"bob", "data2", "write"}}), {"bob"}); + TestGetFilteredPolicy(e, 0, PoliciesValues({{"data2_admin", "data2", "read"}, {"data2_admin", "data2", "write"}}), {"data2_admin"}); + TestGetFilteredPolicy(e, 1, PoliciesValues({{"alice", "data1", "read"}}), {"data1"}); + TestGetFilteredPolicy(e, 1, PoliciesValues({{"bob", "data2", "write"}, {"data2_admin", "data2", "read"}, {"data2_admin", "data2", "write"}}), {"data2"}); + TestGetFilteredPolicy(e, 2, PoliciesValues({{"alice", "data1", "read"}, {"data2_admin", "data2", "read"}}), {"read"}); + TestGetFilteredPolicy(e, 2, PoliciesValues({{"bob", "data2", "write"}, {"data2_admin", "data2", "write"}}), {"write"}); - TestGetFilteredPolicy(e, 0, {{"data2_admin", "data2", "read"}, {"data2_admin", "data2", "write"}}, {"data2_admin", "data2"}); + TestGetFilteredPolicy(e, 0, PoliciesValues({{"data2_admin", "data2", "read"}, {"data2_admin", "data2", "write"}}), {"data2_admin", "data2"}); // Note: "" (empty string) in fieldValues means matching all values. - TestGetFilteredPolicy(e, 0, {{"data2_admin", "data2", "read"}}, {"data2_admin", "", "read"}); - TestGetFilteredPolicy(e, 1, {{"bob", "data2", "write"}, {"data2_admin", "data2", "write"}}, {"data2", "write"}); + TestGetFilteredPolicy(e, 0, PoliciesValues({{"data2_admin", "data2", "read"}}), {"data2_admin", "", "read"}); + TestGetFilteredPolicy(e, 1, PoliciesValues({{"bob", "data2", "write"}, {"data2_admin", "data2", "write"}}), {"data2", "write"}); TestHasPolicy(e, {"alice", "data1", "read"}, true); TestHasPolicy(e, {"bob", "data2", "write"}, true); TestHasPolicy(e, {"alice", "data2", "read"}, false); TestHasPolicy(e, {"bob", "data3", "write"}, false); - TestGetGroupingPolicy(e, PoliciesValues{{"alice", "data2_admin"}}); + TestGetGroupingPolicy(e, PoliciesValues({{"alice", "data2_admin"}})); - TestGetFilteredGroupingPolicy(e, 0, {{"alice", "data2_admin"}}, {"alice"}); - TestGetFilteredGroupingPolicy(e, 0, {}, {"bob"}); - TestGetFilteredGroupingPolicy(e, 1, {}, {"data1_admin"}); - TestGetFilteredGroupingPolicy(e, 1, {{"alice", "data2_admin"}}, {"data2_admin"}); + TestGetFilteredGroupingPolicy(e, 0, PoliciesValues({{"alice", "data2_admin"}}), {"alice"}); + TestGetFilteredGroupingPolicy(e, 0, PoliciesValues({}), {"bob"}); + TestGetFilteredGroupingPolicy(e, 1, PoliciesValues({}), {"data1_admin"}); + TestGetFilteredGroupingPolicy(e, 1, PoliciesValues({{"alice", "data2_admin"}}), {"data2_admin"}); // Note: "" (empty string) in fieldValues means matching all values. - TestGetFilteredGroupingPolicy(e, 0, {{"alice", "data2_admin"}}, {"", "data2_admin"}); + TestGetFilteredGroupingPolicy(e, 0, PoliciesValues({{"alice", "data2_admin"}}), {"", "data2_admin"}); TestHasGroupingPolicy(e, {"alice", "data2_admin"}, true); TestHasGroupingPolicy(e, {"bob", "data2_admin"}, false); @@ -118,7 +118,7 @@ TEST(TestManagementAPI, TestModifyPolicyAPI) { std::shared_ptr adapter = std::make_shared(rbac_policy_path); casbin::Enforcer e(rbac_model_path, adapter); - TestGetPolicy(e, {{"alice", "data1", "read"}, {"bob", "data2", "write"}, {"data2_admin", "data2", "read"}, {"data2_admin", "data2", "write"}}); + TestGetPolicy(e, PoliciesValues({{"alice", "data1", "read"}, {"bob", "data2", "write"}, {"data2_admin", "data2", "read"}, {"data2_admin", "data2", "write"}})); e.RemovePolicy({"alice", "data1", "read"}); e.RemovePolicy({"bob", "data2", "write"}); @@ -126,23 +126,23 @@ TEST(TestManagementAPI, TestModifyPolicyAPI) { e.AddPolicy({"eve", "data3", "read"}); e.AddPolicy({"eve", "data3", "read"}); - PoliciesValues rules{ + PoliciesValues rules({ {"jack", "data4", "read"}, {"katy", "data4", "write"}, {"leyo", "data4", "read"}, {"ham", "data4", "write"}, - }; + }); e.AddPolicies(rules); e.AddPolicies(rules); - TestGetPolicy(e, {{"data2_admin", "data2", "read"}, + TestGetPolicy(e, PoliciesValues({{"data2_admin", "data2", "read"}, {"data2_admin", "data2", "write"}, {"eve", "data3", "read"}, {"jack", "data4", "read"}, {"katy", "data4", "write"}, {"leyo", "data4", "read"}, - {"ham", "data4", "write"}}); + {"ham", "data4", "write"}})); e.RemovePolicies(rules); e.RemovePolicies(rules); @@ -151,19 +151,19 @@ TEST(TestManagementAPI, TestModifyPolicyAPI) { e.RemoveNamedPolicy("p", named_policy); e.AddNamedPolicy("p", named_policy); - TestGetPolicy(e, {{"data2_admin", "data2", "read"}, {"data2_admin", "data2", "write"}, {"eve", "data3", "read"}}); + TestGetPolicy(e, PoliciesValues({{"data2_admin", "data2", "read"}, {"data2_admin", "data2", "write"}, {"eve", "data3", "read"}})); e.RemoveFilteredPolicy(1, {"data2"}); - TestGetPolicy(e, {{"eve", "data3", "read"}}); + TestGetPolicy(e, PoliciesValues({{"eve", "data3", "read"}})); e.UpdatePolicy({"eve", "data3", "read"}, {"eve", "data3", "write"}); - TestGetPolicy(e, {{"eve", "data3", "write"}}); + TestGetPolicy(e, PoliciesValues({{"eve", "data3", "write"}})); e.AddPolicies(rules); - e.UpdatePolicies({{"eve", "data3", "write"}, {"leyo", "data4", "read"}, {"katy", "data4", "write"}}, {{"eve", "data3", "read"}, {"leyo", "data4", "write"}, {"katy", "data1", "write"}}); + e.UpdatePolicies(PoliciesValues({{"eve", "data3", "write"}, {"leyo", "data4", "read"}, {"katy", "data4", "write"}}), PoliciesValues({{"eve", "data3", "read"}, {"leyo", "data4", "write"}, {"katy", "data1", "write"}})); - TestGetPolicy(e, {{"eve", "data3", "read"}, {"leyo", "data4", "write"}, {"katy", "data1", "write"}}); + TestGetPolicy(e, PoliciesValues({{"eve", "data3", "read"}, {"leyo", "data4", "write"}, {"katy", "data1", "write"}})); } TEST(TestManagementAPI, TestModifyGroupingPolicyAPI) { @@ -179,10 +179,10 @@ TEST(TestManagementAPI, TestModifyGroupingPolicyAPI) { e.AddGroupingPolicy({"bob", "data1_admin"}); e.AddGroupingPolicy({"eve", "data3_admin"}); - PoliciesValues grouping_rules{ + PoliciesValues grouping_rules({ {"ham", "data4_admin"}, {"jack", "data5_admin"}, - }; + }); e.AddGroupingPolicies(grouping_rules); ASSERT_TRUE(casbin::ArrayEquals({"data4_admin"}, e.GetRolesForUser("ham"))); diff --git a/tests/rbac_api_test.cpp b/tests/rbac_api_test.cpp index 72021583..9869aca4 100644 --- a/tests/rbac_api_test.cpp +++ b/tests/rbac_api_test.cpp @@ -115,8 +115,8 @@ TEST(TestRBACAPI, TestPermissionAPI) { ASSERT_FALSE(e.Enforce({"bob", "read"})); ASSERT_TRUE(e.Enforce({"bob", "write"})); - TestGetPermissions(e, "alice", {{"alice", "read"}}); - TestGetPermissions(e, "bob", {{"bob", "write"}}); + TestGetPermissions(e, "alice", PoliciesValues({{"alice", "read"}})); + TestGetPermissions(e, "bob", PoliciesValues({{"bob", "write"}})); ASSERT_TRUE(e.HasPermissionForUser("alice", {"read"})); ASSERT_FALSE(e.HasPermissionForUser("alice", {"write"})); @@ -156,8 +156,8 @@ TEST(TestRBACAPI, TestPermissionAPI) { TEST(TestRBACAPI, TestImplicitRoleAPI) { casbin::Enforcer e(rbac_model_path, rbac_with_hierarchy_policy_path); - TestGetPermissions(e, "alice", {{"alice", "data1", "read"}}); - TestGetPermissions(e, "bob", {{"bob", "data2", "write"}}); + TestGetPermissions(e, "alice", PoliciesValues({{"alice", "data1", "read"}})); + TestGetPermissions(e, "bob", PoliciesValues({{"bob", "data2", "write"}})); ASSERT_TRUE(casbin::ArrayEquals(std::vector{"admin", "data1_admin", "data2_admin"}, e.GetImplicitRolesForUser("alice"))); ASSERT_TRUE(casbin::ArrayEquals(std::vector{}, e.GetImplicitRolesForUser("bob"))); @@ -201,17 +201,17 @@ void TestGetImplicitPermissionsWithDomain(casbin::Enforcer& e, const std::string TEST(TestRBACAPI, TestImplicitPermissionAPI) { casbin::Enforcer e(rbac_model_path, rbac_with_hierarchy_policy_path); - TestGetPermissions(e, "alice", {{"alice", "data1", "read"}}); - TestGetPermissions(e, "bob", {{"bob", "data2", "write"}}); + TestGetPermissions(e, "alice", PoliciesValues({{"alice", "data1", "read"}})); + TestGetPermissions(e, "bob", PoliciesValues({{"bob", "data2", "write"}})); TestGetImplicitPermissions(e, "alice", - {{"alice", "data1", "read"}, {"data1_admin", "data1", "read"}, {"data1_admin", "data1", "write"}, {"data2_admin", "data2", "read"}, {"data2_admin", "data2", "write"}}); - TestGetImplicitPermissions(e, "bob", {{"bob", "data2", "write"}}); + PoliciesValues({{"alice", "data1", "read"}, {"data1_admin", "data1", "read"}, {"data1_admin", "data1", "write"}, {"data2_admin", "data2", "read"}, {"data2_admin", "data2", "write"}})); + TestGetImplicitPermissions(e, "bob", PoliciesValues({{"bob", "data2", "write"}})); } TEST(TestRBACAPI, TestImplicitPermissionAPIWithDomain) { casbin::Enforcer e(rbac_with_domains_model_path, rbac_with_hierarchy_with_domains_policy_path); - TestGetImplicitPermissionsWithDomain(e, "alice", "domain1", {{"alice", "domain1", "data2", "read"}, {"role:reader", "domain1", "data1", "read"}, {"role:writer", "domain1", "data1", "write"}}); + TestGetImplicitPermissionsWithDomain(e, "alice", "domain1", PoliciesValues({{"alice", "domain1", "data2", "read"}, {"role:reader", "domain1", "data1", "read"}, {"role:writer", "domain1", "data1", "write"}})); } TEST(TestRBACAPI, TestImplicitUserAPI) { @@ -225,7 +225,7 @@ TEST(TestRBACAPI, TestImplicitUserAPI) { e.ClearPolicy(); e.AddPolicy({"admin", "data1", "read"}); e.AddPolicy({"bob", "data1", "read"}); - e.AddPolicies({{"tom", "data1", "read"}, {"john", "data1", "read"}}); + e.AddPolicies(PoliciesValues({{"tom", "data1", "read"}, {"john", "data1", "read"}})); e.AddGroupingPolicy({"alice", "admin"}); ASSERT_TRUE(casbin::ArrayEquals({"alice", "bob", "tom", "john"}, e.GetImplicitUsersForPermission({"data1", "read"}))); diff --git a/tests/rbac_api_with_domains_test.cpp b/tests/rbac_api_with_domains_test.cpp index 35368e9e..7b0a54d1 100644 --- a/tests/rbac_api_with_domains_test.cpp +++ b/tests/rbac_api_with_domains_test.cpp @@ -174,12 +174,12 @@ TEST(TestRBACAPIWithDomains, TestPermissionAPIInDomain) { TestGetPermissionsInDomain(e, "alice", "domain1", {}); TestGetPermissionsInDomain(e, "bob", "domain1", {}); - TestGetPermissionsInDomain(e, "admin", "domain1", {{"admin", "domain1", "data1", "read"}, {"admin", "domain1", "data1", "write"}}); + TestGetPermissionsInDomain(e, "admin", "domain1", PoliciesValues({{"admin", "domain1", "data1", "read"}, {"admin", "domain1", "data1", "write"}})); TestGetPermissionsInDomain(e, "non_exist", "domain1", {}); TestGetPermissionsInDomain(e, "alice", "domain2", {}); TestGetPermissionsInDomain(e, "bob", "domain2", {}); - TestGetPermissionsInDomain(e, "admin", "domain2", {{"admin", "domain2", "data2", "read"}, {"admin", "domain2", "data2", "write"}}); + TestGetPermissionsInDomain(e, "admin", "domain2", PoliciesValues({{"admin", "domain2", "data2", "read"}, {"admin", "domain2", "data2", "write"}})); TestGetPermissionsInDomain(e, "non_exist", "domain2", {}); }