revert
All checks were successful
BlockStorage/repertory_linux_builds/pipeline/head This commit looks good
BlockStorage/repertory_osx_builds/pipeline/head This commit looks good

This commit is contained in:
2024-01-29 11:36:26 -06:00
parent d175a38ad1
commit 99533a9687
213 changed files with 43429 additions and 41103 deletions

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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
@@ -42,18 +42,18 @@ public:
const auto DEFAULT_SIA_CONFIG = "{\n"
" \"ApiAuth\": \"\",\n"
" \"ApiPort\": 11101,\n"
" \"ApiPort\": 10000,\n"
" \"ApiUser\": \"repertory\",\n"
" \"ChunkDownloaderTimeoutSeconds\": 30,\n"
" \"EnableChunkDownloaderTimeout\": true,\n"
" \"EnableCommDurationEvents\": false,\n"
" \"EnableDriveEvents\": false,\n"
" \"EnableMaxCacheSize\": true,\n"
" \"EnableMaxCacheSize\": false,\n"
#ifdef _WIN32
" \"EnableMountManager\": false,\n"
#endif
" \"EventLevel\": \"normal\",\n"
" \"EvictionDelayMinutes\": 30,\n"
" \"EvictionDelayMinutes\": 10,\n"
" \"EvictionUsesAccessedTime\": false,\n"
" \"HighFreqIntervalSeconds\": 30,\n"
" \"HostConfig\": {\n"
@@ -90,18 +90,18 @@ const auto DEFAULT_SIA_CONFIG = "{\n"
const auto DEFAULT_S3_CONFIG = "{\n"
" \"ApiAuth\": \"\",\n"
" \"ApiPort\": 11103,\n"
" \"ApiPort\": 10100,\n"
" \"ApiUser\": \"repertory\",\n"
" \"ChunkDownloaderTimeoutSeconds\": 30,\n"
" \"EnableChunkDownloaderTimeout\": true,\n"
" \"EnableCommDurationEvents\": false,\n"
" \"EnableDriveEvents\": false,\n"
" \"EnableMaxCacheSize\": true,\n"
" \"EnableMaxCacheSize\": false,\n"
#ifdef _WIN32
" \"EnableMountManager\": false,\n"
#endif
" \"EventLevel\": \"normal\",\n"
" \"EvictionDelayMinutes\": 30,\n"
" \"EvictionDelayMinutes\": 10,\n"
" \"EvictionUsesAccessedTime\": false,\n"
" \"HighFreqIntervalSeconds\": 30,\n"
" \"LowFreqIntervalSeconds\": 3600,\n"
@@ -117,7 +117,7 @@ const auto DEFAULT_S3_CONFIG = "{\n"
" \"RemoteClientPoolSize\": 10,\n"
" \"RemoteHostNameOrIp\": \"\",\n"
" \"RemoteMaxConnections\": 20,\n"
" \"RemotePort\": 20001,\n"
" \"RemotePort\": 20100,\n"
" \"RemoteReceiveTimeoutSeconds\": 120,\n"
" \"RemoteSendTimeoutSeconds\": 30,\n"
" \"RemoteToken\": \"\"\n"
@@ -179,7 +179,7 @@ TEST_F(config_test, api_path) {
{
app_config config(provider_type::sia, "./data");
original_value = config.get_api_auth();
EXPECT_EQ(48u, original_value.size());
EXPECT_EQ(48U, original_value.size());
}
}
@@ -198,7 +198,7 @@ TEST_F(config_test, api_auth) {
}
TEST_F(config_test, api_port) {
std::uint16_t original_value;
std::uint16_t original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_api_port();
@@ -226,7 +226,7 @@ TEST_F(config_test, api_user) {
}
TEST_F(config_test, chunk_downloader_timeout_secs) {
std::uint8_t original_value;
std::uint8_t original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_chunk_downloader_timeout_secs();
@@ -240,7 +240,7 @@ TEST_F(config_test, chunk_downloader_timeout_secs) {
}
TEST_F(config_test, enable_chunk_download_timeout) {
bool original_value;
bool original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_enable_chunk_download_timeout();
@@ -254,7 +254,7 @@ TEST_F(config_test, enable_chunk_download_timeout) {
}
TEST_F(config_test, enable_comm_duration_events) {
bool original_value;
bool original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_enable_comm_duration_events();
@@ -268,7 +268,7 @@ TEST_F(config_test, enable_comm_duration_events) {
}
TEST_F(config_test, enable_drive_events) {
bool original_value;
bool original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_enable_drive_events();
@@ -282,7 +282,7 @@ TEST_F(config_test, enable_drive_events) {
}
TEST_F(config_test, enable_max_cache_size) {
bool original_value;
bool original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_enable_max_cache_size();
@@ -324,7 +324,7 @@ TEST_F(config_test, event_level) {
}
TEST_F(config_test, eviction_delay_mins) {
std::uint32_t original_value;
std::uint32_t original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_eviction_delay_mins();
@@ -338,7 +338,7 @@ TEST_F(config_test, eviction_delay_mins) {
}
TEST_F(config_test, eviction_uses_accessed_time) {
bool original_value;
bool original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_eviction_uses_accessed_time();
@@ -353,7 +353,7 @@ TEST_F(config_test, eviction_uses_accessed_time) {
}
TEST_F(config_test, high_frequency_interval_secs) {
std::uint8_t original_value;
std::uint8_t original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_high_frequency_interval_secs();
@@ -367,7 +367,7 @@ TEST_F(config_test, high_frequency_interval_secs) {
}
TEST_F(config_test, low_frequency_interval_secs) {
std::uint32_t original_value;
std::uint32_t original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_low_frequency_interval_secs();
@@ -384,33 +384,33 @@ TEST_F(config_test, max_cache_size_bytes) {
{
app_config config(provider_type::sia, "./data");
config.set_max_cache_size_bytes(100 * 1024 * 1024);
EXPECT_EQ(100u * 1024 * 1024, config.get_max_cache_size_bytes());
EXPECT_EQ(100U * 1024 * 1024, config.get_max_cache_size_bytes());
}
{
app_config config(provider_type::sia, "./data");
EXPECT_EQ(100u * 1024 * 1024, config.get_max_cache_size_bytes());
EXPECT_EQ(100U * 1024 * 1024, config.get_max_cache_size_bytes());
}
}
TEST_F(config_test, max_upload_count) {
{
app_config config(provider_type::sia, "./data");
config.set_max_upload_count(8u);
EXPECT_EQ(std::uint8_t(8u), config.get_max_upload_count());
config.set_max_upload_count(8U);
EXPECT_EQ(std::uint8_t(8U), config.get_max_upload_count());
}
{
app_config config(provider_type::sia, "./data");
EXPECT_EQ(std::uint8_t(8u), config.get_max_upload_count());
EXPECT_EQ(std::uint8_t(8U), config.get_max_upload_count());
}
{
app_config config(provider_type::sia, "./data");
config.set_max_upload_count(0u);
EXPECT_EQ(std::uint8_t(1u), config.get_max_upload_count());
config.set_max_upload_count(0U);
EXPECT_EQ(std::uint8_t(1U), config.get_max_upload_count());
}
}
TEST_F(config_test, online_check_retry_secs) {
std::uint16_t original_value;
std::uint16_t original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_online_check_retry_secs();
@@ -432,7 +432,7 @@ TEST_F(config_test, online_check_retry_secs_minimum_value) {
}
TEST_F(config_test, orphaned_file_retention_days) {
std::uint16_t original_value;
std::uint16_t original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_orphaned_file_retention_days();
@@ -462,7 +462,7 @@ TEST_F(config_test, orphaned_file_retention_days_maximum_value) {
}
TEST_F(config_test, read_ahead_count) {
std::uint8_t original_value;
std::uint8_t original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_read_ahead_count();
@@ -567,11 +567,11 @@ TEST_F(config_test, default_agent_name) {
}
TEST_F(config_test, default_api_port) {
EXPECT_EQ(9980u, app_config::default_api_port(provider_type::sia));
EXPECT_EQ(9980U, app_config::default_api_port(provider_type::sia));
}
TEST_F(config_test, default_data_directory) {
const std::string data_directory[] = {
const std::array<std::string, 1U> data_directory = {
app_config::default_data_directory(provider_type::sia),
};
@@ -592,7 +592,7 @@ TEST_F(config_test, default_data_directory) {
}
TEST_F(config_test, default_rpc_port) {
EXPECT_EQ(11101u, app_config::default_rpc_port(provider_type::sia));
EXPECT_EQ(10000U, app_config::default_rpc_port(provider_type::sia));
}
TEST_F(config_test, get_provider_display_name) {
@@ -613,7 +613,7 @@ TEST_F(config_test, get_version) {
}
TEST_F(config_test, enable_remote_mount) {
bool original_value;
bool original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_enable_remote_mount();
@@ -627,7 +627,7 @@ TEST_F(config_test, enable_remote_mount) {
}
TEST_F(config_test, is_remote_mount) {
bool original_value;
bool original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_is_remote_mount();
@@ -669,7 +669,7 @@ TEST_F(config_test, remote_host_name_or_ip) {
}
TEST_F(config_test, remote_port) {
std::uint16_t original_value;
std::uint16_t original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_remote_port();
@@ -683,7 +683,7 @@ TEST_F(config_test, remote_port) {
}
TEST_F(config_test, remote_receive_timeout_secs) {
std::uint16_t original_value;
std::uint16_t original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_remote_receive_timeout_secs();
@@ -697,7 +697,7 @@ TEST_F(config_test, remote_receive_timeout_secs) {
}
TEST_F(config_test, remote_send_timeout_secs) {
std::uint16_t original_value;
std::uint16_t original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_remote_send_timeout_secs();
@@ -723,7 +723,7 @@ TEST_F(config_test, remote_token) {
}
TEST_F(config_test, remote_client_pool_size) {
std::uint8_t original_value;
std::uint8_t original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_remote_client_pool_size();
@@ -749,7 +749,7 @@ TEST_F(config_test, remote_client_pool_size_minimum_value) {
}
TEST_F(config_test, remote_max_connections) {
std::uint8_t original_value;
std::uint8_t original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_remote_max_connections();
@@ -775,7 +775,7 @@ TEST_F(config_test, remote_max_connections_minimum_value) {
}
TEST_F(config_test, retry_read_count) {
std::uint16_t original_value;
std::uint16_t original_value{};
{
app_config config(provider_type::sia, "./data");
original_value = config.get_retry_read_count();
@@ -801,7 +801,7 @@ TEST_F(config_test, cache_timeout_seconds_minimum_value) {
app_config config(provider_type::s3, "./data");
EXPECT_FALSE(
config.set_value_by_name("S3Config.CacheTimeoutSeconds", "1").empty());
EXPECT_EQ(std::uint16_t(5u), config.get_s3_config().cache_timeout_secs);
EXPECT_EQ(std::uint16_t(5U), config.get_s3_config().cache_timeout_secs);
}
}
} // namespace repertory

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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
@@ -22,25 +22,42 @@
#include "test_common.hpp"
#include "app_config.hpp"
#include "file_manager/file_manager.hpp"
#include "events/consumers/console_consumer.hpp"
#include "providers/encrypt/encrypt_provider.hpp"
#include "utils/path_utils.hpp"
namespace repertory {
/* TEST(encrypt_provider, can_construct_encrypt_provider) {
/*
TEST(encrypt_provider, can_construct_encrypt_provider) {
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
// console_consumer consumer{};
// event_system::instance().start();
{
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::encrypt, "./encrypt_provider_test");
EXPECT_FALSE(
cfg.set_value_by_name("EncryptConfig.Path", "c:\\src").empty());
encrypt_provider provider(cfg);
file_manager mgr(cfg, provider);
mgr.start();
event_system::instance().stop();
EXPECT_TRUE(provider.start(
[&provider](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
&mgr));
directory_item_list list{};
EXPECT_EQ(api_error::success, provider.get_directory_items("/", list));
provider.stop();
mgr.stop();
}
// event_system::instance().stop();
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
}

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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
@@ -27,7 +27,7 @@
#include "utils/path_utils.hpp"
namespace repertory {
static std::string get_source_file_name() {
static auto get_source_file_name() -> std::string {
return generate_test_file_name("./", "encrypting_reader");
}
@@ -36,7 +36,7 @@ TEST(encrypting_reader, get_encrypted_file_name) {
ASSERT_TRUE(utils::file::retry_delete_file(source_file_name));
const auto token = std::string("moose");
auto source_file = create_random_file(source_file_name, 1024ul);
auto source_file = create_random_file(source_file_name, 1024UL);
EXPECT_TRUE(source_file != nullptr);
if (source_file) {
stop_type stop_requested = false;
@@ -64,20 +64,20 @@ TEST(encrypting_reader, file_data) {
const auto token = std::string("moose");
auto source_file = create_random_file(
source_file_name,
8u * utils::encryption::encrypting_reader::get_data_chunk_size());
8U * utils::encryption::encrypting_reader::get_data_chunk_size());
EXPECT_TRUE(source_file != nullptr);
if (source_file) {
stop_type stop_requested = false;
utils::encryption::encrypting_reader reader("test.dat", source_file_name,
stop_requested, token);
for (std::uint8_t i = 0u; i < 8u; i++) {
for (std::uint8_t i = 0U; i < 8U; i++) {
data_buffer buffer(
utils::encryption::encrypting_reader::get_encrypted_chunk_size());
for (std::uint8_t j = 0u; j < 2u; j++) {
EXPECT_EQ(buffer.size() / 2u,
for (std::uint8_t j = 0U; j < 2U; j++) {
EXPECT_EQ(buffer.size() / 2U,
utils::encryption::encrypting_reader::reader_function(
&buffer[(buffer.size() / 2u) * j], buffer.size() / 2u, 1u,
&buffer[(buffer.size() / 2U) * j], buffer.size() / 2U, 1U,
&reader));
}
@@ -91,10 +91,10 @@ TEST(encrypting_reader, file_data) {
std::size_t bytes_read{};
data_buffer file_data(decrypted_data.size());
EXPECT_TRUE(source_file->read_bytes(
&file_data[0u], file_data.size(),
file_data.data(), file_data.size(),
utils::encryption::encrypting_reader::get_data_chunk_size() * i,
bytes_read));
EXPECT_EQ(0, std::memcmp(&file_data[0u], &decrypted_data[0u],
EXPECT_EQ(0, std::memcmp(file_data.data(), decrypted_data.data(),
file_data.size()));
}
@@ -110,28 +110,30 @@ TEST(encrypting_reader, file_data_in_multiple_chunks) {
const auto token = std::string("moose");
auto source_file = create_random_file(
source_file_name,
8u * utils::encryption::encrypting_reader::get_data_chunk_size());
8U * utils::encryption::encrypting_reader::get_data_chunk_size());
EXPECT_TRUE(source_file != nullptr);
if (source_file) {
stop_type stop_requested = false;
utils::encryption::encrypting_reader reader("test.dat", source_file_name,
stop_requested, token);
for (std::uint8_t i = 0u; i < 8u; i += 2u) {
for (std::uint8_t i = 0U; i < 8U; i += 2U) {
data_buffer buffer(
utils::encryption::encrypting_reader::get_encrypted_chunk_size() *
2u);
2U);
EXPECT_EQ(buffer.size(),
utils::encryption::encrypting_reader::reader_function(
&buffer[0u], buffer.size(), 1u, &reader));
buffer.data(), buffer.size(), 1U, &reader));
for (std::uint8_t j = 0u; j < 2u; j++) {
for (std::uint8_t j = 0U; j < 2U; j++) {
data_buffer decrypted_data;
const auto offset = (j * (buffer.size() / 2u));
const auto offset = (j * (buffer.size() / 2U));
EXPECT_TRUE(utils::encryption::decrypt_data(
token,
data_buffer(buffer.begin() + offset,
buffer.begin() + offset + (buffer.size() / 2u)),
data_buffer(
std::next(buffer.begin(), static_cast<std::int64_t>(offset)),
std::next(buffer.begin(), static_cast<std::int64_t>(
offset + (buffer.size() / 2U)))),
decrypted_data));
EXPECT_EQ(utils::encryption::encrypting_reader::get_data_chunk_size(),
@@ -140,12 +142,12 @@ TEST(encrypting_reader, file_data_in_multiple_chunks) {
std::size_t bytes_read{};
data_buffer file_data(decrypted_data.size());
EXPECT_TRUE(source_file->read_bytes(
&file_data[0u], file_data.size(),
file_data.data(), file_data.size(),
(utils::encryption::encrypting_reader::get_data_chunk_size() * i) +
(j *
utils::encryption::encrypting_reader::get_data_chunk_size()),
bytes_read));
EXPECT_EQ(0, std::memcmp(&file_data[0u], &decrypted_data[0u],
EXPECT_EQ(0, std::memcmp(file_data.data(), decrypted_data.data(),
file_data.size()));
}
}
@@ -163,7 +165,7 @@ TEST(encrypting_reader, file_data_as_stream) {
const auto token = std::string("moose");
auto source_file = create_random_file(
source_file_name,
8u * utils::encryption::encrypting_reader::get_data_chunk_size());
8U * utils::encryption::encrypting_reader::get_data_chunk_size());
EXPECT_TRUE(source_file != nullptr);
if (source_file) {
stop_type stop_requested = false;
@@ -177,15 +179,18 @@ TEST(encrypting_reader, file_data_as_stream) {
EXPECT_FALSE(io_stream->seekg(0, std::ios_base::beg).fail());
EXPECT_TRUE(io_stream->good());
for (std::uint8_t i = 0u; i < 8u; i++) {
for (std::uint8_t i = 0U; i < 8U; i++) {
data_buffer buffer(
utils::encryption::encrypting_reader::get_encrypted_chunk_size());
EXPECT_FALSE(io_stream->seekg(i * buffer.size()).fail());
EXPECT_FALSE(
io_stream->seekg(static_cast<std::streamoff>(i * buffer.size()))
.fail());
EXPECT_TRUE(io_stream->good());
for (std::uint8_t j = 0u; j < 2u; j++) {
for (std::uint8_t j = 0U; j < 2U; j++) {
EXPECT_FALSE(
io_stream
->read(&buffer[(buffer.size() / 2u) * j], buffer.size() / 2u)
->read(&buffer[(buffer.size() / 2U) * j],
static_cast<std::streamsize>(buffer.size()) / 2U)
.fail());
EXPECT_TRUE(io_stream->good());
}
@@ -200,10 +205,10 @@ TEST(encrypting_reader, file_data_as_stream) {
std::size_t bytes_read{};
data_buffer file_data(decrypted_data.size());
EXPECT_TRUE(source_file->read_bytes(
&file_data[0u], file_data.size(),
file_data.data(), file_data.size(),
utils::encryption::encrypting_reader::get_data_chunk_size() * i,
bytes_read));
EXPECT_EQ(0, std::memcmp(&file_data[0u], &decrypted_data[0u],
EXPECT_EQ(0, std::memcmp(file_data.data(), decrypted_data.data(),
file_data.size()));
}
@@ -233,20 +238,25 @@ TEST(encrypting_reader, file_data_in_multiple_chunks_as_stream) {
EXPECT_FALSE(io_stream->seekg(0, std::ios_base::beg).fail());
EXPECT_TRUE(io_stream->good());
for (std::uint8_t i = 0u; i < 8u; i += 2u) {
for (std::uint8_t i = 0U; i < 8U; i += 2U) {
data_buffer buffer(
utils::encryption::encrypting_reader::get_encrypted_chunk_size() *
2u);
EXPECT_FALSE(io_stream->read(&buffer[0u], buffer.size()).fail());
2U);
EXPECT_FALSE(
io_stream
->read(buffer.data(), static_cast<std::streamsize>(buffer.size()))
.fail());
EXPECT_TRUE(io_stream->good());
for (std::uint8_t j = 0u; j < 2u; j++) {
for (std::uint8_t j = 0U; j < 2U; j++) {
data_buffer decrypted_data;
const auto offset = (j * (buffer.size() / 2u));
const auto offset = (j * (buffer.size() / 2U));
EXPECT_TRUE(utils::encryption::decrypt_data(
token,
data_buffer(buffer.begin() + offset,
buffer.begin() + offset + (buffer.size() / 2u)),
data_buffer(
std::next(buffer.begin(), static_cast<std::int64_t>(offset)),
std::next(buffer.begin(), static_cast<std::int64_t>(
offset + (buffer.size() / 2U)))),
decrypted_data));
EXPECT_EQ(utils::encryption::encrypting_reader::get_data_chunk_size(),
@@ -255,12 +265,12 @@ TEST(encrypting_reader, file_data_in_multiple_chunks_as_stream) {
std::size_t bytes_read{};
data_buffer file_data(decrypted_data.size());
EXPECT_TRUE(source_file->read_bytes(
&file_data[0u], file_data.size(),
file_data.data(), file_data.size(),
(utils::encryption::encrypting_reader::get_data_chunk_size() * i) +
(j *
utils::encryption::encrypting_reader::get_data_chunk_size()),
bytes_read));
EXPECT_EQ(0, std::memcmp(&file_data[0u], &decrypted_data[0u],
EXPECT_EQ(0, std::memcmp(file_data.data(), decrypted_data.data(),
file_data.size()));
}
}

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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
@@ -319,11 +319,9 @@ TEST(open_file, write_new_file) {
return api_error::success;
});
EXPECT_CALL(um, remove_upload)
.Times(2)
.WillRepeatedly([&fsi](const std::string &api_path) {
EXPECT_EQ(fsi.api_path, api_path);
});
EXPECT_CALL(um, remove_upload).WillOnce([&fsi](const std::string &api_path) {
EXPECT_EQ(fsi.api_path, api_path);
});
EXPECT_CALL(um, queue_upload).WillOnce([&fsi](const i_open_file &cur_file) {
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
@@ -408,11 +406,9 @@ TEST(open_file, write_new_file_multiple_chunks) {
return api_error::success;
});
EXPECT_CALL(um, remove_upload)
.Times(4)
.WillRepeatedly([&fsi](const std::string &api_path) {
EXPECT_EQ(fsi.api_path, api_path);
});
EXPECT_CALL(um, remove_upload).WillOnce([&fsi](const std::string &api_path) {
EXPECT_EQ(fsi.api_path, api_path);
});
EXPECT_CALL(um, queue_upload).WillOnce([&fsi](const i_open_file &cur_file) {
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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
@@ -81,7 +81,7 @@ TEST(file_manager, can_start_and_stop) {
}
event_system::instance().stop();
EXPECT_TRUE(utils::file::delete_directory_recursively("./fm_test"));
// EXPECT_TRUE(utils::file::delete_directory_recursively("./fm_test"));
}
TEST(file_manager, can_create_and_close_file) {

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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
@@ -128,36 +128,36 @@ static void unlink_file_and_test(const std::string &file_path) {
EXPECT_FALSE(utils::file::is_file(file_path));
}
static void test_chmod(const std::string &api_path,
static void test_chmod(const std::string & /* api_path */,
const std::string &file_path) {
std::cout << __FUNCTION__ << std::endl;
EXPECT_EQ(0, chmod(file_path.c_str(), S_IRUSR | S_IWUSR));
std::this_thread::sleep_for(SLEEP_SECONDS);
struct stat64 path_stat {};
stat64(file_path.c_str(), &path_stat);
struct stat64 unix_st {};
stat64(file_path.c_str(), &unix_st);
EXPECT_EQ(static_cast<std::uint32_t>(S_IRUSR | S_IWUSR),
ACCESSPERMS & path_stat.st_mode);
ACCESSPERMS & unix_st.st_mode);
}
static void test_chown(const std::string &api_path,
static void test_chown(const std::string & /* api_path */,
const std::string &file_path) {
std::cout << __FUNCTION__ << std::endl;
EXPECT_EQ(0, chown(file_path.c_str(), -1, 0));
EXPECT_EQ(0, chown(file_path.c_str(), static_cast<uid_t>(-1), 0));
std::this_thread::sleep_for(SLEEP_SECONDS);
struct stat64 path_stat {};
stat64(file_path.c_str(), &path_stat);
EXPECT_EQ(0, path_stat.st_gid);
struct stat64 unix_st {};
stat64(file_path.c_str(), &unix_st);
EXPECT_EQ(0U, unix_st.st_gid);
EXPECT_EQ(0, chown(file_path.c_str(), 0, -1));
EXPECT_EQ(0, chown(file_path.c_str(), 0, static_cast<gid_t>(-1)));
std::this_thread::sleep_for(SLEEP_SECONDS);
stat64(file_path.c_str(), &path_stat);
EXPECT_EQ(0, path_stat.st_gid);
stat64(file_path.c_str(), &unix_st);
EXPECT_EQ(0U, unix_st.st_gid);
}
static void test_mkdir(const std::string &api_path,
static void test_mkdir(const std::string & /* api_path */,
const std::string &directory_path) {
std::cout << __FUNCTION__ << std::endl;
EXPECT_EQ(0, mkdir(directory_path.c_str(),
@@ -166,18 +166,18 @@ static void test_mkdir(const std::string &api_path,
EXPECT_TRUE(utils::file::is_directory(directory_path));
EXPECT_FALSE(utils::file::is_file(directory_path));
struct stat64 path_stat {};
stat64(directory_path.c_str(), &path_stat);
struct stat64 unix_st {};
stat64(directory_path.c_str(), &unix_st);
EXPECT_EQ(getuid(), path_stat.st_uid);
EXPECT_EQ(getgid(), path_stat.st_gid);
EXPECT_EQ(getuid(), unix_st.st_uid);
EXPECT_EQ(getgid(), unix_st.st_gid);
EXPECT_EQ(static_cast<std::uint32_t>(S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP |
S_IXGRP),
ACCESSPERMS & path_stat.st_mode);
ACCESSPERMS & unix_st.st_mode);
}
static void test_write_and_read(const std::string &api_path,
static void test_write_and_read(const std::string & /* api_path */,
const std::string &file_path) {
std::cout << __FUNCTION__ << std::endl;
auto fd =
@@ -279,31 +279,23 @@ static void test_ftruncate(const std::string &file_path) {
}
#ifndef __APPLE__
static void test_fallocate(const std::string &api_path,
static void test_fallocate(const std::string & /* api_path */,
const std::string &file_path) {
std::cout << __FUNCTION__ << std::endl;
auto fd =
auto file =
open(file_path.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP);
EXPECT_LE(1, fd);
EXPECT_EQ(0, fallocate(fd, 0, 0, 16));
EXPECT_LE(1, file);
EXPECT_EQ(0, fallocate(file, 0, 0, 16));
std::uint64_t file_size{};
EXPECT_TRUE(utils::file::get_file_size(file_path, file_size));
EXPECT_EQ(16u, file_size);
EXPECT_EQ(16U, file_size);
EXPECT_EQ(0, close(fd));
EXPECT_EQ(0, close(file));
file_size = 0u;
file_size = 0U;
EXPECT_TRUE(utils::file::get_file_size(file_path, file_size));
EXPECT_EQ(16u, file_size);
// filesystem_item fsi{};
// EXPECT_EQ(api_error::success,
// provider.get_filesystem_item(api_path, false, fsi));
// file_size = 0u;
// EXPECT_TRUE(utils::file::get_file_size(fsi.source_path, file_size));
// EXPECT_EQ(16u, file_size);
EXPECT_EQ(16U, file_size);
}
#endif
@@ -316,12 +308,12 @@ static void test_file_getattr(const std::string & /* api_path */,
EXPECT_EQ(0, close(fd));
struct stat64 st {};
EXPECT_EQ(0, stat64(file_path.c_str(), &st));
struct stat64 unix_st {};
EXPECT_EQ(0, stat64(file_path.c_str(), &unix_st));
EXPECT_EQ(static_cast<std::uint32_t>(S_IRUSR | S_IWUSR | S_IRGRP),
ACCESSPERMS & st.st_mode);
EXPECT_FALSE(S_ISDIR(st.st_mode));
EXPECT_TRUE(S_ISREG(st.st_mode));
ACCESSPERMS & unix_st.st_mode);
EXPECT_FALSE(S_ISDIR(unix_st.st_mode));
EXPECT_TRUE(S_ISREG(unix_st.st_mode));
}
static void test_directory_getattr(const std::string & /* api_path */,
@@ -330,17 +322,17 @@ static void test_directory_getattr(const std::string & /* api_path */,
EXPECT_EQ(0, mkdir(directory_path.c_str(),
S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP));
struct stat64 st {};
EXPECT_EQ(0, stat64(directory_path.c_str(), &st));
struct stat64 unix_st {};
EXPECT_EQ(0, stat64(directory_path.c_str(), &unix_st));
EXPECT_EQ(static_cast<std::uint32_t>(S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP |
S_IXGRP),
ACCESSPERMS & st.st_mode);
EXPECT_TRUE(S_ISDIR(st.st_mode));
EXPECT_FALSE(S_ISREG(st.st_mode));
ACCESSPERMS & unix_st.st_mode);
EXPECT_TRUE(S_ISDIR(unix_st.st_mode));
EXPECT_FALSE(S_ISREG(unix_st.st_mode));
}
static void
test_write_operations_fail_if_read_only(const std::string &api_path,
test_write_operations_fail_if_read_only(const std::string & /* api_path */,
const std::string &file_path) {
std::cout << __FUNCTION__ << std::endl;
auto fd =
@@ -418,13 +410,14 @@ static void test_xattr_listxattr(const std::string &file_path) {
EXPECT_STREQ(attr.c_str(), val.c_str());
std::string data;
auto size = listxattr(file_path.c_str(), &data[0u], 0u);
auto size = listxattr(file_path.c_str(), data.data(), 0U);
EXPECT_EQ(31, size);
data.resize(size);
EXPECT_EQ(size, listxattr(file_path.c_str(), &data[0u], size));
data.resize(static_cast<std::size_t>(size));
EXPECT_EQ(size, listxattr(file_path.c_str(), data.data(),
static_cast<std::size_t>(size)));
char *ptr = &data[0u];
auto *ptr = data.data();
EXPECT_STREQ("user.test_attr", ptr);
ptr += strlen(ptr) + 1;

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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
@@ -39,52 +39,58 @@ public:
: mount_location_(std::move(mount_location)) {}
private:
const std::string mount_location_;
std::string mount_location_;
std::unordered_map<std::string, api_meta_map> meta_;
public:
api_error check_owner(const std::string &) const override {
auto check_owner(const std::string &) const -> api_error override {
return api_error::success;
}
api_error check_parent_access(const std::string &, int) const override {
auto check_parent_access(const std::string &, int) const
-> api_error override {
return api_error::success;
}
std::uint64_t get_directory_item_count(const std::string &) const override {
auto get_directory_item_count(const std::string &) const
-> std::uint64_t override {
return 1;
}
directory_item_list get_directory_items(const std::string &) const override {
auto get_directory_items(const std::string &) const
-> directory_item_list override {
directory_item_list list{};
directory_item di{};
di.api_path = ".";
di.directory = true;
di.size = 0;
di.meta = {{META_ATTRIBUTES, "16"},
{META_MODIFIED, std::to_string(utils::get_file_time_now())},
{META_WRITTEN, std::to_string(utils::get_file_time_now())},
{META_ACCESSED, std::to_string(utils::get_file_time_now())},
{META_CREATION, std::to_string(utils::get_file_time_now())}};
list.emplace_back(di);
directory_item dir_item{};
dir_item.api_path = ".";
dir_item.directory = true;
dir_item.size = 0;
dir_item.meta = {
{META_ATTRIBUTES, "16"},
{META_MODIFIED, std::to_string(utils::get_file_time_now())},
{META_WRITTEN, std::to_string(utils::get_file_time_now())},
{META_ACCESSED, std::to_string(utils::get_file_time_now())},
{META_CREATION, std::to_string(utils::get_file_time_now())}};
list.emplace_back(dir_item);
di.api_path = "..";
list.emplace_back(di);
dir_item.api_path = "..";
list.emplace_back(dir_item);
return list;
}
std::uint64_t get_file_size(const std::string &) const override { return 0u; }
auto get_file_size(const std::string &) const -> std::uint64_t override {
return 0U;
}
api_error get_item_meta(const std::string &api_path,
api_meta_map &meta) const override {
auto get_item_meta(const std::string &api_path, api_meta_map &meta) const
-> api_error override {
meta = const_cast<mock_fuse_drive *>(this)->meta_[api_path];
return api_error::success;
}
api_error get_item_meta(const std::string &api_path, const std::string &name,
std::string &value) const override {
auto get_item_meta(const std::string &api_path, const std::string &name,
std::string &value) const -> api_error override {
value = const_cast<mock_fuse_drive *>(this)->meta_[api_path][name];
if (value.empty()) {
value = "0";
@@ -92,13 +98,13 @@ public:
return api_error::success;
}
std::uint64_t get_total_drive_space() const override {
return 100 * 1024 * 1024;
auto get_total_drive_space() const -> std::uint64_t override {
return 100ULL * 1024ULL * 1024ULL;
}
std::uint64_t get_total_item_count() const override { return 0u; }
auto get_total_item_count() const -> std::uint64_t override { return 0U; }
std::uint64_t get_used_drive_space() const override { return 0u; }
auto get_used_drive_space() const -> std::uint64_t override { return 0U; }
void get_volume_info(UINT64 &total_size, UINT64 &free_size,
std::string &volume_label) const override {
@@ -107,10 +113,8 @@ public:
volume_label = "TestVolumeLabel";
}
void populate_stat(const directory_item &, struct stat &) const override {}
int rename_directory(const std::string &from_api_path,
const std::string &to_api_path) override {
auto rename_directory(const std::string &from_api_path,
const std::string &to_api_path) -> int override {
const auto from_file_path =
utils::path::combine(mount_location_, {from_api_path});
const auto to_file_path =
@@ -118,8 +122,9 @@ public:
return rename(from_file_path.c_str(), to_file_path.c_str());
}
int rename_file(const std::string &from_api_path,
const std::string &to_api_path, bool overwrite) override {
auto rename_file(const std::string &from_api_path,
const std::string &to_api_path, bool overwrite)
-> int override {
const auto from_file_path =
utils::path::combine(mount_location_, {from_api_path});
const auto to_file_path =
@@ -138,7 +143,9 @@ public:
return rename(from_file_path.c_str(), to_file_path.c_str());
}
bool is_processing(const std::string &) const override { return false; }
auto is_processing(const std::string &) const -> bool override {
return false;
}
void set_item_meta(const std::string &api_path, const std::string &key,
const std::string &value) override {

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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
@@ -52,12 +52,11 @@ public:
MOCK_METHOD(bool, is_directory, (), (const, override));
MOCK_METHOD(api_error, native_operation,
(const native_operation_callback &callback), (override));
MOCK_METHOD(api_error, native_operation, (native_operation_callback callback),
(override));
MOCK_METHOD(api_error, native_operation,
(std::uint64_t new_file_size,
const native_operation_callback &callback),
(std::uint64_t new_file_size, native_operation_callback callback),
(override));
MOCK_METHOD(api_error, read,

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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
@@ -37,18 +37,20 @@
namespace {
#ifdef _WIN32
static constexpr auto getgid() -> std::uint32_t { return 0U; }
static constexpr auto getuid() -> std::uint32_t { return 0U; }
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
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 &di = list.at(i);
EXPECT_TRUE(di.directory);
EXPECT_STREQ(forced_dirs.at(i).c_str(), di.api_path.c_str());
EXPECT_STREQ("", di.api_parent.c_str());
EXPECT_EQ(std::size_t(0U), di.size);
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);
}
};
@@ -56,8 +58,8 @@ const auto create_directory = [](repertory::i_provider &provider,
const std::string &api_path) {
auto date = repertory::utils::get_file_time_now();
auto meta = repertory::create_meta_attributes(
date, 0U, date + 1U, date + 2U, true, getgid(), "", 0700, date + 3U, 1U,
2U, 0U, api_path + "_src", getuid(), date + 4U);
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));
@@ -65,6 +67,41 @@ const auto create_directory = [](repertory::i_provider &provider,
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_STREQ((api_path + "_src").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 create_file = [](repertory::i_provider &provider,
@@ -73,8 +110,8 @@ const auto create_file = [](repertory::i_provider &provider,
auto date = repertory::utils::get_file_time_now();
auto meta = repertory::create_meta_attributes(
date, 0U, date + 1U, date + 2U, false, getgid(), "", 0700, date + 3U, 1U,
2U, 0U, source_path, getuid(), date + 4U);
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));
@@ -83,6 +120,40 @@ const auto create_file = [](repertory::i_provider &provider,
EXPECT_TRUE(exists);
EXPECT_TRUE(repertory::utils::file::delete_file(source_path));
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,
@@ -167,15 +238,15 @@ static void create_directory_clone_source_meta(i_provider &provider) {
EXPECT_EQ(api_error::success, provider.get_item_meta("/clone2", meta_clone));
EXPECT_EQ(meta_orig.size(), meta_clone.size());
for (const auto &kv : meta_orig) {
if (kv.first == META_KEY) {
if (kv.second.empty() && meta_clone[kv.first].empty()) {
for (const auto &item : meta_orig) {
if (item.first == META_KEY) {
if (item.second.empty() && meta_clone[item.first].empty()) {
continue;
}
EXPECT_STRNE(kv.second.c_str(), meta_clone[kv.first].c_str());
EXPECT_STRNE(item.second.c_str(), meta_clone[item.first].c_str());
continue;
}
EXPECT_STREQ(kv.second.c_str(), meta_clone[kv.first].c_str());
EXPECT_STREQ(item.second.c_str(), meta_clone[item.first].c_str());
}
EXPECT_EQ(api_error::success, provider.remove_directory("/clone"));
@@ -343,22 +414,24 @@ static void get_directory_items(const app_config &cfg, i_provider &provider) {
EXPECT_EQ(std::size_t(4U), list.size());
directory_item_list list_decrypted{list.begin() + 2U, list.end()};
for (auto &di : list_decrypted) {
decrypt_parts(cfg, di.api_parent);
decrypt_parts(cfg, di.api_path);
for (auto &dir_item : list_decrypted) {
decrypt_parts(cfg, dir_item.api_parent);
decrypt_parts(cfg, dir_item.api_path);
}
auto dir = std::find_if(
list_decrypted.begin(), list_decrypted.end(),
[](const directory_item &di) -> bool { return di.directory; });
auto dir = std::find_if(list_decrypted.begin(), list_decrypted.end(),
[](const directory_item &dir_item) -> bool {
return dir_item.directory;
});
EXPECT_LT(dir, list_decrypted.end());
EXPECT_STREQ("/sub10", dir->api_path.c_str());
EXPECT_STREQ("/", dir->api_parent.c_str());
EXPECT_EQ(std::size_t(0U), dir->size);
auto file = std::find_if(
list_decrypted.begin(), list_decrypted.end(),
[](const directory_item &di) -> bool { return not di.directory; });
auto file = std::find_if(list_decrypted.begin(), list_decrypted.end(),
[](const directory_item &dir_item) -> bool {
return not dir_item.directory;
});
EXPECT_LT(file, list_decrypted.end());
EXPECT_STREQ("/test.txt", file->api_path.c_str());
EXPECT_STREQ("/", file->api_parent.c_str());
@@ -380,14 +453,15 @@ static void get_directory_items(const app_config &cfg, i_provider &provider) {
EXPECT_EQ(std::size_t(3U), list.size());
directory_item_list list_decrypted2{list.begin() + 2U, list.end()};
for (auto &di : list_decrypted2) {
decrypt_parts(cfg, di.api_parent);
decrypt_parts(cfg, di.api_path);
for (auto &dir_item : list_decrypted2) {
decrypt_parts(cfg, dir_item.api_parent);
decrypt_parts(cfg, dir_item.api_path);
}
auto file2 = std::find_if(
list_decrypted2.begin(), list_decrypted2.end(),
[](const directory_item &di) -> bool { return not di.directory; });
auto file2 = std::find_if(list_decrypted2.begin(), list_decrypted2.end(),
[](const directory_item &dir_item) -> bool {
return not dir_item.directory;
});
EXPECT_LT(file2, list_decrypted2.end());
EXPECT_STREQ("/sub10/moose.txt", file2->api_path.c_str());
EXPECT_STREQ("/sub10", file2->api_parent.c_str());
@@ -517,22 +591,45 @@ static void run_tests(const app_config &cfg, i_provider &provider) {
get_api_path_from_source_fails_if_file_not_found(cfg, provider);
// TODO: continue here
get_directory_item_count(cfg, provider);
get_directory_items(cfg, provider);
get_directory_items_fails_if_directory_not_found(provider);
get_directory_items_fails_if_item_is_file(cfg, provider);
get_directory_item_count(cfg, provider);
get_file(cfg, provider);
get_file_fails_if_file_not_found(provider);
get_file_fails_if_item_is_directory(cfg, provider);
/* get_file_list(provider);
get_file_size(provider);
get_filesystem_item(provider);
get_filesystem_item_and_file(provider);
get_filesystem_item_from_source_path(provider);
get_item_meta(provider);
get_item_meta2(provider);
get_pinned_files(provider);
get_total_drive_space(provider);
get_total_item_count(provider);
get_used_drive_space(provider);
is_directory(provider);
is_file(provider);
is_file_writeable(provider);
read_file_bytes(provider);
remove_directory(provider);
remove_file(provider);
remove_item_meta(provider);
rename_file(provider);
set_item_meta(provider);
set_item_meta2(provider);
upload_file(provider); */
}
TEST(providers, encrypt_provider) {
const auto config_path = utils::path::absolute("./providers_test_encrypt");
ASSERT_TRUE(utils::file::delete_directory_recursively(config_path));
console_consumer cc{};
console_consumer consumer{};
event_system::instance().start();
{
app_config cfg(provider_type::encrypt, config_path);
@@ -545,22 +642,21 @@ TEST(providers, encrypt_provider) {
EXPECT_STREQ(
encrypt_path.c_str(),
cfg.set_value_by_name("EncryptConfig.Path", encrypt_path.c_str())
.c_str());
cfg.set_value_by_name("EncryptConfig.Path", encrypt_path).c_str());
EXPECT_STREQ(
"test_token",
cfg.set_value_by_name("EncryptConfig.EncryptionToken", "test_token")
.c_str());
encrypt_provider provider{cfg};
file_manager fm(cfg, provider);
fm.start();
file_manager mgr(cfg, provider);
mgr.start();
EXPECT_TRUE(provider.start(
[&provider](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
&fm));
&mgr));
EXPECT_EQ(provider_type::encrypt, provider.get_provider_type());
EXPECT_TRUE(provider.is_direct_only());
EXPECT_TRUE(provider.is_online());
@@ -569,11 +665,9 @@ TEST(providers, encrypt_provider) {
run_tests(cfg, provider);
provider.stop();
fm.stop();
mgr.stop();
}
event_system::instance().stop();
ASSERT_TRUE(utils::file::delete_directory_recursively(config_path));
}
#if defined(REPERTORY_ENABLE_S3) && defined(REPERTORY_ENABLE_S3_TESTING)
@@ -581,7 +675,7 @@ TEST(providers, s3_provider) {
const auto config_path = utils::path::absolute("./providers_test_s3");
ASSERT_TRUE(utils::file::delete_directory_recursively(config_path));
console_consumer cc{};
console_consumer consumer{};
event_system::instance().start();
{
app_config cfg(provider_type::s3, config_path);
@@ -593,14 +687,14 @@ TEST(providers, s3_provider) {
curl_comm comm{cfg.get_s3_config()};
s3_provider provider{cfg, comm};
file_manager fm(cfg, provider);
fm.start();
file_manager mgr(cfg, provider);
mgr.start();
EXPECT_TRUE(provider.start(
[&provider](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
&fm));
&mgr));
EXPECT_EQ(provider_type::s3, provider.get_provider_type());
EXPECT_FALSE(provider.is_direct_only());
EXPECT_TRUE(provider.is_online());
@@ -609,11 +703,9 @@ TEST(providers, s3_provider) {
run_tests(cfg, provider);
provider.stop();
fm.stop();
mgr.stop();
}
event_system::instance().stop();
ASSERT_TRUE(utils::file::delete_directory_recursively(config_path));
}
#endif
@@ -621,7 +713,7 @@ TEST(providers, sia_provider) {
const auto config_path = utils::path::absolute("./providers_test_sia");
ASSERT_TRUE(utils::file::delete_directory_recursively(config_path));
console_consumer cc{};
console_consumer consumer{};
event_system::instance().start();
{
app_config cfg(provider_type::sia, config_path);
@@ -633,26 +725,24 @@ TEST(providers, sia_provider) {
curl_comm comm{cfg.get_host_config()};
sia_provider provider{cfg, comm};
file_manager fm(cfg, provider);
fm.start();
file_manager mgr(cfg, provider);
mgr.start();
EXPECT_TRUE(provider.start(
[&provider](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
&fm));
&mgr));
EXPECT_EQ(provider_type::sia, provider.get_provider_type());
EXPECT_FALSE(provider.is_direct_only());
EXPECT_TRUE(provider.is_online());
EXPECT_FALSE(provider.is_rename_supported());
EXPECT_TRUE(provider.is_rename_supported());
run_tests(cfg, provider);
provider.stop();
fm.stop();
mgr.stop();
}
event_system::instance().stop();
ASSERT_TRUE(utils::file::delete_directory_recursively(config_path));
}
} // namespace repertory

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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
@@ -26,34 +26,34 @@
#include "utils/utils.hpp"
namespace repertory {
static std::vector<std::string> generated_files;
std::vector<std::string> generated_files;
void delete_generated_files() {
for (const auto &f : generated_files) {
EXPECT_TRUE(utils::file::retry_delete_file(f));
for (const auto &file : generated_files) {
EXPECT_TRUE(utils::file::retry_delete_file(file));
}
}
auto create_random_file(std::string path, std::size_t size) -> native_file_ptr {
native_file_ptr nf;
if (native_file::create_or_open(path, nf) == api_error::success) {
native_file_ptr file;
if (native_file::create_or_open(path, file) == api_error::success) {
generated_files.emplace_back(utils::path::absolute(path));
EXPECT_TRUE(nf->truncate(0u));
EXPECT_TRUE(file->truncate(0U));
data_buffer buf(size);
randombytes_buf(buf.data(), buf.size());
std::size_t bytes_written{};
EXPECT_TRUE(nf->write_bytes(&buf[0u], buf.size(), 0u, bytes_written));
nf->flush();
EXPECT_TRUE(file->write_bytes(buf.data(), buf.size(), 0U, bytes_written));
file->flush();
std::uint64_t current_size;
std::uint64_t current_size{};
EXPECT_TRUE(utils::file::get_file_size(path, current_size));
EXPECT_EQ(size, current_size);
}
return nf;
return file;
}
auto generate_test_file_name(const std::string &directory,
@@ -71,10 +71,6 @@ auto get_test_dir() -> std::string {
if (not dir.empty()) {
return utils::path::absolute(dir);
}
#ifdef _WIN32
return utils::path::absolute("..\\..\\..");
#else
return utils::path::absolute("../..");
#endif
return utils::path::absolute(utils::path::combine("..", {".."}));
}
} // namespace repertory

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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
@@ -26,19 +26,14 @@
#undef U
#endif
REPERTORY_IGNORE_WARNINGS_ENABLE()
#include <gmock/gmock.h>
#include <gtest/gtest.h>
REPERTORY_IGNORE_WARNINGS_DISABLE()
#include "events/consumers/console_consumer.hpp"
#include "events/event_system.hpp"
#include "events/events.hpp"
#ifdef _WIN32
// Disable DLL-interface warnings
#pragma warning(disable : 4251)
#pragma warning(disable : 4275)
#endif
#include "utils/encryption.hpp"
#include "utils/file_utils.hpp"
#include "utils/native_file.hpp"

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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

View File

@@ -1,5 +1,5 @@
/*
Copyright <2018-2023> <scott.e.graves@protonmail.com>
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