From faa1f5fa3be5958d3c06943d968927a7bb4f2978 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 17 Sep 2025 18:12:06 -0500 Subject: [PATCH] [unit test] Complete all providers unit tests #12 --- .../providers/encrypt/encrypt_provider.hpp | 8 +++----- .../librepertory/include/types/repertory.hpp | 6 ------ .../librepertory/src/db/impl/rdb_meta_db.cpp | 4 ++-- .../librepertory/src/db/impl/sqlite_meta_db.cpp | 4 ++-- .../src/providers/encrypt/encrypt_provider.cpp | 15 +++++++++++++++ repertory/repertory_test/src/providers_test.cpp | 4 ++-- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/repertory/librepertory/include/providers/encrypt/encrypt_provider.hpp b/repertory/librepertory/include/providers/encrypt/encrypt_provider.hpp index ad54ea71..30b9bf84 100644 --- a/repertory/librepertory/include/providers/encrypt/encrypt_provider.hpp +++ b/repertory/librepertory/include/providers/encrypt/encrypt_provider.hpp @@ -202,11 +202,9 @@ public: return api_error::not_implemented; } - [[nodiscard]] auto remove_item_meta(const std::string & /*api_path*/, - const std::string & /*key*/) - -> api_error override { - return api_error::success; - } + [[nodiscard]] auto remove_item_meta(const std::string &api_path, + const std::string &key) + -> api_error override; [[nodiscard]] auto rename_file(const std::string & /*from_api_path*/, const std::string & /*to_api_path*/) diff --git a/repertory/librepertory/include/types/repertory.hpp b/repertory/librepertory/include/types/repertory.hpp index fb996fd2..d2f37890 100644 --- a/repertory/librepertory/include/types/repertory.hpp +++ b/repertory/librepertory/include/types/repertory.hpp @@ -88,12 +88,6 @@ inline constexpr std::array META_USED_NAMES = { META_UID, META_WRITTEN, }; -inline constexpr std::array META_PERMANENT_NAMES = { - META_DIRECTORY, - META_PINNED, - META_SIZE, - META_SOURCE, -}; using api_meta_map = std::map; enum class api_error { diff --git a/repertory/librepertory/src/db/impl/rdb_meta_db.cpp b/repertory/librepertory/src/db/impl/rdb_meta_db.cpp index 7044278e..663abba0 100644 --- a/repertory/librepertory/src/db/impl/rdb_meta_db.cpp +++ b/repertory/librepertory/src/db/impl/rdb_meta_db.cpp @@ -347,12 +347,12 @@ auto rdb_meta_db::remove_item_meta(const std::string &api_path, const std::string &key) -> api_error { 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( function_name, api_path, fmt::format("failed to remove item meta-key is restricted|key|{}", key)); - return api_error::success; + return api_error::permission_denied; } json json_data; diff --git a/repertory/librepertory/src/db/impl/sqlite_meta_db.cpp b/repertory/librepertory/src/db/impl/sqlite_meta_db.cpp index 9b764c84..44b674aa 100644 --- a/repertory/librepertory/src/db/impl/sqlite_meta_db.cpp +++ b/repertory/librepertory/src/db/impl/sqlite_meta_db.cpp @@ -308,12 +308,12 @@ auto sqlite_meta_db::remove_item_meta(const std::string &api_path, const std::string &key) -> api_error { 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( function_name, api_path, fmt::format("failed to remove item meta-key is restricted|key|{}", key)); - return api_error::success; + return api_error::permission_denied; } api_meta_map meta{}; diff --git a/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp b/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp index afdb7e65..7b5cf60d 100644 --- a/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp +++ b/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp @@ -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*/, i_file_manager * /*mgr*/) -> bool { REPERTORY_USES_FUNCTION_NAME(); diff --git a/repertory/repertory_test/src/providers_test.cpp b/repertory/repertory_test/src/providers_test.cpp index 7d61fa64..5fddf92f 100644 --- a/repertory/repertory_test/src/providers_test.cpp +++ b/repertory/repertory_test/src/providers_test.cpp @@ -1438,9 +1438,9 @@ static void remove_item_meta_restricted_names_fail(i_provider &provider) { 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}); - EXPECT_EQ(api_error::success, res); + EXPECT_EQ(api_error::permission_denied, res); api_meta_map meta{}; EXPECT_EQ(api_error::success, provider.get_item_meta(api_path, meta));