|
|
|
@@ -22,156 +22,12 @@
|
|
|
|
|
#include "test_common.hpp"
|
|
|
|
|
|
|
|
|
|
#include "fixtures/providers_fixture.hpp"
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
|
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
|
|
|
|
|
#include "utils/collection.hpp"
|
|
|
|
|
#include "utils/string.hpp"
|
|
|
|
|
#include "utils/time.hpp"
|
|
|
|
|
|
|
|
|
|
namespace repertory {
|
|
|
|
|
TYPED_TEST_CASE(providers_test, provider_types);
|
|
|
|
|
TYPED_TEST_SUITE(providers_test, provider_types);
|
|
|
|
|
|
|
|
|
|
TYPED_TEST(providers_test, get_file_list) {
|
|
|
|
|
api_file_list list{};
|
|
|
|
@@ -190,8 +46,8 @@ TYPED_TEST(providers_test, get_file_list) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (auto &file : list) {
|
|
|
|
|
decrypt_parts(*this->config, file.api_parent);
|
|
|
|
|
decrypt_parts(*this->config, file.api_path);
|
|
|
|
|
this->decrypt_parts(file.api_parent);
|
|
|
|
|
this->decrypt_parts(file.api_path);
|
|
|
|
|
utils::collection::remove_element(expected_parents, file.api_parent);
|
|
|
|
|
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 api_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};
|
|
|
|
|
ASSERT_EQ(api_error::success, this->provider->upload_file(
|
|
|
|
@@ -261,7 +117,7 @@ TYPED_TEST(providers_test, can_create_and_remove_directory) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_directory(*this->provider, "/pt01");
|
|
|
|
|
this->create_directory("/pt01");
|
|
|
|
|
EXPECT_EQ(api_error::success, this->provider->remove_directory("/pt01"));
|
|
|
|
|
|
|
|
|
|
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 api_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};
|
|
|
|
|
ASSERT_EQ(api_error::success, this->provider->upload_file(
|
|
|
|
@@ -351,7 +207,7 @@ TYPED_TEST(providers_test, can_create_and_remove_file) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_file(*this->provider, "/pt01.txt");
|
|
|
|
|
this->create_file("/pt01.txt");
|
|
|
|
|
|
|
|
|
|
bool 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_directory(*this->provider, "/pt01");
|
|
|
|
|
this->create_directory("/pt01");
|
|
|
|
|
|
|
|
|
|
api_meta_map meta{};
|
|
|
|
|
EXPECT_EQ(api_error::directory_exists,
|
|
|
|
@@ -381,7 +237,7 @@ TYPED_TEST(providers_test, create_directory_fails_if_file_already_exists) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_file(*this->provider, "/pt01");
|
|
|
|
|
this->create_file("/pt01");
|
|
|
|
|
|
|
|
|
|
api_meta_map meta{};
|
|
|
|
|
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"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
create_directory(*this->provider, "/clone");
|
|
|
|
|
this->create_directory("/clone");
|
|
|
|
|
|
|
|
|
|
api_meta_map meta_orig{};
|
|
|
|
|
EXPECT_EQ(api_error::success,
|
|
|
|
@@ -432,8 +288,8 @@ TYPED_TEST(providers_test,
|
|
|
|
|
if (this->provider->is_read_only()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
create_directory(*this->provider, "/clone");
|
|
|
|
|
create_directory(*this->provider, "/clone2");
|
|
|
|
|
this->create_directory("/clone");
|
|
|
|
|
this->create_directory("/clone2");
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(
|
|
|
|
|
api_error::directory_exists,
|
|
|
|
@@ -460,8 +316,8 @@ TYPED_TEST(providers_test,
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_directory(*this->provider, "/clone");
|
|
|
|
|
create_file(*this->provider, "/clone2");
|
|
|
|
|
this->create_directory("/clone");
|
|
|
|
|
this->create_file("/clone2");
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(
|
|
|
|
|
api_error::item_exists,
|
|
|
|
@@ -476,7 +332,7 @@ TYPED_TEST(providers_test, create_file_fails_if_already_exists) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_file(*this->provider, "/pt01.txt");
|
|
|
|
|
this->create_file("/pt01.txt");
|
|
|
|
|
|
|
|
|
|
api_meta_map meta{};
|
|
|
|
|
EXPECT_EQ(api_error::item_exists,
|
|
|
|
@@ -490,7 +346,7 @@ TYPED_TEST(providers_test, create_file_fails_if_directory_already_exists) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_directory(*this->provider, "/pt01");
|
|
|
|
|
this->create_directory("/pt01");
|
|
|
|
|
|
|
|
|
|
api_meta_map meta{};
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_file(*this->provider, "/pt01.txt");
|
|
|
|
|
this->create_file("/pt01.txt");
|
|
|
|
|
|
|
|
|
|
filesystem_item fsi{};
|
|
|
|
|
EXPECT_EQ(api_error::success,
|
|
|
|
@@ -549,14 +405,14 @@ TYPED_TEST(providers_test, get_directory_items) {
|
|
|
|
|
directory_item_list list{};
|
|
|
|
|
EXPECT_EQ(api_error::success,
|
|
|
|
|
this->provider->get_directory_items("/", list));
|
|
|
|
|
check_forced_dirs(list);
|
|
|
|
|
this->check_forced_dirs(list);
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(std::size_t(4U), list.size());
|
|
|
|
|
|
|
|
|
|
directory_item_list list_decrypted{list.begin() + 2U, list.end()};
|
|
|
|
|
for (auto &dir_item : list_decrypted) {
|
|
|
|
|
decrypt_parts(*this->config, dir_item.api_parent);
|
|
|
|
|
decrypt_parts(*this->config, dir_item.api_path);
|
|
|
|
|
this->decrypt_parts(dir_item.api_parent);
|
|
|
|
|
this->decrypt_parts(dir_item.api_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto dir =
|
|
|
|
@@ -590,13 +446,13 @@ TYPED_TEST(providers_test, get_directory_items) {
|
|
|
|
|
list.clear();
|
|
|
|
|
EXPECT_EQ(api_error::success,
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
directory_item_list list_decrypted2{list.begin() + 2U, list.end()};
|
|
|
|
|
for (auto &dir_item : list_decrypted2) {
|
|
|
|
|
decrypt_parts(*this->config, dir_item.api_parent);
|
|
|
|
|
decrypt_parts(*this->config, dir_item.api_path);
|
|
|
|
|
this->decrypt_parts(dir_item.api_parent);
|
|
|
|
|
this->decrypt_parts(dir_item.api_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto file2 =
|
|
|
|
@@ -614,14 +470,14 @@ TYPED_TEST(providers_test, get_directory_items) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_file(*this->provider, "/pt01.txt");
|
|
|
|
|
create_file(*this->provider, "/pt02.txt");
|
|
|
|
|
create_directory(*this->provider, "/dir01");
|
|
|
|
|
create_directory(*this->provider, "/dir02");
|
|
|
|
|
this->create_file("/pt01.txt");
|
|
|
|
|
this->create_file("/pt02.txt");
|
|
|
|
|
this->create_directory("/dir01");
|
|
|
|
|
this->create_directory("/dir02");
|
|
|
|
|
|
|
|
|
|
directory_item_list 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));
|
|
|
|
|
|
|
|
|
|
auto iter = std::ranges::find_if(
|
|
|
|
@@ -680,7 +536,7 @@ TYPED_TEST(providers_test, get_directory_items_fails_if_item_is_file) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_file(*this->provider, "/pt01.txt");
|
|
|
|
|
this->create_file("/pt01.txt");
|
|
|
|
|
|
|
|
|
|
directory_item_list list{};
|
|
|
|
|
EXPECT_EQ(api_error::item_exists,
|
|
|
|
@@ -705,14 +561,14 @@ TYPED_TEST(providers_test, get_directory_item_count) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_file(*this->provider, "/pt01.txt");
|
|
|
|
|
create_file(*this->provider, "/pt02.txt");
|
|
|
|
|
create_directory(*this->provider, "/dir01");
|
|
|
|
|
create_directory(*this->provider, "/dir02");
|
|
|
|
|
this->create_file("/pt01.txt");
|
|
|
|
|
this->create_file("/pt02.txt");
|
|
|
|
|
this->create_directory("/dir01");
|
|
|
|
|
this->create_directory("/dir02");
|
|
|
|
|
|
|
|
|
|
directory_item_list 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_EQ(api_error::success, this->provider->remove_file("/pt01.txt"));
|
|
|
|
@@ -732,8 +588,8 @@ TYPED_TEST(providers_test, get_file) {
|
|
|
|
|
|
|
|
|
|
api_file file{};
|
|
|
|
|
EXPECT_EQ(api_error::success, this->provider->get_file(api_path, file));
|
|
|
|
|
decrypt_parts(*this->config, file.api_path);
|
|
|
|
|
decrypt_parts(*this->config, file.api_parent);
|
|
|
|
|
this->decrypt_parts(file.api_path);
|
|
|
|
|
this->decrypt_parts(file.api_parent);
|
|
|
|
|
|
|
|
|
|
EXPECT_STREQ("/test.txt", file.api_path.c_str());
|
|
|
|
|
EXPECT_STREQ("/", file.api_parent.c_str());
|
|
|
|
@@ -746,7 +602,7 @@ TYPED_TEST(providers_test, get_file) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_file(*this->provider, "/pt01.txt");
|
|
|
|
|
this->create_file("/pt01.txt");
|
|
|
|
|
|
|
|
|
|
api_file 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_directory(*this->provider, "/dir01");
|
|
|
|
|
this->create_directory("/dir01");
|
|
|
|
|
|
|
|
|
|
api_file file{};
|
|
|
|
|
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 api_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};
|
|
|
|
|
auto res =
|
|
|
|
@@ -867,7 +723,7 @@ TYPED_TEST(providers_test, get_filesystem_item) {
|
|
|
|
|
auto &file = test::create_random_file(128U);
|
|
|
|
|
auto api_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};
|
|
|
|
|
auto res =
|
|
|
|
@@ -930,7 +786,7 @@ TYPED_TEST(providers_test, get_filesystem_item_from_source_path) {
|
|
|
|
|
api_path =
|
|
|
|
|
fmt::format("/{}", utils::path::strip_to_file_name(file.get_path()));
|
|
|
|
|
source_path = file.get_path();
|
|
|
|
|
create_file(*this->provider, api_path);
|
|
|
|
|
this->create_file(api_path);
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(api_error::success,
|
|
|
|
|
this->provider->set_item_meta(
|
|
|
|
@@ -980,7 +836,7 @@ TYPED_TEST(providers_test, remove_file_fails_if_item_is_directory) {
|
|
|
|
|
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::success, this->provider->remove_directory("/dir01"));
|
|
|
|
|
}
|
|
|
|
@@ -992,7 +848,7 @@ TYPED_TEST(providers_test, remove_directory_fails_if_item_is_file) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_file(*this->provider, "/pt01.txt");
|
|
|
|
|
this->create_file("/pt01.txt");
|
|
|
|
|
EXPECT_EQ(api_error::item_not_found,
|
|
|
|
|
this->provider->remove_directory("/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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_file(*this->provider, "/pin01.txt");
|
|
|
|
|
create_file(*this->provider, "/pin02.txt");
|
|
|
|
|
create_file(*this->provider, "/nopin01.txt");
|
|
|
|
|
this->create_file("/pin01.txt");
|
|
|
|
|
this->create_file("/pin02.txt");
|
|
|
|
|
this->create_file("/nopin01.txt");
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(api_error::success,
|
|
|
|
|
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();
|
|
|
|
|
EXPECT_EQ(std::size_t(2U), pinned.size());
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(pinned_includes_api_path(pinned, "/pin01.txt"));
|
|
|
|
|
EXPECT_TRUE(pinned_includes_api_path(pinned, "/pin02.txt"));
|
|
|
|
|
EXPECT_FALSE(pinned_includes_api_path(pinned, "/nopin01.txt"));
|
|
|
|
|
EXPECT_TRUE(this->pinned_includes_api_path(pinned, "/pin01.txt"));
|
|
|
|
|
EXPECT_TRUE(this->pinned_includes_api_path(pinned, "/pin02.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("/pin02.txt"));
|
|
|
|
@@ -1044,8 +900,8 @@ TYPED_TEST(providers_test, remove_pin_updates_pinned_files) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_file(*this->provider, "/pin01.txt");
|
|
|
|
|
create_file(*this->provider, "/pin02.txt");
|
|
|
|
|
this->create_file("/pin01.txt");
|
|
|
|
|
this->create_file("/pin02.txt");
|
|
|
|
|
EXPECT_EQ(api_error::success,
|
|
|
|
|
this->provider->set_item_meta("/pin01.txt", META_PINNED, "true"));
|
|
|
|
|
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"));
|
|
|
|
|
pinned = this->provider->get_pinned_files();
|
|
|
|
|
EXPECT_EQ(std::size_t(1U), pinned.size());
|
|
|
|
|
EXPECT_TRUE(pinned_includes_api_path(pinned, "/pin01.txt"));
|
|
|
|
|
EXPECT_FALSE(pinned_includes_api_path(pinned, "/pin02.txt"));
|
|
|
|
|
EXPECT_TRUE(this->pinned_includes_api_path(pinned, "/pin01.txt"));
|
|
|
|
|
EXPECT_FALSE(this->pinned_includes_api_path(pinned, "/pin02.txt"));
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(api_error::success,
|
|
|
|
|
this->provider->set_item_meta("/pin01.txt", META_PINNED, "false"));
|
|
|
|
@@ -1077,9 +933,9 @@ TYPED_TEST(providers_test, remove_file_updates_pinned_files) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_file(*this->provider, "/pin_keep.txt");
|
|
|
|
|
create_file(*this->provider, "/pin_delete.txt");
|
|
|
|
|
create_file(*this->provider, "/nopin.txt");
|
|
|
|
|
this->create_file("/pin_keep.txt");
|
|
|
|
|
this->create_file("/pin_delete.txt");
|
|
|
|
|
this->create_file("/nopin.txt");
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(api_error::success, this->provider->set_item_meta(
|
|
|
|
|
"/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();
|
|
|
|
|
EXPECT_EQ(std::size_t(2U), pinned.size());
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(pinned_includes_api_path(pinned, "/pin_keep.txt"));
|
|
|
|
|
EXPECT_TRUE(pinned_includes_api_path(pinned, "/pin_delete.txt"));
|
|
|
|
|
EXPECT_FALSE(pinned_includes_api_path(pinned, "/nopin.txt"));
|
|
|
|
|
EXPECT_TRUE(this->pinned_includes_api_path(pinned, "/pin_keep.txt"));
|
|
|
|
|
EXPECT_TRUE(this->pinned_includes_api_path(pinned, "/pin_delete.txt"));
|
|
|
|
|
EXPECT_FALSE(this->pinned_includes_api_path(pinned, "/nopin.txt"));
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(api_error::success, this->provider->remove_file("/pin_delete.txt"));
|
|
|
|
|
|
|
|
|
|
pinned = this->provider->get_pinned_files();
|
|
|
|
|
EXPECT_EQ(std::size_t(1U), pinned.size());
|
|
|
|
|
EXPECT_TRUE(pinned_includes_api_path(pinned, "/pin_keep.txt"));
|
|
|
|
|
EXPECT_FALSE(pinned_includes_api_path(pinned, "/pin_delete.txt"));
|
|
|
|
|
EXPECT_TRUE(this->pinned_includes_api_path(pinned, "/pin_keep.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("/nopin.txt"));
|
|
|
|
@@ -1116,8 +972,8 @@ TYPED_TEST(providers_test, get_total_item_count) {
|
|
|
|
|
|
|
|
|
|
std::uint64_t before{this->provider->get_total_item_count()};
|
|
|
|
|
|
|
|
|
|
create_file(*this->provider, "/count01.txt");
|
|
|
|
|
create_file(*this->provider, "/count02.txt");
|
|
|
|
|
this->create_file("/count01.txt");
|
|
|
|
|
this->create_file("/count02.txt");
|
|
|
|
|
|
|
|
|
|
std::uint64_t mid{this->provider->get_total_item_count()};
|
|
|
|
|
EXPECT_EQ(before + 2U, mid);
|
|
|
|
@@ -1159,8 +1015,8 @@ TYPED_TEST(providers_test, get_used_drive_space) {
|
|
|
|
|
auto api_path2 =
|
|
|
|
|
fmt::format("/{}", utils::path::strip_to_file_name(file2.get_path()));
|
|
|
|
|
|
|
|
|
|
create_file(*this->provider, api_path1);
|
|
|
|
|
create_file(*this->provider, api_path2);
|
|
|
|
|
this->create_file(api_path1);
|
|
|
|
|
this->create_file(api_path2);
|
|
|
|
|
|
|
|
|
|
stop_type stop_requested{false};
|
|
|
|
|
ASSERT_EQ(
|
|
|
|
@@ -1203,7 +1059,7 @@ TYPED_TEST(providers_test, remove_item_meta) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create_file(*this->provider, api_path);
|
|
|
|
|
this->create_file(api_path);
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(api_error::success,
|
|
|
|
|
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));
|
|
|
|
|
} else {
|
|
|
|
|
api_path = "/rim_restricted.txt";
|
|
|
|
|
create_file(*this->provider, api_path);
|
|
|
|
|
this->create_file(api_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 dst{"/rn_dst.txt"};
|
|
|
|
|
create_file(*this->provider, src);
|
|
|
|
|
this->create_file(src);
|
|
|
|
|
|
|
|
|
|
std::string src_meta_size{};
|
|
|
|
|
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) {
|
|
|
|
|
if (not this->provider->is_rename_supported()) {
|
|
|
|
|
if (this->provider->get_provider_type() != provider_type::encrypt) {
|
|
|
|
|
create_file(*this->provider, "/rn_src_conflict.txt");
|
|
|
|
|
create_file(*this->provider, "/rn_dst_conflict.txt");
|
|
|
|
|
this->create_file("/rn_src_conflict.txt");
|
|
|
|
|
this->create_file("/rn_dst_conflict.txt");
|
|
|
|
|
}
|
|
|
|
|
auto res = this->provider->rename_file("/rn_src_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 dst{"/rn_dst_conflict.txt"};
|
|
|
|
|
create_file(*this->provider, src);
|
|
|
|
|
create_file(*this->provider, dst);
|
|
|
|
|
this->create_file(src);
|
|
|
|
|
this->create_file(dst);
|
|
|
|
|
|
|
|
|
|
auto res = this->provider->rename_file(src, dst);
|
|
|
|
|
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) {
|
|
|
|
|
if (not this->provider->is_rename_supported()) {
|
|
|
|
|
if (this->provider->get_provider_type() != provider_type::encrypt) {
|
|
|
|
|
create_file(*this->provider, "/rn_src_conflict.txt");
|
|
|
|
|
create_directory(*this->provider, "/rn_dst_conflict");
|
|
|
|
|
this->create_file("/rn_src_conflict.txt");
|
|
|
|
|
this->create_directory("/rn_dst_conflict");
|
|
|
|
|
}
|
|
|
|
|
auto res =
|
|
|
|
|
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 dst{"/rn_dst_conflict"};
|
|
|
|
|
create_file(*this->provider, src);
|
|
|
|
|
create_directory(*this->provider, dst);
|
|
|
|
|
this->create_file(src);
|
|
|
|
|
this->create_directory(dst);
|
|
|
|
|
|
|
|
|
|
auto res = this->provider->rename_file(src, dst);
|
|
|
|
|
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_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
|
|
|
|
|