[unit test] Complete all providers unit tests #12
Some checks are pending
BlockStorage/repertory/pipeline/head Build queued...
Blockstorage/repertory/pipeline/head This commit looks good

This commit is contained in:
2025-09-17 18:12:06 -05:00
parent e5df094da4
commit faa1f5fa3b
6 changed files with 24 additions and 17 deletions

View File

@@ -202,11 +202,9 @@ public:
return api_error::not_implemented; return api_error::not_implemented;
} }
[[nodiscard]] auto remove_item_meta(const std::string & /*api_path*/, [[nodiscard]] auto remove_item_meta(const std::string &api_path,
const std::string & /*key*/) const std::string &key)
-> api_error override { -> api_error override;
return api_error::success;
}
[[nodiscard]] auto rename_file(const std::string & /*from_api_path*/, [[nodiscard]] auto rename_file(const std::string & /*from_api_path*/,
const std::string & /*to_api_path*/) const std::string & /*to_api_path*/)

View File

@@ -88,12 +88,6 @@ inline constexpr std::array<std::string, 17U> META_USED_NAMES = {
META_UID, META_WRITTEN, META_UID, META_WRITTEN,
}; };
inline constexpr std::array<std::string, 4U> META_PERMANENT_NAMES = {
META_DIRECTORY,
META_PINNED,
META_SIZE,
META_SOURCE,
};
using api_meta_map = std::map<std::string, std::string>; using api_meta_map = std::map<std::string, std::string>;
enum class api_error { enum class api_error {

View File

@@ -347,12 +347,12 @@ auto rdb_meta_db::remove_item_meta(const std::string &api_path,
const std::string &key) -> api_error { const std::string &key) -> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if (utils::collection::includes(META_PERMANENT_NAMES, key)) { if (utils::collection::includes(META_USED_NAMES, key)) {
utils::error::raise_api_path_error( utils::error::raise_api_path_error(
function_name, api_path, function_name, api_path,
fmt::format("failed to remove item meta-key is restricted|key|{}", fmt::format("failed to remove item meta-key is restricted|key|{}",
key)); key));
return api_error::success; return api_error::permission_denied;
} }
json json_data; json json_data;

View File

@@ -308,12 +308,12 @@ auto sqlite_meta_db::remove_item_meta(const std::string &api_path,
const std::string &key) -> api_error { const std::string &key) -> api_error {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
if (utils::collection::includes(META_PERMANENT_NAMES, key)) { if (utils::collection::includes(META_USED_NAMES, key)) {
utils::error::raise_api_path_error( utils::error::raise_api_path_error(
function_name, api_path, function_name, api_path,
fmt::format("failed to remove item meta-key is restricted|key|{}", fmt::format("failed to remove item meta-key is restricted|key|{}",
key)); key));
return api_error::success; return api_error::permission_denied;
} }
api_meta_map meta{}; api_meta_map meta{};

View File

@@ -906,6 +906,21 @@ void encrypt_provider::remove_expired_files() {
} }
} }
auto encrypt_provider::remove_item_meta(const std::string &api_path,
const std::string &key) -> api_error {
REPERTORY_USES_FUNCTION_NAME();
if (utils::collection::includes(META_USED_NAMES, key)) {
utils::error::raise_api_path_error(
function_name, api_path,
fmt::format("failed to remove item meta-key is restricted|key|{}",
key));
return api_error::permission_denied;
}
return api_error::success;
}
auto encrypt_provider::start(api_item_added_callback /*api_item_added*/, auto encrypt_provider::start(api_item_added_callback /*api_item_added*/,
i_file_manager * /*mgr*/) -> bool { i_file_manager * /*mgr*/) -> bool {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();

View File

@@ -1438,9 +1438,9 @@ static void remove_item_meta_restricted_names_fail(i_provider &provider) {
create_file(provider, api_path); create_file(provider, api_path);
} }
for (const auto &key : META_PERMANENT_NAMES) { for (const auto &key : META_USED_NAMES) {
auto res = provider.remove_item_meta(api_path, std::string{key}); auto res = provider.remove_item_meta(api_path, std::string{key});
EXPECT_EQ(api_error::success, res); EXPECT_EQ(api_error::permission_denied, res);
api_meta_map meta{}; api_meta_map meta{};
EXPECT_EQ(api_error::success, provider.get_item_meta(api_path, meta)); EXPECT_EQ(api_error::success, provider.get_item_meta(api_path, meta));