v2.0.5-rc (#41)
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
Reviewed-on: #41
This commit is contained in:
@@ -128,7 +128,7 @@ std::atomic<std::uint64_t> app_config_test::idx{0U};
|
||||
|
||||
static void defaults_tests(const json &json_data, provider_type prov) {
|
||||
json json_defaults = {
|
||||
{JSON_API_PORT, app_config::default_rpc_port(prov)},
|
||||
{JSON_API_PORT, app_config::default_rpc_port()},
|
||||
{JSON_API_USER, std::string{REPERTORY}},
|
||||
{JSON_DOWNLOAD_TIMEOUT_SECS, default_download_timeout_secs},
|
||||
{JSON_DATABASE_TYPE, database_type::rocksdb},
|
||||
@@ -185,9 +185,9 @@ static void defaults_tests(const json &json_data, provider_type prov) {
|
||||
}
|
||||
|
||||
fmt::println("testing default|{}-{}", app_config::get_provider_name(prov),
|
||||
JSON_API_AUTH);
|
||||
ASSERT_EQ(std::size_t(default_api_auth_size),
|
||||
json_data.at(JSON_API_AUTH).get<std::string>().size());
|
||||
JSON_API_PASSWORD);
|
||||
ASSERT_EQ(std::size_t(default_api_password_size),
|
||||
json_data.at(JSON_API_PASSWORD).get<std::string>().size());
|
||||
for (const auto &[key, value] : json_defaults.items()) {
|
||||
fmt::println("testing default|{}-{}", app_config::get_provider_name(prov),
|
||||
key);
|
||||
@@ -216,11 +216,11 @@ static void common_tests(app_config &config, provider_type prov) {
|
||||
ASSERT_EQ(config.get_provider_type(), prov);
|
||||
|
||||
std::map<std::string_view, std::function<void(app_config &)>> methods{
|
||||
{JSON_API_AUTH,
|
||||
{JSON_API_PASSWORD,
|
||||
[](app_config &cfg) {
|
||||
test_getter_setter(cfg, &app_config::get_api_auth,
|
||||
&app_config::set_api_auth, "", "auth",
|
||||
JSON_API_AUTH, "auth2");
|
||||
test_getter_setter(cfg, &app_config::get_api_password,
|
||||
&app_config::set_api_password, "", "auth",
|
||||
JSON_API_PASSWORD, "auth2");
|
||||
}},
|
||||
{JSON_API_PORT,
|
||||
[](app_config &cfg) {
|
||||
|
||||
198
repertory/repertory_test/src/clean_json_test.cpp
Normal file
198
repertory/repertory_test/src/clean_json_test.cpp
Normal file
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
TEST(clean_json_test, can_clean_values) {
|
||||
auto result = clean_json_value(JSON_API_PASSWORD, "moose");
|
||||
EXPECT_TRUE(result.empty());
|
||||
|
||||
result = clean_json_value(
|
||||
fmt::format("{}.{}", JSON_ENCRYPT_CONFIG, JSON_ENCRYPTION_TOKEN),
|
||||
"moose");
|
||||
EXPECT_TRUE(result.empty());
|
||||
|
||||
result = clean_json_value(
|
||||
fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_API_PASSWORD), "moose");
|
||||
EXPECT_TRUE(result.empty());
|
||||
|
||||
result = clean_json_value(
|
||||
fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_ENCRYPTION_TOKEN), "moose");
|
||||
EXPECT_TRUE(result.empty());
|
||||
|
||||
result = clean_json_value(
|
||||
fmt::format("{}.{}", JSON_REMOTE_MOUNT, JSON_ENCRYPTION_TOKEN), "moose");
|
||||
EXPECT_TRUE(result.empty());
|
||||
|
||||
result = clean_json_value(
|
||||
fmt::format("{}.{}", JSON_S3_CONFIG, JSON_ENCRYPTION_TOKEN), "moose");
|
||||
EXPECT_TRUE(result.empty());
|
||||
|
||||
result = clean_json_value(
|
||||
fmt::format("{}.{}", JSON_S3_CONFIG, JSON_SECRET_KEY), "moose");
|
||||
EXPECT_TRUE(result.empty());
|
||||
}
|
||||
|
||||
TEST(clean_json_test, can_clean_encrypt_config) {
|
||||
auto dir =
|
||||
utils::path::combine(test::get_test_output_dir(), {
|
||||
"clean_json_test",
|
||||
"encrypt",
|
||||
});
|
||||
app_config cfg(provider_type::encrypt, dir);
|
||||
cfg.set_value_by_name(JSON_API_PASSWORD, "moose");
|
||||
cfg.set_value_by_name(
|
||||
fmt::format("{}.{}", JSON_ENCRYPT_CONFIG, JSON_ENCRYPTION_TOKEN),
|
||||
"moose");
|
||||
cfg.set_value_by_name(
|
||||
fmt::format("{}.{}", JSON_REMOTE_MOUNT, JSON_ENCRYPTION_TOKEN), "moose");
|
||||
|
||||
auto data = cfg.get_json();
|
||||
EXPECT_FALSE(data.at(JSON_API_PASSWORD).get<std::string>().empty());
|
||||
EXPECT_FALSE(data.at(JSON_ENCRYPT_CONFIG)
|
||||
.at(JSON_ENCRYPTION_TOKEN)
|
||||
.get<std::string>()
|
||||
.empty());
|
||||
EXPECT_FALSE(data.at(JSON_REMOTE_MOUNT)
|
||||
.at(JSON_ENCRYPTION_TOKEN)
|
||||
.get<std::string>()
|
||||
.empty());
|
||||
|
||||
clean_json_config(cfg.get_provider_type(), data);
|
||||
EXPECT_TRUE(data.at(JSON_API_PASSWORD).get<std::string>().empty());
|
||||
EXPECT_TRUE(data.at(JSON_ENCRYPT_CONFIG)
|
||||
.at(JSON_ENCRYPTION_TOKEN)
|
||||
.get<std::string>()
|
||||
.empty());
|
||||
EXPECT_TRUE(data.at(JSON_REMOTE_MOUNT)
|
||||
.at(JSON_ENCRYPTION_TOKEN)
|
||||
.get<std::string>()
|
||||
.empty());
|
||||
}
|
||||
|
||||
TEST(clean_json_test, can_clean_remote_config) {
|
||||
auto dir =
|
||||
utils::path::combine(test::get_test_output_dir(), {
|
||||
"clean_json_test",
|
||||
"remote",
|
||||
});
|
||||
app_config cfg(provider_type::remote, dir);
|
||||
cfg.set_value_by_name(JSON_API_PASSWORD, "moose");
|
||||
cfg.set_value_by_name(
|
||||
fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_ENCRYPTION_TOKEN), "moose");
|
||||
|
||||
auto data = cfg.get_json();
|
||||
EXPECT_FALSE(data.at(JSON_API_PASSWORD).get<std::string>().empty());
|
||||
EXPECT_FALSE(data.at(JSON_REMOTE_CONFIG)
|
||||
.at(JSON_ENCRYPTION_TOKEN)
|
||||
.get<std::string>()
|
||||
.empty());
|
||||
|
||||
clean_json_config(cfg.get_provider_type(), data);
|
||||
EXPECT_TRUE(data.at(JSON_API_PASSWORD).get<std::string>().empty());
|
||||
EXPECT_TRUE(data.at(JSON_REMOTE_CONFIG)
|
||||
.at(JSON_ENCRYPTION_TOKEN)
|
||||
.get<std::string>()
|
||||
.empty());
|
||||
}
|
||||
|
||||
TEST(clean_json_test, can_clean_s3_config) {
|
||||
auto dir =
|
||||
utils::path::combine(test::get_test_output_dir(), {
|
||||
"clean_json_test",
|
||||
"s3",
|
||||
});
|
||||
app_config cfg(provider_type::s3, dir);
|
||||
cfg.set_value_by_name(JSON_API_PASSWORD, "moose");
|
||||
cfg.set_value_by_name(
|
||||
fmt::format("{}.{}", JSON_REMOTE_MOUNT, JSON_ENCRYPTION_TOKEN), "moose");
|
||||
cfg.set_value_by_name(
|
||||
fmt::format("{}.{}", JSON_S3_CONFIG, JSON_ENCRYPTION_TOKEN), "moose");
|
||||
cfg.set_value_by_name(fmt::format("{}.{}", JSON_S3_CONFIG, JSON_SECRET_KEY),
|
||||
"moose");
|
||||
|
||||
auto data = cfg.get_json();
|
||||
EXPECT_FALSE(data.at(JSON_API_PASSWORD).get<std::string>().empty());
|
||||
EXPECT_FALSE(data.at(JSON_REMOTE_MOUNT)
|
||||
.at(JSON_ENCRYPTION_TOKEN)
|
||||
.get<std::string>()
|
||||
.empty());
|
||||
EXPECT_FALSE(data.at(JSON_S3_CONFIG)
|
||||
.at(JSON_ENCRYPTION_TOKEN)
|
||||
.get<std::string>()
|
||||
.empty());
|
||||
EXPECT_FALSE(
|
||||
data.at(JSON_S3_CONFIG).at(JSON_SECRET_KEY).get<std::string>().empty());
|
||||
|
||||
clean_json_config(cfg.get_provider_type(), data);
|
||||
EXPECT_TRUE(data.at(JSON_API_PASSWORD).get<std::string>().empty());
|
||||
EXPECT_TRUE(data.at(JSON_REMOTE_MOUNT)
|
||||
.at(JSON_ENCRYPTION_TOKEN)
|
||||
.get<std::string>()
|
||||
.empty());
|
||||
EXPECT_TRUE(data.at(JSON_S3_CONFIG)
|
||||
.at(JSON_ENCRYPTION_TOKEN)
|
||||
.get<std::string>()
|
||||
.empty());
|
||||
EXPECT_TRUE(
|
||||
data.at(JSON_S3_CONFIG).at(JSON_SECRET_KEY).get<std::string>().empty());
|
||||
}
|
||||
|
||||
TEST(clean_json_test, can_clean_sia_config) {
|
||||
auto dir =
|
||||
utils::path::combine(test::get_test_output_dir(), {
|
||||
"clean_json_test",
|
||||
"sia",
|
||||
});
|
||||
app_config cfg(provider_type::sia, dir);
|
||||
cfg.set_value_by_name(JSON_API_PASSWORD, "moose");
|
||||
cfg.set_value_by_name(
|
||||
fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_API_PASSWORD), "moose");
|
||||
cfg.set_value_by_name(
|
||||
fmt::format("{}.{}", JSON_REMOTE_MOUNT, JSON_ENCRYPTION_TOKEN), "moose");
|
||||
|
||||
auto data = cfg.get_json();
|
||||
EXPECT_FALSE(data.at(JSON_API_PASSWORD).get<std::string>().empty());
|
||||
EXPECT_FALSE(data.at(JSON_HOST_CONFIG)
|
||||
.at(JSON_API_PASSWORD)
|
||||
.get<std::string>()
|
||||
.empty());
|
||||
EXPECT_FALSE(data.at(JSON_REMOTE_MOUNT)
|
||||
.at(JSON_ENCRYPTION_TOKEN)
|
||||
.get<std::string>()
|
||||
.empty());
|
||||
|
||||
clean_json_config(cfg.get_provider_type(), data);
|
||||
EXPECT_TRUE(data.at(JSON_API_PASSWORD).get<std::string>().empty());
|
||||
EXPECT_TRUE(data.at(JSON_HOST_CONFIG)
|
||||
.at(JSON_API_PASSWORD)
|
||||
.get<std::string>()
|
||||
.empty());
|
||||
EXPECT_TRUE(data.at(JSON_REMOTE_MOUNT)
|
||||
.at(JSON_ENCRYPTION_TOKEN)
|
||||
.get<std::string>()
|
||||
.empty());
|
||||
}
|
||||
} // namespace repertory
|
||||
@@ -62,13 +62,16 @@ TEST(lock_data_test, set_and_unset_mount_state) {
|
||||
|
||||
json mount_state;
|
||||
EXPECT_TRUE(l.get_mount_state(mount_state));
|
||||
|
||||
EXPECT_STREQ(R"({"Active":true,"Location":"C:","PID":99})",
|
||||
mount_state["Sia1"].dump().c_str());
|
||||
mount_state.dump().c_str());
|
||||
|
||||
EXPECT_TRUE(l2.get_mount_state(mount_state));
|
||||
EXPECT_STREQ(R"({"Active":true,"Location":"D:","PID":97})",
|
||||
mount_state["Remote1"].dump().c_str());
|
||||
mount_state.dump().c_str());
|
||||
|
||||
EXPECT_TRUE(l3.get_mount_state(mount_state));
|
||||
EXPECT_STREQ(R"({"Active":true,"Location":"E:","PID":96})",
|
||||
mount_state["Remote2"].dump().c_str());
|
||||
mount_state.dump().c_str());
|
||||
|
||||
EXPECT_TRUE(l.set_mount_state(false, "C:", 99));
|
||||
EXPECT_TRUE(l2.set_mount_state(false, "D:", 98));
|
||||
@@ -76,11 +79,15 @@ TEST(lock_data_test, set_and_unset_mount_state) {
|
||||
|
||||
EXPECT_TRUE(l.get_mount_state(mount_state));
|
||||
EXPECT_STREQ(R"({"Active":false,"Location":"","PID":-1})",
|
||||
mount_state["Sia1"].dump().c_str());
|
||||
mount_state.dump().c_str());
|
||||
|
||||
EXPECT_TRUE(l2.get_mount_state(mount_state));
|
||||
EXPECT_STREQ(R"({"Active":false,"Location":"","PID":-1})",
|
||||
mount_state["Remote1"].dump().c_str());
|
||||
mount_state.dump().c_str());
|
||||
|
||||
EXPECT_TRUE(l3.get_mount_state(mount_state));
|
||||
EXPECT_STREQ(R"({"Active":false,"Location":"","PID":-1})",
|
||||
mount_state["Remote2"].dump().c_str());
|
||||
mount_state.dump().c_str());
|
||||
}
|
||||
#else
|
||||
TEST(lock_data_test, set_and_unset_mount_state) {
|
||||
@@ -91,14 +98,13 @@ TEST(lock_data_test, set_and_unset_mount_state) {
|
||||
EXPECT_TRUE(l.get_mount_state(mount_state));
|
||||
|
||||
EXPECT_STREQ(R"({"Active":true,"Location":"/mnt/1","PID":99})",
|
||||
mount_state["Sia1"].dump().c_str());
|
||||
mount_state.dump().c_str());
|
||||
|
||||
EXPECT_TRUE(l.set_mount_state(false, "/mnt/1", 99));
|
||||
|
||||
EXPECT_TRUE(l.get_mount_state(mount_state));
|
||||
|
||||
EXPECT_STREQ(R"({"Active":false,"Location":"","PID":-1})",
|
||||
mount_state["Sia1"].dump().c_str());
|
||||
mount_state.dump().c_str());
|
||||
}
|
||||
#endif
|
||||
} // namespace repertory
|
||||
|
||||
Reference in New Issue
Block a user