4 Commits

Author SHA1 Message Date
9c3e464ce4 fuse unit tests and fixes
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
2024-11-10 15:45:25 -06:00
4e8e188d24 fuse unit tests and fixes 2024-11-10 15:18:05 -06:00
e476b4f0c6 fuse unit tests and fixes 2024-11-10 10:26:38 -06:00
eec286845e fuse unit tests and fixes 2024-11-10 10:25:53 -06:00
2 changed files with 59 additions and 74 deletions

View File

@ -88,7 +88,7 @@ auto fuse_drive_base::check_access(const std::string &api_path,
// Check allow execute // Check allow execute
if ((mask & X_OK) == X_OK) { if ((mask & X_OK) == X_OK) {
if ((effective_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) == 0) { if ((effective_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) == 0) {
return api_error::permission_denied; return api_error::access_denied;
} }
} }

View File

@ -23,6 +23,53 @@
#include "fixtures/fuse_fixture.hpp" #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 { namespace repertory {
TYPED_TEST_CASE(fuse_test, fuse_provider_types); TYPED_TEST_CASE(fuse_test, fuse_provider_types);
@ -43,48 +90,6 @@ TYPED_TEST(fuse_test, access_can_check_if_directory_exists) {
this->rmdir_and_test(dir_path); 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_if_file_exists) { TYPED_TEST(fuse_test, access_can_check_if_file_exists) {
std::string file_name{"access_test"}; std::string file_name{"access_test"};
auto file_path = this->create_file_and_test(file_name); auto file_path = this->create_file_and_test(file_name);
@ -94,44 +99,24 @@ TYPED_TEST(fuse_test, access_can_check_if_file_exists) {
this->unlink_file_and_test(file_path); this->unlink_file_and_test(file_path);
} }
TYPED_TEST(fuse_test, access_can_check_file_read_access) { TYPED_TEST(fuse_test, access_directory_permutations_test) {
std::string file_name{"access_test"}; std::string dir_name{"access_test"};
auto file_path = this->create_file_and_test(file_name); 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"}; std::string file_name{"access_test"};
auto file_path = this->create_file_and_test(file_name); auto file_path = this->create_file_and_test(file_name);
EXPECT_EQ(0, chmod(file_path.c_str(), 0000)); for (auto &&permutation : access_permutations) {
perform_access_test(permutation, file_path);
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); this->unlink_file_and_test(file_path);
} }