[unit test] Complete all providers unit tests #12
This commit is contained in:
@@ -28,24 +28,29 @@
|
|||||||
#include "comm/i_http_comm.hpp"
|
#include "comm/i_http_comm.hpp"
|
||||||
#include "events/event_system.hpp"
|
#include "events/event_system.hpp"
|
||||||
#include "file_manager/file_manager.hpp"
|
#include "file_manager/file_manager.hpp"
|
||||||
#include "fixtures/providers_fixture.hpp"
|
|
||||||
#include "platform/platform.hpp"
|
#include "platform/platform.hpp"
|
||||||
#include "providers/encrypt/encrypt_provider.hpp"
|
#include "providers/encrypt/encrypt_provider.hpp"
|
||||||
#include "providers/i_provider.hpp"
|
#include "providers/i_provider.hpp"
|
||||||
#include "providers/s3/s3_provider.hpp"
|
#include "providers/s3/s3_provider.hpp"
|
||||||
#include "providers/sia/sia_provider.hpp"
|
#include "providers/sia/sia_provider.hpp"
|
||||||
#include "utils/collection.hpp"
|
|
||||||
#include "utils/file.hpp"
|
#include "utils/file.hpp"
|
||||||
#include "utils/path.hpp"
|
#include "utils/path.hpp"
|
||||||
#include "utils/string.hpp"
|
|
||||||
#include "utils/time.hpp"
|
|
||||||
#include "utils/utils.hpp"
|
#include "utils/utils.hpp"
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
namespace {
|
||||||
|
using gid_t = std::uint32_t;
|
||||||
|
using uid_t = std::uint32_t;
|
||||||
|
static constexpr auto getgid() -> gid_t { return 0U; }
|
||||||
|
static constexpr auto getuid() -> uid_t { return 0U; }
|
||||||
|
} // namespace
|
||||||
|
#endif // defined(_WIN32)
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
struct encrypt_provider_type final {
|
struct encrypt_provider_type final {
|
||||||
static constexpr provider_type type{provider_type::encrypt};
|
static constexpr provider_type type{provider_type::encrypt};
|
||||||
|
|
||||||
static void setup(std::unique_ptr<i_http_comm> &comm,
|
static void setup(std::unique_ptr<i_http_comm> & /* comm */,
|
||||||
std::unique_ptr<app_config> &config,
|
std::unique_ptr<app_config> &config,
|
||||||
std::unique_ptr<i_provider> &provider) {
|
std::unique_ptr<i_provider> &provider) {
|
||||||
auto config_path =
|
auto config_path =
|
||||||
@@ -200,6 +205,114 @@ protected:
|
|||||||
|
|
||||||
event_system::instance().stop();
|
event_system::instance().stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static void check_forced_dirs(const directory_item_list &list) {
|
||||||
|
static auto forced_dirs = std::array<std::string, 2>{".", ".."};
|
||||||
|
for (std::size_t i = 0U; i < forced_dirs.size(); ++i) {
|
||||||
|
const auto &item = list.at(i);
|
||||||
|
EXPECT_TRUE(item.directory);
|
||||||
|
EXPECT_STREQ(forced_dirs.at(i).c_str(), item.api_path.c_str());
|
||||||
|
EXPECT_STREQ("", item.api_parent.c_str());
|
||||||
|
EXPECT_EQ(std::size_t(0U), item.size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void create_directory(const std::string &api_path) {
|
||||||
|
auto date = utils::time::get_time_now();
|
||||||
|
auto meta = create_meta_attributes(
|
||||||
|
date, 1U, date + 1U, date + 2U, true, getgid(), "", 0700, date + 3U, 2U,
|
||||||
|
3U, 0U, api_path + "_src", getuid(), date + 4U);
|
||||||
|
EXPECT_EQ(api_error::success, provider->create_directory(api_path, meta));
|
||||||
|
|
||||||
|
bool exists{};
|
||||||
|
EXPECT_EQ(api_error::success, provider->is_directory(api_path, exists));
|
||||||
|
EXPECT_TRUE(exists);
|
||||||
|
|
||||||
|
api_meta_map meta2{};
|
||||||
|
EXPECT_EQ(api_error::success, provider->get_item_meta(api_path, meta2));
|
||||||
|
|
||||||
|
EXPECT_EQ(date, utils::string::to_uint64(meta2[META_ACCESSED]));
|
||||||
|
EXPECT_EQ(1U, utils::string::to_uint64(meta2[META_ATTRIBUTES]));
|
||||||
|
EXPECT_EQ(date + 1U, utils::string::to_uint64(meta2[META_CHANGED]));
|
||||||
|
EXPECT_EQ(date + 2U, utils::string::to_uint64(meta2[META_CREATION]));
|
||||||
|
EXPECT_TRUE(utils::string::to_bool(meta2.at(META_DIRECTORY)));
|
||||||
|
EXPECT_EQ(getgid(),
|
||||||
|
static_cast<gid_t>(utils::string::to_uint32(meta2[META_GID])));
|
||||||
|
EXPECT_EQ(std::uint32_t(0700), utils::string::to_uint32(meta2[META_MODE]));
|
||||||
|
EXPECT_EQ(date + 3U, utils::string::to_uint64(meta2[META_MODIFIED]));
|
||||||
|
EXPECT_EQ(2U, utils::string::to_uint64(meta2[META_BACKUP]));
|
||||||
|
EXPECT_EQ(3U, utils::string::to_uint64(meta2[META_OSXFLAGS]));
|
||||||
|
EXPECT_FALSE(utils::string::to_bool(meta2[META_PINNED]));
|
||||||
|
EXPECT_EQ(std::uint64_t(0U), utils::string::to_uint64(meta2[META_SIZE]));
|
||||||
|
EXPECT_EQ(getuid(),
|
||||||
|
static_cast<uid_t>(utils::string::to_uint32(meta2[META_UID])));
|
||||||
|
EXPECT_EQ(date + 4U, utils::string::to_uint64(meta2[META_WRITTEN]));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void create_file(const std::string &api_path) {
|
||||||
|
auto source_path = test::generate_test_file_name("providers_test");
|
||||||
|
|
||||||
|
auto date = utils::time::get_time_now();
|
||||||
|
auto meta = create_meta_attributes(date, 1U, date + 1U, date + 2U, false,
|
||||||
|
getgid(), "", 0700, date + 3U, 2U, 3U,
|
||||||
|
0U, source_path, getuid(), date + 4U);
|
||||||
|
EXPECT_EQ(api_error::success, provider->create_file(api_path, meta));
|
||||||
|
|
||||||
|
bool exists{};
|
||||||
|
EXPECT_EQ(api_error::success, provider->is_file(api_path, exists));
|
||||||
|
EXPECT_TRUE(exists);
|
||||||
|
|
||||||
|
EXPECT_TRUE(utils::file::file{source_path}.remove());
|
||||||
|
|
||||||
|
api_meta_map meta2{};
|
||||||
|
EXPECT_EQ(api_error::success, provider->get_item_meta(api_path, meta2));
|
||||||
|
|
||||||
|
EXPECT_EQ(date, utils::string::to_uint64(meta2[META_ACCESSED]));
|
||||||
|
EXPECT_EQ(1U, utils::string::to_uint64(meta2[META_ATTRIBUTES]));
|
||||||
|
EXPECT_EQ(date + 1U, utils::string::to_uint64(meta2[META_CHANGED]));
|
||||||
|
EXPECT_EQ(date + 2U, utils::string::to_uint64(meta2[META_CREATION]));
|
||||||
|
EXPECT_FALSE(utils::string::to_bool(meta2.at(META_DIRECTORY)));
|
||||||
|
EXPECT_EQ(getgid(),
|
||||||
|
static_cast<gid_t>(utils::string::to_uint32(meta2[META_GID])));
|
||||||
|
EXPECT_EQ(std::uint32_t(0700), utils::string::to_uint32(meta2[META_MODE]));
|
||||||
|
EXPECT_EQ(date + 3U, utils::string::to_uint64(meta2[META_MODIFIED]));
|
||||||
|
EXPECT_EQ(2U, utils::string::to_uint64(meta2[META_BACKUP]));
|
||||||
|
EXPECT_EQ(3U, utils::string::to_uint64(meta2[META_OSXFLAGS]));
|
||||||
|
EXPECT_FALSE(utils::string::to_bool(meta2[META_PINNED]));
|
||||||
|
EXPECT_EQ(std::uint64_t(0U), utils::string::to_uint64(meta2[META_SIZE]));
|
||||||
|
EXPECT_STREQ(source_path.c_str(), meta2[META_SOURCE].c_str());
|
||||||
|
EXPECT_EQ(getuid(),
|
||||||
|
static_cast<uid_t>(utils::string::to_uint32(meta2[META_UID])));
|
||||||
|
EXPECT_EQ(date + 4U, utils::string::to_uint64(meta2[META_WRITTEN]));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void decrypt_parts(std::string &path) {
|
||||||
|
if (path != "/" && path != "." && path != "..") {
|
||||||
|
utils::hash::hash_256_t key{};
|
||||||
|
EXPECT_TRUE(utils::encryption::recreate_key_argon2id(
|
||||||
|
config->get_encrypt_config().encryption_token,
|
||||||
|
config->get_encrypt_config().kdf_cfg, key));
|
||||||
|
auto parts = utils::string::split(path, '/', false);
|
||||||
|
for (auto &part : parts) {
|
||||||
|
if (part.empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPECT_TRUE(utils::encryption::decrypt_file_name(key, part));
|
||||||
|
}
|
||||||
|
path = utils::string::join(parts, '/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] static auto
|
||||||
|
pinned_includes_api_path(const auto &pinned, const std::string &expected_path)
|
||||||
|
-> bool {
|
||||||
|
return std::ranges::any_of(pinned,
|
||||||
|
[&expected_path](auto &&api_path) -> bool {
|
||||||
|
return api_path == expected_path;
|
||||||
|
});
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename provider_t>
|
template <typename provider_t>
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
// } // namespace
|
// } // namespace
|
||||||
//
|
//
|
||||||
// namespace repertory {
|
// namespace repertory {
|
||||||
// TYPED_TEST_CASE(file_db_test, file_db_types);
|
// TYPED_TEST_SUITE(file_db_test, file_db_types);
|
||||||
//
|
//
|
||||||
// TYPED_TEST(file_db_test, can_add_and_remove_directory) {
|
// TYPED_TEST(file_db_test, can_add_and_remove_directory) {
|
||||||
// this->file_db->clear();
|
// this->file_db->clear();
|
||||||
|
@@ -24,7 +24,7 @@
|
|||||||
#include "utils/time.hpp"
|
#include "utils/time.hpp"
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
TYPED_TEST_CASE(file_mgr_db_test, file_mgr_db_types);
|
TYPED_TEST_SUITE(file_mgr_db_test, file_mgr_db_types);
|
||||||
|
|
||||||
TYPED_TEST(file_mgr_db_test, can_add_and_remove_resume) {
|
TYPED_TEST(file_mgr_db_test, can_add_and_remove_resume) {
|
||||||
this->file_mgr_db->clear();
|
this->file_mgr_db->clear();
|
||||||
|
@@ -71,7 +71,7 @@ void perform_access_test(auto &&permutation, auto &&item_path) {
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
TYPED_TEST_CASE(fuse_test, fuse_provider_types);
|
TYPED_TEST_SUITE(fuse_test, fuse_provider_types);
|
||||||
|
|
||||||
TYPED_TEST(fuse_test, access_can_check_if_item_does_not_exist) {
|
TYPED_TEST(fuse_test, access_can_check_if_item_does_not_exist) {
|
||||||
EXPECT_EQ(
|
EXPECT_EQ(
|
||||||
|
@@ -24,7 +24,7 @@
|
|||||||
#include "fixtures/fuse_fixture.hpp"
|
#include "fixtures/fuse_fixture.hpp"
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
TYPED_TEST_CASE(fuse_test, fuse_provider_types);
|
TYPED_TEST_SUITE(fuse_test, fuse_provider_types);
|
||||||
|
|
||||||
TYPED_TEST(fuse_test, chmod_can_not_chmod_set_sticky_if_not_root) {
|
TYPED_TEST(fuse_test, chmod_can_not_chmod_set_sticky_if_not_root) {
|
||||||
std::string file_name{"chmod_test"};
|
std::string file_name{"chmod_test"};
|
||||||
|
@@ -24,7 +24,7 @@
|
|||||||
#include "fixtures/fuse_fixture.hpp"
|
#include "fixtures/fuse_fixture.hpp"
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
TYPED_TEST_CASE(fuse_test, fuse_provider_types);
|
TYPED_TEST_SUITE(fuse_test, fuse_provider_types);
|
||||||
|
|
||||||
TYPED_TEST(fuse_test,
|
TYPED_TEST(fuse_test,
|
||||||
chown_can_chown_group_if_owner_and_a_member_of_the_group) {
|
chown_can_chown_group_if_owner_and_a_member_of_the_group) {
|
||||||
|
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "fixtures/fuse_fixture.hpp"
|
#include "fixtures/fuse_fixture.hpp"
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
TYPED_TEST_CASE(fuse_test, fuse_provider_types);
|
TYPED_TEST_SUITE(fuse_test, fuse_provider_types);
|
||||||
|
|
||||||
TYPED_TEST(fuse_test, create_can_create_and_remove_directory) {
|
TYPED_TEST(fuse_test, create_can_create_and_remove_directory) {
|
||||||
std::string dir_name{"create_test"};
|
std::string dir_name{"create_test"};
|
||||||
|
@@ -24,7 +24,7 @@
|
|||||||
#include "fixtures/fuse_fixture.hpp"
|
#include "fixtures/fuse_fixture.hpp"
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
TYPED_TEST_CASE(fuse_test, fuse_provider_types);
|
TYPED_TEST_SUITE(fuse_test, fuse_provider_types);
|
||||||
|
|
||||||
TYPED_TEST(fuse_test, rdrw_can_read_and_write_file) {
|
TYPED_TEST(fuse_test, rdrw_can_read_and_write_file) {
|
||||||
std::string file_name{"create_test"};
|
std::string file_name{"create_test"};
|
||||||
|
@@ -30,7 +30,7 @@ namespace {
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
TYPED_TEST_CASE(meta_db_test, meta_db_types);
|
TYPED_TEST_SUITE(meta_db_test, meta_db_types);
|
||||||
|
|
||||||
TYPED_TEST(meta_db_test, can_get_api_path_from_source_path) {
|
TYPED_TEST(meta_db_test, can_get_api_path_from_source_path) {
|
||||||
auto test_file = create_test_file();
|
auto test_file = create_test_file();
|
||||||
|
@@ -22,156 +22,12 @@
|
|||||||
#include "test_common.hpp"
|
#include "test_common.hpp"
|
||||||
|
|
||||||
#include "fixtures/providers_fixture.hpp"
|
#include "fixtures/providers_fixture.hpp"
|
||||||
|
#include "utils/collection.hpp"
|
||||||
namespace {
|
#include "utils/string.hpp"
|
||||||
#if defined(_WIN32)
|
#include "utils/time.hpp"
|
||||||
using gid_t = std::uint32_t;
|
|
||||||
using uid_t = std::uint32_t;
|
|
||||||
static constexpr auto getgid() -> gid_t { return 0U; }
|
|
||||||
static constexpr auto getuid() -> uid_t { return 0U; }
|
|
||||||
#endif // defined(_WIN32)
|
|
||||||
|
|
||||||
const auto check_forced_dirs = [](const repertory::directory_item_list &list) {
|
|
||||||
static auto forced_dirs = std::array<std::string, 2>{".", ".."};
|
|
||||||
for (std::size_t i = 0U; i < forced_dirs.size(); ++i) {
|
|
||||||
const auto &item = list.at(i);
|
|
||||||
EXPECT_TRUE(item.directory);
|
|
||||||
EXPECT_STREQ(forced_dirs.at(i).c_str(), item.api_path.c_str());
|
|
||||||
EXPECT_STREQ("", item.api_parent.c_str());
|
|
||||||
EXPECT_EQ(std::size_t(0U), item.size);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto create_directory = [](repertory::i_provider &provider,
|
|
||||||
const std::string &api_path) {
|
|
||||||
auto date = repertory::utils::time::get_time_now();
|
|
||||||
auto meta = repertory::create_meta_attributes(
|
|
||||||
date, 1U, date + 1U, date + 2U, true, getgid(), "", 0700, date + 3U, 2U,
|
|
||||||
3U, 0U, api_path + "_src", getuid(), date + 4U);
|
|
||||||
EXPECT_EQ(repertory::api_error::success,
|
|
||||||
provider.create_directory(api_path, meta));
|
|
||||||
|
|
||||||
bool exists{};
|
|
||||||
EXPECT_EQ(repertory::api_error::success,
|
|
||||||
provider.is_directory(api_path, exists));
|
|
||||||
EXPECT_TRUE(exists);
|
|
||||||
|
|
||||||
repertory::api_meta_map meta2{};
|
|
||||||
EXPECT_EQ(repertory::api_error::success,
|
|
||||||
provider.get_item_meta(api_path, meta2));
|
|
||||||
|
|
||||||
EXPECT_EQ(date, repertory::utils::string::to_uint64(
|
|
||||||
meta2[repertory::META_ACCESSED]));
|
|
||||||
EXPECT_EQ(1U, repertory::utils::string::to_uint64(
|
|
||||||
meta2[repertory::META_ATTRIBUTES]));
|
|
||||||
EXPECT_EQ(date + 1U, repertory::utils::string::to_uint64(
|
|
||||||
meta2[repertory::META_CHANGED]));
|
|
||||||
EXPECT_EQ(date + 2U, repertory::utils::string::to_uint64(
|
|
||||||
meta2[repertory::META_CREATION]));
|
|
||||||
EXPECT_TRUE(
|
|
||||||
repertory::utils::string::to_bool(meta2.at(repertory::META_DIRECTORY)));
|
|
||||||
EXPECT_EQ(getgid(), static_cast<gid_t>(repertory::utils::string::to_uint32(
|
|
||||||
meta2[repertory::META_GID])));
|
|
||||||
EXPECT_EQ(std::uint32_t(0700),
|
|
||||||
repertory::utils::string::to_uint32(meta2[repertory::META_MODE]));
|
|
||||||
EXPECT_EQ(date + 3U, repertory::utils::string::to_uint64(
|
|
||||||
meta2[repertory::META_MODIFIED]));
|
|
||||||
EXPECT_EQ(2U,
|
|
||||||
repertory::utils::string::to_uint64(meta2[repertory::META_BACKUP]));
|
|
||||||
EXPECT_EQ(
|
|
||||||
3U, repertory::utils::string::to_uint64(meta2[repertory::META_OSXFLAGS]));
|
|
||||||
EXPECT_FALSE(
|
|
||||||
repertory::utils::string::to_bool(meta2[repertory::META_PINNED]));
|
|
||||||
EXPECT_EQ(std::uint64_t(0U),
|
|
||||||
repertory::utils::string::to_uint64(meta2[repertory::META_SIZE]));
|
|
||||||
EXPECT_EQ(getuid(), static_cast<uid_t>(repertory::utils::string::to_uint32(
|
|
||||||
meta2[repertory::META_UID])));
|
|
||||||
EXPECT_EQ(date + 4U, repertory::utils::string::to_uint64(
|
|
||||||
meta2[repertory::META_WRITTEN]));
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto create_file = [](repertory::i_provider &provider,
|
|
||||||
const std::string &api_path) {
|
|
||||||
auto source_path = repertory::test::generate_test_file_name("providers_test");
|
|
||||||
|
|
||||||
auto date = repertory::utils::time::get_time_now();
|
|
||||||
auto meta = repertory::create_meta_attributes(
|
|
||||||
date, 1U, date + 1U, date + 2U, false, getgid(), "", 0700, date + 3U, 2U,
|
|
||||||
3U, 0U, source_path, getuid(), date + 4U);
|
|
||||||
EXPECT_EQ(repertory::api_error::success,
|
|
||||||
provider.create_file(api_path, meta));
|
|
||||||
|
|
||||||
bool exists{};
|
|
||||||
EXPECT_EQ(repertory::api_error::success, provider.is_file(api_path, exists));
|
|
||||||
EXPECT_TRUE(exists);
|
|
||||||
|
|
||||||
EXPECT_TRUE(repertory::utils::file::file{source_path}.remove());
|
|
||||||
|
|
||||||
repertory::api_meta_map meta2{};
|
|
||||||
EXPECT_EQ(repertory::api_error::success,
|
|
||||||
provider.get_item_meta(api_path, meta2));
|
|
||||||
|
|
||||||
EXPECT_EQ(date, repertory::utils::string::to_uint64(
|
|
||||||
meta2[repertory::META_ACCESSED]));
|
|
||||||
EXPECT_EQ(1U, repertory::utils::string::to_uint64(
|
|
||||||
meta2[repertory::META_ATTRIBUTES]));
|
|
||||||
EXPECT_EQ(date + 1U, repertory::utils::string::to_uint64(
|
|
||||||
meta2[repertory::META_CHANGED]));
|
|
||||||
EXPECT_EQ(date + 2U, repertory::utils::string::to_uint64(
|
|
||||||
meta2[repertory::META_CREATION]));
|
|
||||||
EXPECT_FALSE(
|
|
||||||
repertory::utils::string::to_bool(meta2.at(repertory::META_DIRECTORY)));
|
|
||||||
EXPECT_EQ(getgid(), static_cast<gid_t>(repertory::utils::string::to_uint32(
|
|
||||||
meta2[repertory::META_GID])));
|
|
||||||
EXPECT_EQ(std::uint32_t(0700),
|
|
||||||
repertory::utils::string::to_uint32(meta2[repertory::META_MODE]));
|
|
||||||
EXPECT_EQ(date + 3U, repertory::utils::string::to_uint64(
|
|
||||||
meta2[repertory::META_MODIFIED]));
|
|
||||||
EXPECT_EQ(2U,
|
|
||||||
repertory::utils::string::to_uint64(meta2[repertory::META_BACKUP]));
|
|
||||||
EXPECT_EQ(
|
|
||||||
3U, repertory::utils::string::to_uint64(meta2[repertory::META_OSXFLAGS]));
|
|
||||||
EXPECT_FALSE(
|
|
||||||
repertory::utils::string::to_bool(meta2[repertory::META_PINNED]));
|
|
||||||
EXPECT_EQ(std::uint64_t(0U),
|
|
||||||
repertory::utils::string::to_uint64(meta2[repertory::META_SIZE]));
|
|
||||||
EXPECT_STREQ(source_path.c_str(), meta2[repertory::META_SOURCE].c_str());
|
|
||||||
EXPECT_EQ(getuid(), static_cast<uid_t>(repertory::utils::string::to_uint32(
|
|
||||||
meta2[repertory::META_UID])));
|
|
||||||
EXPECT_EQ(date + 4U, repertory::utils::string::to_uint64(
|
|
||||||
meta2[repertory::META_WRITTEN]));
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto decrypt_parts = [](const repertory::app_config &cfg,
|
|
||||||
std::string &path) {
|
|
||||||
if (path != "/" && path != "." && path != "..") {
|
|
||||||
repertory::utils::hash::hash_256_t key{};
|
|
||||||
EXPECT_TRUE(repertory::utils::encryption::recreate_key_argon2id(
|
|
||||||
cfg.get_encrypt_config().encryption_token,
|
|
||||||
cfg.get_encrypt_config().kdf_cfg, key));
|
|
||||||
auto parts = repertory::utils::string::split(path, '/', false);
|
|
||||||
for (auto &part : parts) {
|
|
||||||
if (part.empty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
EXPECT_TRUE(repertory::utils::encryption::decrypt_file_name(key, part));
|
|
||||||
}
|
|
||||||
path = repertory::utils::string::join(parts, '/');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto pinned_includes_api_path =
|
|
||||||
[](const auto &pinned, const std::string &expected_path) -> bool {
|
|
||||||
return std::ranges::any_of(pinned, [&expected_path](auto &&api_path) -> bool {
|
|
||||||
return api_path == expected_path;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
TYPED_TEST_CASE(providers_test, provider_types);
|
TYPED_TEST_SUITE(providers_test, provider_types);
|
||||||
|
|
||||||
TYPED_TEST(providers_test, get_file_list) {
|
TYPED_TEST(providers_test, get_file_list) {
|
||||||
api_file_list list{};
|
api_file_list list{};
|
||||||
@@ -190,8 +46,8 @@ TYPED_TEST(providers_test, get_file_list) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (auto &file : list) {
|
for (auto &file : list) {
|
||||||
decrypt_parts(*this->config, file.api_parent);
|
this->decrypt_parts(file.api_parent);
|
||||||
decrypt_parts(*this->config, file.api_path);
|
this->decrypt_parts(file.api_path);
|
||||||
utils::collection::remove_element(expected_parents, file.api_parent);
|
utils::collection::remove_element(expected_parents, file.api_parent);
|
||||||
utils::collection::remove_element(expected_paths, file.api_path);
|
utils::collection::remove_element(expected_paths, file.api_path);
|
||||||
}
|
}
|
||||||
@@ -225,7 +81,7 @@ TYPED_TEST(providers_test, get_and_set_item_meta_with_upload_file) {
|
|||||||
auto &file = test::create_random_file(128U);
|
auto &file = test::create_random_file(128U);
|
||||||
auto api_path =
|
auto api_path =
|
||||||
fmt::format("/{}", utils::path::strip_to_file_name(file.get_path()));
|
fmt::format("/{}", utils::path::strip_to_file_name(file.get_path()));
|
||||||
create_file(*this->provider, api_path);
|
this->create_file(api_path);
|
||||||
|
|
||||||
stop_type stop_requested{false};
|
stop_type stop_requested{false};
|
||||||
ASSERT_EQ(api_error::success, this->provider->upload_file(
|
ASSERT_EQ(api_error::success, this->provider->upload_file(
|
||||||
@@ -261,7 +117,7 @@ TYPED_TEST(providers_test, can_create_and_remove_directory) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_directory(*this->provider, "/pt01");
|
this->create_directory("/pt01");
|
||||||
EXPECT_EQ(api_error::success, this->provider->remove_directory("/pt01"));
|
EXPECT_EQ(api_error::success, this->provider->remove_directory("/pt01"));
|
||||||
|
|
||||||
bool exists{};
|
bool exists{};
|
||||||
@@ -290,7 +146,7 @@ TYPED_TEST(providers_test, get_and_set_item_meta2_with_upload_file) {
|
|||||||
auto &file = test::create_random_file(64U);
|
auto &file = test::create_random_file(64U);
|
||||||
auto api_path =
|
auto api_path =
|
||||||
fmt::format("/{}", utils::path::strip_to_file_name(file.get_path()));
|
fmt::format("/{}", utils::path::strip_to_file_name(file.get_path()));
|
||||||
create_file(*this->provider, api_path);
|
this->create_file(api_path);
|
||||||
|
|
||||||
stop_type stop_requested{false};
|
stop_type stop_requested{false};
|
||||||
ASSERT_EQ(api_error::success, this->provider->upload_file(
|
ASSERT_EQ(api_error::success, this->provider->upload_file(
|
||||||
@@ -351,7 +207,7 @@ TYPED_TEST(providers_test, can_create_and_remove_file) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_file(*this->provider, "/pt01.txt");
|
this->create_file("/pt01.txt");
|
||||||
|
|
||||||
bool exists{};
|
bool exists{};
|
||||||
EXPECT_EQ(api_error::success, this->provider->is_file("/pt01.txt", exists));
|
EXPECT_EQ(api_error::success, this->provider->is_file("/pt01.txt", exists));
|
||||||
@@ -368,7 +224,7 @@ TYPED_TEST(providers_test, create_directory_fails_if_already_exists) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_directory(*this->provider, "/pt01");
|
this->create_directory("/pt01");
|
||||||
|
|
||||||
api_meta_map meta{};
|
api_meta_map meta{};
|
||||||
EXPECT_EQ(api_error::directory_exists,
|
EXPECT_EQ(api_error::directory_exists,
|
||||||
@@ -381,7 +237,7 @@ TYPED_TEST(providers_test, create_directory_fails_if_file_already_exists) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_file(*this->provider, "/pt01");
|
this->create_file("/pt01");
|
||||||
|
|
||||||
api_meta_map meta{};
|
api_meta_map meta{};
|
||||||
EXPECT_EQ(api_error::item_exists,
|
EXPECT_EQ(api_error::item_exists,
|
||||||
@@ -397,7 +253,7 @@ TYPED_TEST(providers_test, create_directory_clone_source_meta) {
|
|||||||
this->provider->create_directory_clone_source_meta("/moose", "/moose"));
|
this->provider->create_directory_clone_source_meta("/moose", "/moose"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
create_directory(*this->provider, "/clone");
|
this->create_directory("/clone");
|
||||||
|
|
||||||
api_meta_map meta_orig{};
|
api_meta_map meta_orig{};
|
||||||
EXPECT_EQ(api_error::success,
|
EXPECT_EQ(api_error::success,
|
||||||
@@ -432,8 +288,8 @@ TYPED_TEST(providers_test,
|
|||||||
if (this->provider->is_read_only()) {
|
if (this->provider->is_read_only()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
create_directory(*this->provider, "/clone");
|
this->create_directory("/clone");
|
||||||
create_directory(*this->provider, "/clone2");
|
this->create_directory("/clone2");
|
||||||
|
|
||||||
EXPECT_EQ(
|
EXPECT_EQ(
|
||||||
api_error::directory_exists,
|
api_error::directory_exists,
|
||||||
@@ -460,8 +316,8 @@ TYPED_TEST(providers_test,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_directory(*this->provider, "/clone");
|
this->create_directory("/clone");
|
||||||
create_file(*this->provider, "/clone2");
|
this->create_file("/clone2");
|
||||||
|
|
||||||
EXPECT_EQ(
|
EXPECT_EQ(
|
||||||
api_error::item_exists,
|
api_error::item_exists,
|
||||||
@@ -476,7 +332,7 @@ TYPED_TEST(providers_test, create_file_fails_if_already_exists) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_file(*this->provider, "/pt01.txt");
|
this->create_file("/pt01.txt");
|
||||||
|
|
||||||
api_meta_map meta{};
|
api_meta_map meta{};
|
||||||
EXPECT_EQ(api_error::item_exists,
|
EXPECT_EQ(api_error::item_exists,
|
||||||
@@ -490,7 +346,7 @@ TYPED_TEST(providers_test, create_file_fails_if_directory_already_exists) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_directory(*this->provider, "/pt01");
|
this->create_directory("/pt01");
|
||||||
|
|
||||||
api_meta_map meta{};
|
api_meta_map meta{};
|
||||||
EXPECT_EQ(api_error::directory_exists,
|
EXPECT_EQ(api_error::directory_exists,
|
||||||
@@ -509,12 +365,12 @@ TYPED_TEST(providers_test, get_api_path_from_source) {
|
|||||||
this->provider->get_api_path_from_source(source_path, api_path));
|
this->provider->get_api_path_from_source(source_path, api_path));
|
||||||
|
|
||||||
std::string file_name{api_path.substr(1U)};
|
std::string file_name{api_path.substr(1U)};
|
||||||
decrypt_parts(*this->config, file_name);
|
this->decrypt_parts(file_name);
|
||||||
EXPECT_STREQ("test.txt", file_name.c_str());
|
EXPECT_STREQ("test.txt", file_name.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_file(*this->provider, "/pt01.txt");
|
this->create_file("/pt01.txt");
|
||||||
|
|
||||||
filesystem_item fsi{};
|
filesystem_item fsi{};
|
||||||
EXPECT_EQ(api_error::success,
|
EXPECT_EQ(api_error::success,
|
||||||
@@ -549,14 +405,14 @@ TYPED_TEST(providers_test, get_directory_items) {
|
|||||||
directory_item_list list{};
|
directory_item_list list{};
|
||||||
EXPECT_EQ(api_error::success,
|
EXPECT_EQ(api_error::success,
|
||||||
this->provider->get_directory_items("/", list));
|
this->provider->get_directory_items("/", list));
|
||||||
check_forced_dirs(list);
|
this->check_forced_dirs(list);
|
||||||
|
|
||||||
EXPECT_EQ(std::size_t(4U), list.size());
|
EXPECT_EQ(std::size_t(4U), list.size());
|
||||||
|
|
||||||
directory_item_list list_decrypted{list.begin() + 2U, list.end()};
|
directory_item_list list_decrypted{list.begin() + 2U, list.end()};
|
||||||
for (auto &dir_item : list_decrypted) {
|
for (auto &dir_item : list_decrypted) {
|
||||||
decrypt_parts(*this->config, dir_item.api_parent);
|
this->decrypt_parts(dir_item.api_parent);
|
||||||
decrypt_parts(*this->config, dir_item.api_path);
|
this->decrypt_parts(dir_item.api_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto dir =
|
auto dir =
|
||||||
@@ -590,13 +446,13 @@ TYPED_TEST(providers_test, get_directory_items) {
|
|||||||
list.clear();
|
list.clear();
|
||||||
EXPECT_EQ(api_error::success,
|
EXPECT_EQ(api_error::success,
|
||||||
this->provider->get_directory_items(api_path, list));
|
this->provider->get_directory_items(api_path, list));
|
||||||
check_forced_dirs(list);
|
this->check_forced_dirs(list);
|
||||||
EXPECT_EQ(std::size_t(3U), list.size());
|
EXPECT_EQ(std::size_t(3U), list.size());
|
||||||
|
|
||||||
directory_item_list list_decrypted2{list.begin() + 2U, list.end()};
|
directory_item_list list_decrypted2{list.begin() + 2U, list.end()};
|
||||||
for (auto &dir_item : list_decrypted2) {
|
for (auto &dir_item : list_decrypted2) {
|
||||||
decrypt_parts(*this->config, dir_item.api_parent);
|
this->decrypt_parts(dir_item.api_parent);
|
||||||
decrypt_parts(*this->config, dir_item.api_path);
|
this->decrypt_parts(dir_item.api_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto file2 =
|
auto file2 =
|
||||||
@@ -614,14 +470,14 @@ TYPED_TEST(providers_test, get_directory_items) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_file(*this->provider, "/pt01.txt");
|
this->create_file("/pt01.txt");
|
||||||
create_file(*this->provider, "/pt02.txt");
|
this->create_file("/pt02.txt");
|
||||||
create_directory(*this->provider, "/dir01");
|
this->create_directory("/dir01");
|
||||||
create_directory(*this->provider, "/dir02");
|
this->create_directory("/dir02");
|
||||||
|
|
||||||
directory_item_list list{};
|
directory_item_list list{};
|
||||||
EXPECT_EQ(api_error::success, this->provider->get_directory_items("/", list));
|
EXPECT_EQ(api_error::success, this->provider->get_directory_items("/", list));
|
||||||
check_forced_dirs(list);
|
this->check_forced_dirs(list);
|
||||||
EXPECT_GE(list.size(), std::size_t(6U));
|
EXPECT_GE(list.size(), std::size_t(6U));
|
||||||
|
|
||||||
auto iter = std::ranges::find_if(
|
auto iter = std::ranges::find_if(
|
||||||
@@ -680,7 +536,7 @@ TYPED_TEST(providers_test, get_directory_items_fails_if_item_is_file) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_file(*this->provider, "/pt01.txt");
|
this->create_file("/pt01.txt");
|
||||||
|
|
||||||
directory_item_list list{};
|
directory_item_list list{};
|
||||||
EXPECT_EQ(api_error::item_exists,
|
EXPECT_EQ(api_error::item_exists,
|
||||||
@@ -705,14 +561,14 @@ TYPED_TEST(providers_test, get_directory_item_count) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_file(*this->provider, "/pt01.txt");
|
this->create_file("/pt01.txt");
|
||||||
create_file(*this->provider, "/pt02.txt");
|
this->create_file("/pt02.txt");
|
||||||
create_directory(*this->provider, "/dir01");
|
this->create_directory("/dir01");
|
||||||
create_directory(*this->provider, "/dir02");
|
this->create_directory("/dir02");
|
||||||
|
|
||||||
directory_item_list list{};
|
directory_item_list list{};
|
||||||
EXPECT_EQ(api_error::success, this->provider->get_directory_items("/", list));
|
EXPECT_EQ(api_error::success, this->provider->get_directory_items("/", list));
|
||||||
check_forced_dirs(list);
|
this->check_forced_dirs(list);
|
||||||
EXPECT_GE(list.size(), std::size_t(6U));
|
EXPECT_GE(list.size(), std::size_t(6U));
|
||||||
|
|
||||||
EXPECT_EQ(api_error::success, this->provider->remove_file("/pt01.txt"));
|
EXPECT_EQ(api_error::success, this->provider->remove_file("/pt01.txt"));
|
||||||
@@ -732,8 +588,8 @@ TYPED_TEST(providers_test, get_file) {
|
|||||||
|
|
||||||
api_file file{};
|
api_file file{};
|
||||||
EXPECT_EQ(api_error::success, this->provider->get_file(api_path, file));
|
EXPECT_EQ(api_error::success, this->provider->get_file(api_path, file));
|
||||||
decrypt_parts(*this->config, file.api_path);
|
this->decrypt_parts(file.api_path);
|
||||||
decrypt_parts(*this->config, file.api_parent);
|
this->decrypt_parts(file.api_parent);
|
||||||
|
|
||||||
EXPECT_STREQ("/test.txt", file.api_path.c_str());
|
EXPECT_STREQ("/test.txt", file.api_path.c_str());
|
||||||
EXPECT_STREQ("/", file.api_parent.c_str());
|
EXPECT_STREQ("/", file.api_parent.c_str());
|
||||||
@@ -746,7 +602,7 @@ TYPED_TEST(providers_test, get_file) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_file(*this->provider, "/pt01.txt");
|
this->create_file("/pt01.txt");
|
||||||
|
|
||||||
api_file file{};
|
api_file file{};
|
||||||
EXPECT_EQ(api_error::success, this->provider->get_file("/pt01.txt", file));
|
EXPECT_EQ(api_error::success, this->provider->get_file("/pt01.txt", file));
|
||||||
@@ -785,7 +641,7 @@ TYPED_TEST(providers_test, get_file_fails_if_item_is_directory) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_directory(*this->provider, "/dir01");
|
this->create_directory("/dir01");
|
||||||
|
|
||||||
api_file file{};
|
api_file file{};
|
||||||
EXPECT_EQ(api_error::directory_exists,
|
EXPECT_EQ(api_error::directory_exists,
|
||||||
@@ -816,7 +672,7 @@ TYPED_TEST(providers_test, get_file_size) {
|
|||||||
auto &file = test::create_random_file(128U);
|
auto &file = test::create_random_file(128U);
|
||||||
auto api_path =
|
auto api_path =
|
||||||
fmt::format("/{}", utils::path::strip_to_file_name(file.get_path()));
|
fmt::format("/{}", utils::path::strip_to_file_name(file.get_path()));
|
||||||
create_file(*this->provider, api_path);
|
this->create_file(api_path);
|
||||||
|
|
||||||
stop_type stop_requested{false};
|
stop_type stop_requested{false};
|
||||||
auto res =
|
auto res =
|
||||||
@@ -867,7 +723,7 @@ TYPED_TEST(providers_test, get_filesystem_item) {
|
|||||||
auto &file = test::create_random_file(128U);
|
auto &file = test::create_random_file(128U);
|
||||||
auto api_path =
|
auto api_path =
|
||||||
fmt::format("/{}", utils::path::strip_to_file_name(file.get_path()));
|
fmt::format("/{}", utils::path::strip_to_file_name(file.get_path()));
|
||||||
create_file(*this->provider, api_path);
|
this->create_file(api_path);
|
||||||
|
|
||||||
stop_type stop_requested{false};
|
stop_type stop_requested{false};
|
||||||
auto res =
|
auto res =
|
||||||
@@ -930,7 +786,7 @@ TYPED_TEST(providers_test, get_filesystem_item_from_source_path) {
|
|||||||
api_path =
|
api_path =
|
||||||
fmt::format("/{}", utils::path::strip_to_file_name(file.get_path()));
|
fmt::format("/{}", utils::path::strip_to_file_name(file.get_path()));
|
||||||
source_path = file.get_path();
|
source_path = file.get_path();
|
||||||
create_file(*this->provider, api_path);
|
this->create_file(api_path);
|
||||||
|
|
||||||
EXPECT_EQ(api_error::success,
|
EXPECT_EQ(api_error::success,
|
||||||
this->provider->set_item_meta(
|
this->provider->set_item_meta(
|
||||||
@@ -980,7 +836,7 @@ TYPED_TEST(providers_test, remove_file_fails_if_item_is_directory) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_directory(*this->provider, "/dir01");
|
this->create_directory("/dir01");
|
||||||
EXPECT_EQ(api_error::directory_exists, this->provider->remove_file("/dir01"));
|
EXPECT_EQ(api_error::directory_exists, this->provider->remove_file("/dir01"));
|
||||||
EXPECT_EQ(api_error::success, this->provider->remove_directory("/dir01"));
|
EXPECT_EQ(api_error::success, this->provider->remove_directory("/dir01"));
|
||||||
}
|
}
|
||||||
@@ -992,7 +848,7 @@ TYPED_TEST(providers_test, remove_directory_fails_if_item_is_file) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_file(*this->provider, "/pt01.txt");
|
this->create_file("/pt01.txt");
|
||||||
EXPECT_EQ(api_error::item_not_found,
|
EXPECT_EQ(api_error::item_not_found,
|
||||||
this->provider->remove_directory("/pt01.txt"));
|
this->provider->remove_directory("/pt01.txt"));
|
||||||
EXPECT_EQ(api_error::success, this->provider->remove_file("/pt01.txt"));
|
EXPECT_EQ(api_error::success, this->provider->remove_file("/pt01.txt"));
|
||||||
@@ -1014,9 +870,9 @@ TYPED_TEST(providers_test, get_pinned_files) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_file(*this->provider, "/pin01.txt");
|
this->create_file("/pin01.txt");
|
||||||
create_file(*this->provider, "/pin02.txt");
|
this->create_file("/pin02.txt");
|
||||||
create_file(*this->provider, "/nopin01.txt");
|
this->create_file("/nopin01.txt");
|
||||||
|
|
||||||
EXPECT_EQ(api_error::success,
|
EXPECT_EQ(api_error::success,
|
||||||
this->provider->set_item_meta("/pin01.txt", META_PINNED, "true"));
|
this->provider->set_item_meta("/pin01.txt", META_PINNED, "true"));
|
||||||
@@ -1028,9 +884,9 @@ TYPED_TEST(providers_test, get_pinned_files) {
|
|||||||
auto pinned = this->provider->get_pinned_files();
|
auto pinned = this->provider->get_pinned_files();
|
||||||
EXPECT_EQ(std::size_t(2U), pinned.size());
|
EXPECT_EQ(std::size_t(2U), pinned.size());
|
||||||
|
|
||||||
EXPECT_TRUE(pinned_includes_api_path(pinned, "/pin01.txt"));
|
EXPECT_TRUE(this->pinned_includes_api_path(pinned, "/pin01.txt"));
|
||||||
EXPECT_TRUE(pinned_includes_api_path(pinned, "/pin02.txt"));
|
EXPECT_TRUE(this->pinned_includes_api_path(pinned, "/pin02.txt"));
|
||||||
EXPECT_FALSE(pinned_includes_api_path(pinned, "/nopin01.txt"));
|
EXPECT_FALSE(this->pinned_includes_api_path(pinned, "/nopin01.txt"));
|
||||||
|
|
||||||
EXPECT_EQ(api_error::success, this->provider->remove_file("/pin01.txt"));
|
EXPECT_EQ(api_error::success, this->provider->remove_file("/pin01.txt"));
|
||||||
EXPECT_EQ(api_error::success, this->provider->remove_file("/pin02.txt"));
|
EXPECT_EQ(api_error::success, this->provider->remove_file("/pin02.txt"));
|
||||||
@@ -1044,8 +900,8 @@ TYPED_TEST(providers_test, remove_pin_updates_pinned_files) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_file(*this->provider, "/pin01.txt");
|
this->create_file("/pin01.txt");
|
||||||
create_file(*this->provider, "/pin02.txt");
|
this->create_file("/pin02.txt");
|
||||||
EXPECT_EQ(api_error::success,
|
EXPECT_EQ(api_error::success,
|
||||||
this->provider->set_item_meta("/pin01.txt", META_PINNED, "true"));
|
this->provider->set_item_meta("/pin01.txt", META_PINNED, "true"));
|
||||||
EXPECT_EQ(api_error::success,
|
EXPECT_EQ(api_error::success,
|
||||||
@@ -1058,8 +914,8 @@ TYPED_TEST(providers_test, remove_pin_updates_pinned_files) {
|
|||||||
this->provider->set_item_meta("/pin02.txt", META_PINNED, "false"));
|
this->provider->set_item_meta("/pin02.txt", META_PINNED, "false"));
|
||||||
pinned = this->provider->get_pinned_files();
|
pinned = this->provider->get_pinned_files();
|
||||||
EXPECT_EQ(std::size_t(1U), pinned.size());
|
EXPECT_EQ(std::size_t(1U), pinned.size());
|
||||||
EXPECT_TRUE(pinned_includes_api_path(pinned, "/pin01.txt"));
|
EXPECT_TRUE(this->pinned_includes_api_path(pinned, "/pin01.txt"));
|
||||||
EXPECT_FALSE(pinned_includes_api_path(pinned, "/pin02.txt"));
|
EXPECT_FALSE(this->pinned_includes_api_path(pinned, "/pin02.txt"));
|
||||||
|
|
||||||
EXPECT_EQ(api_error::success,
|
EXPECT_EQ(api_error::success,
|
||||||
this->provider->set_item_meta("/pin01.txt", META_PINNED, "false"));
|
this->provider->set_item_meta("/pin01.txt", META_PINNED, "false"));
|
||||||
@@ -1077,9 +933,9 @@ TYPED_TEST(providers_test, remove_file_updates_pinned_files) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_file(*this->provider, "/pin_keep.txt");
|
this->create_file("/pin_keep.txt");
|
||||||
create_file(*this->provider, "/pin_delete.txt");
|
this->create_file("/pin_delete.txt");
|
||||||
create_file(*this->provider, "/nopin.txt");
|
this->create_file("/nopin.txt");
|
||||||
|
|
||||||
EXPECT_EQ(api_error::success, this->provider->set_item_meta(
|
EXPECT_EQ(api_error::success, this->provider->set_item_meta(
|
||||||
"/pin_keep.txt", META_PINNED, "true"));
|
"/pin_keep.txt", META_PINNED, "true"));
|
||||||
@@ -1091,16 +947,16 @@ TYPED_TEST(providers_test, remove_file_updates_pinned_files) {
|
|||||||
auto pinned = this->provider->get_pinned_files();
|
auto pinned = this->provider->get_pinned_files();
|
||||||
EXPECT_EQ(std::size_t(2U), pinned.size());
|
EXPECT_EQ(std::size_t(2U), pinned.size());
|
||||||
|
|
||||||
EXPECT_TRUE(pinned_includes_api_path(pinned, "/pin_keep.txt"));
|
EXPECT_TRUE(this->pinned_includes_api_path(pinned, "/pin_keep.txt"));
|
||||||
EXPECT_TRUE(pinned_includes_api_path(pinned, "/pin_delete.txt"));
|
EXPECT_TRUE(this->pinned_includes_api_path(pinned, "/pin_delete.txt"));
|
||||||
EXPECT_FALSE(pinned_includes_api_path(pinned, "/nopin.txt"));
|
EXPECT_FALSE(this->pinned_includes_api_path(pinned, "/nopin.txt"));
|
||||||
|
|
||||||
EXPECT_EQ(api_error::success, this->provider->remove_file("/pin_delete.txt"));
|
EXPECT_EQ(api_error::success, this->provider->remove_file("/pin_delete.txt"));
|
||||||
|
|
||||||
pinned = this->provider->get_pinned_files();
|
pinned = this->provider->get_pinned_files();
|
||||||
EXPECT_EQ(std::size_t(1U), pinned.size());
|
EXPECT_EQ(std::size_t(1U), pinned.size());
|
||||||
EXPECT_TRUE(pinned_includes_api_path(pinned, "/pin_keep.txt"));
|
EXPECT_TRUE(this->pinned_includes_api_path(pinned, "/pin_keep.txt"));
|
||||||
EXPECT_FALSE(pinned_includes_api_path(pinned, "/pin_delete.txt"));
|
EXPECT_FALSE(this->pinned_includes_api_path(pinned, "/pin_delete.txt"));
|
||||||
|
|
||||||
EXPECT_EQ(api_error::success, this->provider->remove_file("/pin_keep.txt"));
|
EXPECT_EQ(api_error::success, this->provider->remove_file("/pin_keep.txt"));
|
||||||
EXPECT_EQ(api_error::success, this->provider->remove_file("/nopin.txt"));
|
EXPECT_EQ(api_error::success, this->provider->remove_file("/nopin.txt"));
|
||||||
@@ -1116,8 +972,8 @@ TYPED_TEST(providers_test, get_total_item_count) {
|
|||||||
|
|
||||||
std::uint64_t before{this->provider->get_total_item_count()};
|
std::uint64_t before{this->provider->get_total_item_count()};
|
||||||
|
|
||||||
create_file(*this->provider, "/count01.txt");
|
this->create_file("/count01.txt");
|
||||||
create_file(*this->provider, "/count02.txt");
|
this->create_file("/count02.txt");
|
||||||
|
|
||||||
std::uint64_t mid{this->provider->get_total_item_count()};
|
std::uint64_t mid{this->provider->get_total_item_count()};
|
||||||
EXPECT_EQ(before + 2U, mid);
|
EXPECT_EQ(before + 2U, mid);
|
||||||
@@ -1159,8 +1015,8 @@ TYPED_TEST(providers_test, get_used_drive_space) {
|
|||||||
auto api_path2 =
|
auto api_path2 =
|
||||||
fmt::format("/{}", utils::path::strip_to_file_name(file2.get_path()));
|
fmt::format("/{}", utils::path::strip_to_file_name(file2.get_path()));
|
||||||
|
|
||||||
create_file(*this->provider, api_path1);
|
this->create_file(api_path1);
|
||||||
create_file(*this->provider, api_path2);
|
this->create_file(api_path2);
|
||||||
|
|
||||||
stop_type stop_requested{false};
|
stop_type stop_requested{false};
|
||||||
ASSERT_EQ(
|
ASSERT_EQ(
|
||||||
@@ -1203,7 +1059,7 @@ TYPED_TEST(providers_test, remove_item_meta) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_file(*this->provider, api_path);
|
this->create_file(api_path);
|
||||||
|
|
||||||
EXPECT_EQ(api_error::success,
|
EXPECT_EQ(api_error::success,
|
||||||
this->provider->set_item_meta(api_path, "user.custom", "abc123"));
|
this->provider->set_item_meta(api_path, "user.custom", "abc123"));
|
||||||
@@ -1245,7 +1101,7 @@ TYPED_TEST(providers_test, remove_item_meta_restricted_names_fail) {
|
|||||||
this->provider->get_api_path_from_source(source_path, api_path));
|
this->provider->get_api_path_from_source(source_path, api_path));
|
||||||
} else {
|
} else {
|
||||||
api_path = "/rim_restricted.txt";
|
api_path = "/rim_restricted.txt";
|
||||||
create_file(*this->provider, api_path);
|
this->create_file(api_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &key : META_USED_NAMES) {
|
for (const auto &key : META_USED_NAMES) {
|
||||||
@@ -1272,7 +1128,7 @@ TYPED_TEST(providers_test, rename_file) {
|
|||||||
|
|
||||||
std::string src{"/rn_src.txt"};
|
std::string src{"/rn_src.txt"};
|
||||||
std::string dst{"/rn_dst.txt"};
|
std::string dst{"/rn_dst.txt"};
|
||||||
create_file(*this->provider, src);
|
this->create_file(src);
|
||||||
|
|
||||||
std::string src_meta_size{};
|
std::string src_meta_size{};
|
||||||
std::string src_meta_source{};
|
std::string src_meta_source{};
|
||||||
@@ -1316,8 +1172,8 @@ TYPED_TEST(providers_test, rename_file_fails_if_source_not_found) {
|
|||||||
TYPED_TEST(providers_test, rename_file_fails_if_destination_exists) {
|
TYPED_TEST(providers_test, rename_file_fails_if_destination_exists) {
|
||||||
if (not this->provider->is_rename_supported()) {
|
if (not this->provider->is_rename_supported()) {
|
||||||
if (this->provider->get_provider_type() != provider_type::encrypt) {
|
if (this->provider->get_provider_type() != provider_type::encrypt) {
|
||||||
create_file(*this->provider, "/rn_src_conflict.txt");
|
this->create_file("/rn_src_conflict.txt");
|
||||||
create_file(*this->provider, "/rn_dst_conflict.txt");
|
this->create_file("/rn_dst_conflict.txt");
|
||||||
}
|
}
|
||||||
auto res = this->provider->rename_file("/rn_src_conflict.txt",
|
auto res = this->provider->rename_file("/rn_src_conflict.txt",
|
||||||
"/rn_dst_conflict.txt");
|
"/rn_dst_conflict.txt");
|
||||||
@@ -1334,8 +1190,8 @@ TYPED_TEST(providers_test, rename_file_fails_if_destination_exists) {
|
|||||||
|
|
||||||
std::string src{"/rn_src_conflict.txt"};
|
std::string src{"/rn_src_conflict.txt"};
|
||||||
std::string dst{"/rn_dst_conflict.txt"};
|
std::string dst{"/rn_dst_conflict.txt"};
|
||||||
create_file(*this->provider, src);
|
this->create_file(src);
|
||||||
create_file(*this->provider, dst);
|
this->create_file(dst);
|
||||||
|
|
||||||
auto res = this->provider->rename_file(src, dst);
|
auto res = this->provider->rename_file(src, dst);
|
||||||
EXPECT_EQ(api_error::item_exists, res);
|
EXPECT_EQ(api_error::item_exists, res);
|
||||||
@@ -1353,8 +1209,8 @@ TYPED_TEST(providers_test, rename_file_fails_if_destination_exists) {
|
|||||||
TYPED_TEST(providers_test, rename_file_fails_if_destination_is_directory) {
|
TYPED_TEST(providers_test, rename_file_fails_if_destination_is_directory) {
|
||||||
if (not this->provider->is_rename_supported()) {
|
if (not this->provider->is_rename_supported()) {
|
||||||
if (this->provider->get_provider_type() != provider_type::encrypt) {
|
if (this->provider->get_provider_type() != provider_type::encrypt) {
|
||||||
create_file(*this->provider, "/rn_src_conflict.txt");
|
this->create_file("/rn_src_conflict.txt");
|
||||||
create_directory(*this->provider, "/rn_dst_conflict");
|
this->create_directory("/rn_dst_conflict");
|
||||||
}
|
}
|
||||||
auto res =
|
auto res =
|
||||||
this->provider->rename_file("/rn_src_conflict.txt", "/rn_dst_conflict");
|
this->provider->rename_file("/rn_src_conflict.txt", "/rn_dst_conflict");
|
||||||
@@ -1371,8 +1227,8 @@ TYPED_TEST(providers_test, rename_file_fails_if_destination_is_directory) {
|
|||||||
|
|
||||||
std::string src{"/rn_src_conflict.txt"};
|
std::string src{"/rn_src_conflict.txt"};
|
||||||
std::string dst{"/rn_dst_conflict"};
|
std::string dst{"/rn_dst_conflict"};
|
||||||
create_file(*this->provider, src);
|
this->create_file(src);
|
||||||
create_directory(*this->provider, dst);
|
this->create_directory(dst);
|
||||||
|
|
||||||
auto res = this->provider->rename_file(src, dst);
|
auto res = this->provider->rename_file(src, dst);
|
||||||
EXPECT_EQ(api_error::directory_exists, res);
|
EXPECT_EQ(api_error::directory_exists, res);
|
||||||
@@ -1386,4 +1242,50 @@ TYPED_TEST(providers_test, rename_file_fails_if_destination_is_directory) {
|
|||||||
EXPECT_EQ(api_error::success, this->provider->remove_file(src));
|
EXPECT_EQ(api_error::success, this->provider->remove_file(src));
|
||||||
EXPECT_EQ(api_error::success, this->provider->remove_directory(dst));
|
EXPECT_EQ(api_error::success, this->provider->remove_directory(dst));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TYPED_TEST(providers_test, upload_file_not_implemented_on_read_only) {
|
||||||
|
if (not this->provider->is_read_only()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto &file = test::create_random_file(16U);
|
||||||
|
stop_type stop_requested{false};
|
||||||
|
auto res = this->provider->upload_file("/ro_upload.txt", file.get_path(),
|
||||||
|
stop_requested);
|
||||||
|
EXPECT_EQ(api_error::not_implemented, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPED_TEST(providers_test, upload_file_fails_if_source_not_found) {
|
||||||
|
if (this->provider->is_read_only()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
stop_type stop_requested{false};
|
||||||
|
auto res = this->provider->upload_file(
|
||||||
|
"/no_src_upload.txt", "/path/does/not/exist.bin", stop_requested);
|
||||||
|
EXPECT_EQ(api_error::item_not_found, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
TYPED_TEST(providers_test, is_file_is_directory_cross_checks) {
|
||||||
|
if (this->provider->is_read_only()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string file_api_path{"/xf_file.txt"};
|
||||||
|
std::string dir_api_path{"/xd_dir"};
|
||||||
|
|
||||||
|
this->create_file(file_api_path);
|
||||||
|
this->create_directory(dir_api_path);
|
||||||
|
|
||||||
|
bool exists{};
|
||||||
|
EXPECT_EQ(api_error::success,
|
||||||
|
this->provider->is_directory(file_api_path, exists));
|
||||||
|
EXPECT_FALSE(exists);
|
||||||
|
|
||||||
|
EXPECT_EQ(api_error::success, this->provider->is_file(dir_api_path, exists));
|
||||||
|
EXPECT_FALSE(exists);
|
||||||
|
|
||||||
|
EXPECT_EQ(api_error::success, this->provider->remove_file(file_api_path));
|
||||||
|
EXPECT_EQ(api_error::success, this->provider->remove_directory(dir_api_path));
|
||||||
|
}
|
||||||
} // namespace repertory
|
} // namespace repertory
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
#include "fixtures/winfsp_fixture.hpp"
|
#include "fixtures/winfsp_fixture.hpp"
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
TYPED_TEST_CASE(winfsp_test, winfsp_provider_types);
|
TYPED_TEST_SUITE(winfsp_test, winfsp_provider_types);
|
||||||
|
|
||||||
TYPED_TEST(winfsp_test, cr8_attr_can_create_new_file_with_normal_attribute) {
|
TYPED_TEST(winfsp_test, cr8_attr_can_create_new_file_with_normal_attribute) {
|
||||||
auto file_path{
|
auto file_path{
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
#include "fixtures/winfsp_fixture.hpp"
|
#include "fixtures/winfsp_fixture.hpp"
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
TYPED_TEST_CASE(winfsp_test, winfsp_provider_types);
|
TYPED_TEST_SUITE(winfsp_test, winfsp_provider_types);
|
||||||
|
|
||||||
TYPED_TEST(winfsp_test, cr8_nl_can_create_file_of_max_component_length) {
|
TYPED_TEST(winfsp_test, cr8_nl_can_create_file_of_max_component_length) {
|
||||||
if (this->current_provider == provider_type::s3) {
|
if (this->current_provider == provider_type::s3) {
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
#include "fixtures/winfsp_fixture.hpp"
|
#include "fixtures/winfsp_fixture.hpp"
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
TYPED_TEST_CASE(winfsp_test, winfsp_provider_types);
|
TYPED_TEST_SUITE(winfsp_test, winfsp_provider_types);
|
||||||
|
|
||||||
TYPED_TEST(winfsp_test, cr8_file_can_create_file) {
|
TYPED_TEST(winfsp_test, cr8_file_can_create_file) {
|
||||||
auto file_path{
|
auto file_path{
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
#include "fixtures/winfsp_fixture.hpp"
|
#include "fixtures/winfsp_fixture.hpp"
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
TYPED_TEST_CASE(winfsp_test, winfsp_provider_types);
|
TYPED_TEST_SUITE(winfsp_test, winfsp_provider_types);
|
||||||
|
|
||||||
TYPED_TEST(winfsp_test, delete_directory_fails_if_directory_not_empty) {
|
TYPED_TEST(winfsp_test, delete_directory_fails_if_directory_not_empty) {
|
||||||
auto dir_path{
|
auto dir_path{
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
#include "fixtures/winfsp_fixture.hpp"
|
#include "fixtures/winfsp_fixture.hpp"
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
TYPED_TEST_CASE(winfsp_test, winfsp_provider_types);
|
TYPED_TEST_SUITE(winfsp_test, winfsp_provider_types);
|
||||||
|
|
||||||
TYPED_TEST(winfsp_test, info_can_get_tag_info) {
|
TYPED_TEST(winfsp_test, info_can_get_tag_info) {
|
||||||
auto file_path{
|
auto file_path{
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
#include "fixtures/winfsp_fixture.hpp"
|
#include "fixtures/winfsp_fixture.hpp"
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
TYPED_TEST_CASE(winfsp_test, winfsp_provider_types);
|
TYPED_TEST_SUITE(winfsp_test, winfsp_provider_types);
|
||||||
|
|
||||||
static void test_file(auto &&mount_location, auto &&file_path, auto &&flags) {
|
static void test_file(auto &&mount_location, auto &&file_path, auto &&flags) {
|
||||||
SYSTEM_INFO sys_info{};
|
SYSTEM_INFO sys_info{};
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
#include "fixtures/winfsp_fixture.hpp"
|
#include "fixtures/winfsp_fixture.hpp"
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
TYPED_TEST_CASE(winfsp_test, winfsp_provider_types);
|
TYPED_TEST_SUITE(winfsp_test, winfsp_provider_types);
|
||||||
|
|
||||||
TYPED_TEST(winfsp_test, rename_can_rename_file_if_dest_does_not_exist) {
|
TYPED_TEST(winfsp_test, rename_can_rename_file_if_dest_does_not_exist) {
|
||||||
if (this->current_provider == provider_type::s3) {
|
if (this->current_provider == provider_type::s3) {
|
||||||
|
@@ -49,7 +49,7 @@
|
|||||||
#include "fixtures/winfsp_fixture.hpp"
|
#include "fixtures/winfsp_fixture.hpp"
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
TYPED_TEST_CASE(winfsp_test, winfsp_provider_types);
|
TYPED_TEST_SUITE(winfsp_test, winfsp_provider_types);
|
||||||
|
|
||||||
TYPED_TEST(winfsp_test, can_set_current_directory_to_mount_location) {
|
TYPED_TEST(winfsp_test, can_set_current_directory_to_mount_location) {
|
||||||
EXPECT_TRUE(::SetCurrentDirectoryA(this->mount_location.c_str()));
|
EXPECT_TRUE(::SetCurrentDirectoryA(this->mount_location.c_str()));
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
#include "fixtures/winfsp_fixture.hpp"
|
#include "fixtures/winfsp_fixture.hpp"
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
TYPED_TEST_CASE(winfsp_test, winfsp_provider_types);
|
TYPED_TEST_SUITE(winfsp_test, winfsp_provider_types);
|
||||||
|
|
||||||
TYPED_TEST(winfsp_test, volume_can_get_volume_info) {
|
TYPED_TEST(winfsp_test, volume_can_get_volume_info) {
|
||||||
std::string volume_label;
|
std::string volume_label;
|
||||||
|
Reference in New Issue
Block a user