Skip to content

Commit

Permalink
debug of failed test at CI
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyChashchegorov committed Mar 17, 2024
1 parent ef2e38e commit 0e9ccb0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
33 changes: 28 additions & 5 deletions casbin/model/policy_collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "casbin/model/policy_collection.hpp"


#include <iostream>
PoliciesValues::PoliciesValues(PoliciesVector&& base_collection)
: opt_base_vector(base_collection), opt_base_hashset({}) {}

Expand All @@ -28,6 +28,7 @@ PoliciesValues::PoliciesValues(const std::initializer_list<PolicyValues>& list)

PoliciesValues::PoliciesValues(size_t capacity)
: opt_base_vector(PoliciesVector()), opt_base_hashset({}) {
std::cerr<<"DEBUG_:1" << std::endl;
opt_base_vector->reserve(capacity);
}

Expand All @@ -42,14 +43,18 @@ PoliciesValues PoliciesValues::createWithHashset(const std::initializer_list<Pol
}

size_t PoliciesValues::size() const {
std::cerr<<"DEBUG_:2" << std::endl;
if (opt_base_vector.has_value())
return opt_base_vector->size();
std::cerr<<"DEBUG_:2_1" << std::endl;
return opt_base_hashset->size();
}

bool PoliciesValues::empty() const {
std::cerr<<"DEBUG_:3" << std::endl;
if(opt_base_vector.has_value())
return opt_base_vector->empty();
std::cerr<<"DEBUG_:3_1" << std::endl;
return opt_base_hashset->empty();
}

Expand All @@ -58,10 +63,13 @@ bool PoliciesValues::is_hash() const {
}

void PoliciesValues::emplace(const PolicyValues& element) {
if (opt_base_vector.has_value())
if (opt_base_vector.has_value()) {
std::cerr<<"DEBUG_:4_1" << std::endl;
opt_base_vector->push_back(element);
else
} else {
std::cerr<<"DEBUG_:4_2" << std::endl;
opt_base_hashset->emplace(element);
}
}

PoliciesValues::iterator::iterator(const PoliciesVector::iterator& base_iterator_)
Expand Down Expand Up @@ -89,34 +97,45 @@ bool PoliciesValues::iterator::operator!=(const PoliciesValues::iterator& other)
}

PoliciesValues::iterator PoliciesValues::begin() {
std::cerr<<"DEBUG_:5" << std::endl;
if (opt_base_vector.has_value())
return iterator(opt_base_vector->begin());
std::cerr<<"DEBUG_:5_1" << std::endl;
return iterator(opt_base_hashset->begin());
}

PoliciesValues::iterator PoliciesValues::end() {
std::cerr<<"DEBUG_:6" << std::endl;
if (opt_base_vector.has_value())
return iterator(opt_base_vector->end());
std::cerr<<"DEBUG_:6_1" << std::endl;
return iterator(opt_base_hashset->end());
}

PoliciesValues::iterator PoliciesValues::find(const PolicyValues& values) {
std::cerr<<"DEBUG_:7" << std::endl;
if (opt_base_vector.has_value())
return iterator(std::find(opt_base_vector->begin(), opt_base_vector->end(), values));
std::cerr<<"DEBUG_:7_1" << std::endl;
return iterator(opt_base_hashset->find(values));
}

void PoliciesValues::clear() {
std::cerr<<"DEBUG_:8" << std::endl;
if (opt_base_vector.has_value())
opt_base_vector->clear();
std::cerr<<"DEBUG_:8_1" << std::endl;
opt_base_hashset->clear();
}

void PoliciesValues::erase(const iterator& it) {
if (opt_base_vector.has_value())
if (opt_base_vector.has_value()) {
std::cerr<<"DEBUG_:9_1" << std::endl;
opt_base_vector->erase(it.opt_vector_iterator);
else
} else {
std::cerr<<"DEBUG_:9_2" << std::endl;
opt_base_hashset->erase(it.opt_hashset_iterator);
}
}

PoliciesValues::const_iterator::const_iterator(const PoliciesVector::const_iterator& base_iterator_)
Expand Down Expand Up @@ -148,13 +167,17 @@ bool PoliciesValues::const_iterator::operator!=(const const_iterator& other) con


PoliciesValues::const_iterator PoliciesValues::begin() const {
std::cerr<<"DEBUG_:10" << std::endl;
if (opt_base_vector.has_value())
return const_iterator(opt_base_vector->cbegin());
std::cerr<<"DEBUG_:10_1" << std::endl;
return const_iterator(opt_base_hashset->cbegin());
}

PoliciesValues::const_iterator PoliciesValues::end() const {
std::cerr<<"DEBUG_:11" << std::endl;
if (opt_base_vector.has_value())
return const_iterator(opt_base_vector->cend());
std::cerr<<"DEBUG_:11_1" << std::endl;
return const_iterator(opt_base_hashset->cend());
}
15 changes: 14 additions & 1 deletion tests/rbac_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,34 @@ TEST(TestRBACAPI, TestImplicitPermissionAPIWithDomain) {
TestGetImplicitPermissionsWithDomain(e, "alice", "domain1", PoliciesValues({{"alice", "domain1", "data2", "read"}, {"role:reader", "domain1", "data1", "read"}, {"role:writer", "domain1", "data1", "write"}}));
}

#include <iostream>

TEST(TestRBACAPI, TestImplicitUserAPI) {
std::cerr << "DEBUG:1" << std::endl;
casbin::Enforcer e(rbac_model_path, rbac_with_hierarchy_policy_path);

std::cerr << "DEBUG:2" << std::endl;
ASSERT_TRUE(casbin::ArrayEquals({"alice"}, e.GetImplicitUsersForPermission({"data1", "read"})));
std::cerr << "DEBUG:3" << std::endl;
ASSERT_TRUE(casbin::ArrayEquals({"alice"}, e.GetImplicitUsersForPermission({"data1", "write"})));
std::cerr << "DEBUG:4" << std::endl;
ASSERT_TRUE(casbin::ArrayEquals({"alice"}, e.GetImplicitUsersForPermission({"data2", "read"})));
std::cerr << "DEBUG:5" << std::endl;
ASSERT_TRUE(casbin::ArrayEquals({"alice", "bob"}, e.GetImplicitUsersForPermission({"data2", "write"})));
std::cerr << "DEBUG:6" << std::endl;

e.ClearPolicy();
std::cerr << "DEBUG:7" << std::endl;
e.AddPolicy({"admin", "data1", "read"});
std::cerr << "DEBUG:8" << std::endl;
e.AddPolicy({"bob", "data1", "read"});
std::cerr << "DEBUG:9" << std::endl;
e.AddPolicies(PoliciesValues({{"tom", "data1", "read"}, {"john", "data1", "read"}}));
std::cerr << "DEBUG:10" << std::endl;
e.AddGroupingPolicy({"alice", "admin"});
std::cerr << "DEBUG:11" << std::endl;

ASSERT_TRUE(casbin::ArrayEquals({"alice", "bob", "tom", "john"}, e.GetImplicitUsersForPermission({"data1", "read"})));
std::cerr << "DEBUG:12" << std::endl;
}

} // namespace

0 comments on commit 0e9ccb0

Please sign in to comment.