fuse unit tests and fixes
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2024-11-10 15:45:25 -06:00
parent 4e8e188d24
commit 9c3e464ce4

View File

@ -23,6 +23,53 @@
#include "fixtures/fuse_fixture.hpp"
namespace {
const auto access_permutations = {
// clang-format off
std::make_tuple(0000, R_OK, -1, EACCES), // No permissions, R_OK
std::make_tuple(0000, W_OK, -1, EACCES), // No permissions, W_OK
std::make_tuple(0000, X_OK, -1, EACCES), // No permissions, X_OK
std::make_tuple(0444, R_OK, 0, 0), // Read-only, R_OK
std::make_tuple(0444, W_OK, -1, EACCES), // Read-only, W_OK
std::make_tuple(0444, X_OK, -1, EACCES), // Read-only, X_OK
std::make_tuple(0222, R_OK, -1, EACCES), // Write-only, R_OK
std::make_tuple(0222, W_OK, 0, 0), // Write-only, W_OK
std::make_tuple(0222, X_OK, -1, EACCES), // Write-only, X_OK
std::make_tuple(0111, R_OK, -1, EACCES), // Execute-only, R_OK
std::make_tuple(0111, W_OK, -1, EACCES), // Execute-only, W_OK
std::make_tuple(0111, X_OK, 0, 0), // Execute-only, X_OK
std::make_tuple(0666, R_OK | W_OK, 0, 0), // Read and write, R_OK | W_OK
std::make_tuple(0666, R_OK | X_OK, -1, EACCES), // Read and write, R_OK | X_OK
std::make_tuple(0777, R_OK | W_OK | X_OK, 0, 0), // All permissions
std::make_tuple(0555, R_OK | X_OK, 0, 0), // Read and execute, R_OK | X_OK
std::make_tuple(0555, W_OK, -1, EACCES) // Read and execute, W_OK
// clang-format on
};
void perform_access_test(auto &&permutation, auto &&item_path) {
mode_t permissions{};
int access_mode{};
int expected_result{};
int expected_errno{};
std::tie(permissions, access_mode, expected_result, expected_errno) =
permutation;
EXPECT_EQ(0, chmod(item_path.c_str(), permissions));
auto result = access(item_path.c_str(), access_mode);
EXPECT_EQ(result, expected_result)
<< "Expected access result to be " << expected_result
<< " for permissions " << std::oct << permissions << " and access mode "
<< access_mode;
if (result == -1) {
EXPECT_EQ(errno, expected_errno)
<< "Expected errno to be " << expected_errno << " for permissions "
<< std::oct << permissions;
}
}
} // namespace
namespace repertory {
TYPED_TEST_CASE(fuse_test, fuse_provider_types);
@ -43,69 +90,6 @@ TYPED_TEST(fuse_test, access_can_check_if_directory_exists) {
this->rmdir_and_test(dir_path);
}
TYPED_TEST(fuse_test, access_can_check_directory_read_access) {
std::string dir_name{"access_test"};
auto dir_path = this->create_directory_and_test(dir_name);
EXPECT_EQ(0, access(dir_path.c_str(), R_OK));
this->rmdir_and_test(dir_path);
}
TYPED_TEST(fuse_test, access_can_check_directory_does_not_have_read_access) {
std::string dir_name{"access_test"};
auto dir_path = this->create_directory_and_test(dir_name);
EXPECT_EQ(0, chmod(dir_path.c_str(), 0000));
EXPECT_EQ(-1, access(dir_path.c_str(), R_OK));
EXPECT_EQ(EACCES, utils::get_last_error_code());
this->rmdir_and_test(dir_path);
}
TYPED_TEST(fuse_test, access_can_check_directory_write_access) {
std::string dir_name{"access_test"};
auto dir_path = this->create_directory_and_test(dir_name);
EXPECT_EQ(0, access(dir_path.c_str(), W_OK));
this->rmdir_and_test(dir_path);
}
TYPED_TEST(fuse_test, access_can_check_directory_does_not_have_write_access) {
std::string dir_name{"access_test"};
auto dir_path = this->create_directory_and_test(dir_name);
EXPECT_EQ(0, chmod(dir_path.c_str(), 0000));
EXPECT_EQ(-1, access(dir_path.c_str(), W_OK));
EXPECT_EQ(EACCES, utils::get_last_error_code());
this->rmdir_and_test(dir_path);
}
TYPED_TEST(fuse_test, access_can_check_directory_execute_access) {
std::string dir_name{"access_test"};
auto dir_path = this->create_directory_and_test(dir_name);
EXPECT_EQ(0, access(dir_path.c_str(), X_OK));
this->rmdir_and_test(dir_path);
}
TYPED_TEST(fuse_test, access_can_check_directory_does_not_have_execute_access) {
std::string dir_name{"access_test"};
auto dir_path = this->create_directory_and_test(dir_name);
EXPECT_EQ(0, chmod(dir_path.c_str(), 0000));
EXPECT_EQ(-1, access(dir_path.c_str(), X_OK));
EXPECT_EQ(EACCES, utils::get_last_error_code());
this->rmdir_and_test(dir_path);
}
TYPED_TEST(fuse_test, access_can_check_if_file_exists) {
std::string file_name{"access_test"};
auto file_path = this->create_file_and_test(file_name);
@ -115,66 +99,24 @@ TYPED_TEST(fuse_test, access_can_check_if_file_exists) {
this->unlink_file_and_test(file_path);
}
TYPED_TEST(fuse_test, access_can_check_file_read_access) {
std::string file_name{"access_test"};
auto file_path = this->create_file_and_test(file_name);
TYPED_TEST(fuse_test, access_directory_permutations_test) {
std::string dir_name{"access_test"};
auto dir_path = this->create_directory_and_test(dir_name);
EXPECT_EQ(0, access(file_path.c_str(), R_OK));
for (auto &&permutation : access_permutations) {
perform_access_test(permutation, dir_path);
}
this->unlink_file_and_test(file_path);
this->rmdir_and_test(dir_path);
}
TYPED_TEST(fuse_test, access_can_check_file_does_not_have_read_access) {
TYPED_TEST(fuse_test, access_file_permutations_test) {
std::string file_name{"access_test"};
auto file_path = this->create_file_and_test(file_name);
EXPECT_EQ(0, chmod(file_path.c_str(), 0000));
EXPECT_EQ(-1, access(file_path.c_str(), R_OK));
EXPECT_EQ(EACCES, utils::get_last_error_code());
this->unlink_file_and_test(file_path);
}
TYPED_TEST(fuse_test, access_can_check_file_write_access) {
std::string file_name{"access_test"};
auto file_path = this->create_file_and_test(file_name);
EXPECT_EQ(0, access(file_path.c_str(), W_OK));
this->unlink_file_and_test(file_path);
}
TYPED_TEST(fuse_test, access_can_check_file_does_not_have_write_access) {
std::string file_name{"access_test"};
auto file_path = this->create_file_and_test(file_name);
EXPECT_EQ(0, chmod(file_path.c_str(), 0000));
EXPECT_EQ(-1, access(file_path.c_str(), W_OK));
EXPECT_EQ(EACCES, utils::get_last_error_code());
this->unlink_file_and_test(file_path);
}
TYPED_TEST(fuse_test, access_can_check_file_execute_access) {
std::string file_name{"access_test"};
auto file_path = this->create_file_and_test(file_name);
EXPECT_EQ(0, chmod(file_path.c_str(), 0700));
EXPECT_EQ(0, access(file_path.c_str(), X_OK));
this->unlink_file_and_test(file_path);
}
TYPED_TEST(fuse_test, access_can_check_file_does_not_have_execute_access) {
std::string file_name{"access_test"};
auto file_path = this->create_file_and_test(file_name);
EXPECT_EQ(0, chmod(file_path.c_str(), 0000));
EXPECT_EQ(-1, access(file_path.c_str(), X_OK));
EXPECT_EQ(EACCES, utils::get_last_error_code());
for (auto &&permutation : access_permutations) {
perform_access_test(permutation, file_path);
}
this->unlink_file_and_test(file_path);
}