fuse unit tests and fixes
This commit is contained in:
parent
2bd847b833
commit
74109d1195
@ -170,6 +170,17 @@ public:
|
||||
return file_path;
|
||||
}
|
||||
|
||||
static auto create_directory_and_test(std::string &dir_name) -> std::string {
|
||||
dir_name += std::to_string(++idx);
|
||||
|
||||
auto dir_path = utils::path::combine(mount_location, {dir_name});
|
||||
EXPECT_TRUE(utils::file::directory(dir_path).create());
|
||||
|
||||
EXPECT_TRUE(utils::file::directory(dir_path).exists());
|
||||
EXPECT_FALSE(utils::file::file(dir_path).exists());
|
||||
return dir_path;
|
||||
}
|
||||
|
||||
static auto create_root_file(std::string &file_name) -> std::string {
|
||||
auto file_path = create_file_and_test(file_name);
|
||||
auto api_path = utils::path::create_api_path(file_name);
|
||||
@ -204,11 +215,18 @@ public:
|
||||
EXPECT_TRUE(unmounted);
|
||||
}
|
||||
|
||||
static void rmdir_and_test(std::string_view dir_path) {
|
||||
EXPECT_TRUE(utils::file::directory(dir_path).remove());
|
||||
EXPECT_FALSE(utils::file::directory(dir_path).exists());
|
||||
|
||||
EXPECT_FALSE(utils::file::file(dir_path).exists());
|
||||
}
|
||||
|
||||
static void unlink_file_and_test(std::string_view file_path) {
|
||||
EXPECT_TRUE(utils::file::file(file_path).remove());
|
||||
EXPECT_FALSE(utils::file::file(file_path).exists());
|
||||
|
||||
EXPECT_FALSE(utils::file::directory(file_path).exists());
|
||||
EXPECT_FALSE(utils::file::file(file_path).exists());
|
||||
}
|
||||
|
||||
static void unlink_root_file(const std::string &file_path) {
|
||||
|
75
repertory/repertory_test/src/fuse_drive_chmod_test.cpp
Normal file
75
repertory/repertory_test/src/fuse_drive_chmod_test.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#if !defined(_WIN32)
|
||||
|
||||
#include "fixtures/fuse_fixture.hpp"
|
||||
|
||||
namespace repertory {
|
||||
TYPED_TEST_CASE(fuse_test, fuse_provider_types);
|
||||
|
||||
TYPED_TEST(fuse_test, can_chmod_if_owner) {
|
||||
std::string file_name{"chmod_test"};
|
||||
auto file_path = this->create_file_and_test(file_name);
|
||||
|
||||
EXPECT_EQ(0, chmod(file_path.c_str(), S_IRUSR | S_IWUSR));
|
||||
std::this_thread::sleep_for(SLEEP_SECONDS);
|
||||
|
||||
struct stat64 unix_st{};
|
||||
stat64(file_path.c_str(), &unix_st);
|
||||
EXPECT_EQ(static_cast<std::uint32_t>(S_IRUSR | S_IWUSR),
|
||||
ACCESSPERMS & unix_st.st_mode);
|
||||
|
||||
this->unlink_file_and_test(file_path);
|
||||
}
|
||||
|
||||
TYPED_TEST(fuse_test, can_not_chmod_if_not_owner) {
|
||||
std::string file_name{"chmod_test"};
|
||||
auto file_path = this->create_root_file(file_name);
|
||||
|
||||
EXPECT_EQ(-1, chmod(file_path.c_str(), S_IRUSR | S_IWUSR));
|
||||
EXPECT_EQ(EPERM, errno);
|
||||
|
||||
this->unlink_root_file(file_path);
|
||||
}
|
||||
|
||||
TYPED_TEST(fuse_test, can_not_chmod_setgid_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_ISGID));
|
||||
EXPECT_EQ(EPERM, errno);
|
||||
|
||||
this->unlink_file_and_test(file_path);
|
||||
}
|
||||
|
||||
TYPED_TEST(fuse_test, can_not_chmod_setuid_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_ISUID));
|
||||
EXPECT_EQ(EPERM, errno);
|
||||
|
||||
this->unlink_file_and_test(file_path);
|
||||
}
|
||||
} // namespace repertory
|
||||
|
||||
#endif // !defined(_WIN32)
|
113
repertory/repertory_test/src/fuse_drive_chown_test.cpp
Normal file
113
repertory/repertory_test/src/fuse_drive_chown_test.cpp
Normal file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#if !defined(_WIN32)
|
||||
|
||||
#include "fixtures/fuse_fixture.hpp"
|
||||
|
||||
namespace repertory {
|
||||
TYPED_TEST_CASE(fuse_test, fuse_provider_types);
|
||||
|
||||
TYPED_TEST(fuse_test, 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, can_chown_group_if_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(), static_cast<uid_t>(-1), 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,
|
||||
can_not_chown_group_if_owner_but_not_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(-1, chown(file_path.c_str(), static_cast<uid_t>(-1), 0));
|
||||
EXPECT_EQ(EPERM, errno);
|
||||
|
||||
struct stat64 unix_st2{};
|
||||
stat64(file_path.c_str(), &unix_st2);
|
||||
EXPECT_EQ(unix_st.st_gid, 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, can_not_chown_group_if_not_the_owner) {
|
||||
std::string file_name{"chown_test"};
|
||||
auto file_path = this->create_root_file(file_name);
|
||||
|
||||
struct stat64 unix_st{};
|
||||
EXPECT_EQ(0, stat64(file_path.c_str(), &unix_st));
|
||||
|
||||
EXPECT_EQ(-1, chown(file_path.c_str(), static_cast<uid_t>(-1), getgid()));
|
||||
EXPECT_EQ(EPERM, errno);
|
||||
|
||||
struct stat64 unix_st2{};
|
||||
stat64(file_path.c_str(), &unix_st2);
|
||||
EXPECT_EQ(unix_st.st_gid, unix_st2.st_gid);
|
||||
EXPECT_EQ(unix_st.st_uid, unix_st2.st_uid);
|
||||
|
||||
this->unlink_root_file(file_path);
|
||||
}
|
||||
|
||||
TYPED_TEST(fuse_test, can_not_chown_user_if_not_root) {
|
||||
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(-1, chown(file_path.c_str(), 0, static_cast<gid_t>(-1)));
|
||||
EXPECT_EQ(EPERM, errno);
|
||||
|
||||
struct stat64 unix_st2{};
|
||||
stat64(file_path.c_str(), &unix_st2);
|
||||
EXPECT_EQ(unix_st.st_gid, unix_st2.st_gid);
|
||||
EXPECT_EQ(unix_st.st_uid, unix_st2.st_uid);
|
||||
|
||||
this->unlink_file_and_test(file_path);
|
||||
}
|
||||
} // namespace repertory
|
||||
|
||||
#endif // !defined(_WIN32)
|
51
repertory/repertory_test/src/fuse_drive_directory_test.cpp
Normal file
51
repertory/repertory_test/src/fuse_drive_directory_test.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#if !defined(_WIN32)
|
||||
|
||||
#include "fixtures/fuse_fixture.hpp"
|
||||
|
||||
namespace repertory {
|
||||
TYPED_TEST_CASE(fuse_test, fuse_provider_types);
|
||||
|
||||
TYPED_TEST(fuse_test, can_create_and_remove_directory) {
|
||||
auto dir_name = std::string{"dir"} + std::to_string(++this->idx);
|
||||
|
||||
auto dir_path = utils::path::combine(this->mount_location, {dir_name});
|
||||
EXPECT_EQ(0, mkdir(dir_path.c_str(),
|
||||
S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP));
|
||||
|
||||
EXPECT_TRUE(utils::file::is_directory(dir_path));
|
||||
EXPECT_FALSE(utils::file::is_file(dir_path));
|
||||
|
||||
struct stat64 unix_st{};
|
||||
stat64(dir_path.c_str(), &unix_st);
|
||||
|
||||
EXPECT_EQ(getgid(), unix_st.st_gid);
|
||||
EXPECT_EQ(getuid(), unix_st.st_uid);
|
||||
|
||||
EXPECT_EQ(static_cast<std::uint32_t>(S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP |
|
||||
S_IXGRP),
|
||||
ACCESSPERMS & unix_st.st_mode);
|
||||
}
|
||||
} // namespace repertory
|
||||
|
||||
#endif // !defined(_WIN32)
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user