2 Commits

Author SHA1 Message Date
b1735ab0af fuse unit tests and fixes
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
2024-11-29 06:47:21 -06:00
1ab36272f6 fuse unit tests and fixes 2024-11-29 06:44:26 -06:00
3 changed files with 31 additions and 11 deletions

View File

@@ -88,7 +88,7 @@ auto fuse_drive::chown_impl(std::string api_path, uid_t uid,
api_path, X_OK, [&](api_meta_map &meta) -> api_error {
meta.clear();
if (uid != static_cast<uid_t>(-1)) {
if (get_effective_uid() != 0) {
if (get_effective_uid() != 0 && get_effective_uid() != uid) {
return api_error::permission_denied;
}

View File

@@ -26,6 +26,16 @@
namespace repertory {
TYPED_TEST_CASE(fuse_test, fuse_provider_types);
TYPED_TEST(fuse_test, chmod_can_not_chmod_set_sticky_if_not_root) {
std::string file_name{"chmod_test"};
auto file_path = this->create_file_and_test(file_name);
EXPECT_EQ(-1, chmod(file_path.c_str(), S_IRUSR | S_IWUSR | S_ISVTX));
EXPECT_EQ(EPERM, errno);
this->unlink_file_and_test(file_path);
}
TYPED_TEST(fuse_test, chmod_can_chmod_if_owner) {
std::string file_name{"chmod_test"};
auto file_path = this->create_file_and_test(file_name);

View File

@@ -26,16 +26,6 @@
namespace repertory {
TYPED_TEST_CASE(fuse_test, fuse_provider_types);
TYPED_TEST(fuse_test, chown_can_not_chmod_set_sticky_if_not_root) {
std::string file_name{"chown_test"};
auto file_path = this->create_file_and_test(file_name);
EXPECT_EQ(-1, chmod(file_path.c_str(), S_IRUSR | S_IWUSR | S_ISVTX));
EXPECT_EQ(EPERM, errno);
this->unlink_file_and_test(file_path);
}
TYPED_TEST(fuse_test,
chown_can_chown_group_if_owner_and_a_member_of_the_group) {
std::string file_name{"chown_test"};
@@ -55,6 +45,26 @@ TYPED_TEST(fuse_test,
this->unlink_file_and_test(file_path);
}
TYPED_TEST(
fuse_test,
chown_can_chown_group_when_specifying_owner_and_a_member_of_the_group) {
std::string file_name{"chown_test"};
auto file_path = this->create_file_and_test(file_name);
struct stat64 unix_st {};
EXPECT_EQ(0, stat64(file_path.c_str(), &unix_st));
EXPECT_EQ(0, chown(file_path.c_str(), getuid(), getgid()));
std::this_thread::sleep_for(SLEEP_SECONDS);
struct stat64 unix_st2 {};
stat64(file_path.c_str(), &unix_st2);
EXPECT_EQ(getgid(), unix_st2.st_gid);
EXPECT_EQ(unix_st.st_uid, unix_st2.st_uid);
this->unlink_file_and_test(file_path);
}
TYPED_TEST(fuse_test,
chown_can_not_chown_group_if_owner_but_not_a_member_of_the_group) {
std::string file_name{"chown_test"};