Skip to content

Commit

Permalink
feat: [basic_model_speedup] CI fixes for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyChashchegorov committed Mar 14, 2024
1 parent 3f2d7c4 commit 758b4ee
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 49 deletions.
8 changes: 4 additions & 4 deletions casbin/internal_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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<WatcherUpdatable>(m_watcher.get())) {
Expand Down
2 changes: 1 addition & 1 deletion casbin/management_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion casbin/selected_policies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/benchmarks/enforcer_cached_b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion tests/benchmarks/model_b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
58 changes: 29 additions & 29 deletions tests/management_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,34 +81,34 @@ void TestHasGroupingPolicy(casbin::Enforcer& e, const std::vector<std::string>&
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);
Expand All @@ -118,31 +118,31 @@ TEST(TestManagementAPI, TestModifyPolicyAPI) {
std::shared_ptr<casbin::Adapter> adapter = std::make_shared<casbin::BatchFileAdapter>(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"});
e.RemovePolicy({"alice", "data1", "read"});
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);
Expand All @@ -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) {
Expand All @@ -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")));
Expand Down
20 changes: 10 additions & 10 deletions tests/rbac_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"}));
Expand Down Expand Up @@ -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<std::string>{"admin", "data1_admin", "data2_admin"}, e.GetImplicitRolesForUser("alice")));
ASSERT_TRUE(casbin::ArrayEquals(std::vector<std::string>{}, e.GetImplicitRolesForUser("bob")));
Expand Down Expand Up @@ -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) {
Expand All @@ -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"})));
Expand Down
4 changes: 2 additions & 2 deletions tests/rbac_api_with_domains_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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", {});
}

Expand Down

0 comments on commit 758b4ee

Please sign in to comment.