From 1ab36272f6e5237c26cec59693495929f43b4b33 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Fri, 29 Nov 2024 06:44:26 -0600 Subject: [PATCH] fuse unit tests and fixes --- .../src/drives/fuse/fuse_drive.cpp | 2 +- .../src/fuse_drive_chown_test.cpp | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/repertory/librepertory/src/drives/fuse/fuse_drive.cpp b/repertory/librepertory/src/drives/fuse/fuse_drive.cpp index 9b8e0975..37b2418e 100644 --- a/repertory/librepertory/src/drives/fuse/fuse_drive.cpp +++ b/repertory/librepertory/src/drives/fuse/fuse_drive.cpp @@ -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(-1)) { - if (get_effective_uid() != 0) { + if (get_effective_uid() != 0 && get_effective_uid() != uid) { return api_error::permission_denied; } diff --git a/repertory/repertory_test/src/fuse_drive_chown_test.cpp b/repertory/repertory_test/src/fuse_drive_chown_test.cpp index 6d460908..7272ee06 100644 --- a/repertory/repertory_test/src/fuse_drive_chown_test.cpp +++ b/repertory/repertory_test/src/fuse_drive_chown_test.cpp @@ -55,6 +55,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"};