2022-12-31 19:41:45 +00:00
|
|
|
#include "webfuse/webfuse.hpp"
|
|
|
|
#include "webfuse/test/fixture.hpp"
|
|
|
|
#include "webfuse/test/filesystem_mock.hpp"
|
|
|
|
#include "webfuse/test/daemon.hpp"
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
using testing::_;
|
|
|
|
using testing::Return;
|
|
|
|
using testing::Invoke;
|
|
|
|
using testing::AnyNumber;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
int fs_getattr (std::string const & path, struct stat * attr)
|
|
|
|
{
|
|
|
|
memset(reinterpret_cast<void*>(attr),0, sizeof(struct stat));
|
|
|
|
|
2022-12-31 20:33:25 +00:00
|
|
|
if (path == "/")
|
|
|
|
{
|
|
|
|
attr->st_nlink = 0;
|
|
|
|
attr->st_mode = S_IFDIR | 0755;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (path == "/foo")
|
2022-12-31 19:41:45 +00:00
|
|
|
{
|
|
|
|
attr->st_nlink = 0;
|
|
|
|
attr->st_mode = S_IFREG | 0755;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-01 13:48:19 +00:00
|
|
|
TEST(readdir, existing_file)
|
2022-12-31 19:41:45 +00:00
|
|
|
{
|
|
|
|
webfuse::filesystem_mock fs;
|
2022-12-31 20:33:25 +00:00
|
|
|
EXPECT_CALL(fs, access("/",_)).Times(AnyNumber()).WillRepeatedly(Return(0));
|
2023-01-01 13:48:19 +00:00
|
|
|
EXPECT_CALL(fs, access("/foo", F_OK)).WillOnce(Return(0));
|
|
|
|
EXPECT_CALL(fs, access("/foo", R_OK)).WillOnce(Return(0));
|
|
|
|
EXPECT_CALL(fs, access("/foo", W_OK)).WillOnce(Return(0));
|
|
|
|
EXPECT_CALL(fs, access("/foo", X_OK)).WillOnce(Return(-EACCES));
|
2022-12-31 19:41:45 +00:00
|
|
|
EXPECT_CALL(fs, getattr(_,_)).WillRepeatedly(Invoke(fs_getattr));
|
2022-12-31 20:33:25 +00:00
|
|
|
|
|
|
|
webfuse::fixture fixture(fs);
|
2022-12-31 19:41:45 +00:00
|
|
|
auto const path = fixture.get_path() + "/foo";
|
|
|
|
|
2023-01-01 13:48:19 +00:00
|
|
|
ASSERT_EQ(0, ::access(path.c_str(), F_OK));
|
|
|
|
ASSERT_EQ(0, ::access(path.c_str(), R_OK));
|
|
|
|
ASSERT_EQ(0, ::access(path.c_str(), W_OK));
|
|
|
|
ASSERT_EQ(-1, ::access(path.c_str(), X_OK));
|
|
|
|
ASSERT_EQ(EACCES, errno);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(access, non_existing_file)
|
|
|
|
{
|
|
|
|
webfuse::filesystem_mock fs;
|
|
|
|
EXPECT_CALL(fs, access("/",_)).Times(AnyNumber()).WillRepeatedly(Return(0));
|
|
|
|
EXPECT_CALL(fs, access("/foo", F_OK)).WillOnce(Return(-ENOENT));
|
|
|
|
EXPECT_CALL(fs, getattr(_,_)).WillRepeatedly(Invoke(fs_getattr));
|
|
|
|
|
|
|
|
webfuse::fixture fixture(fs);
|
|
|
|
auto const path = fixture.get_path() + "/foo";
|
|
|
|
|
|
|
|
ASSERT_EQ(-1, ::access(path.c_str(), F_OK));
|
|
|
|
ASSERT_EQ(ENOENT, errno);
|
2022-12-31 19:41:45 +00:00
|
|
|
}
|