[unit test] Complete all providers unit tests #12
This commit is contained in:
@@ -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*/)
|
||||
|
@@ -88,12 +88,6 @@ inline constexpr std::array<std::string, 17U> META_USED_NAMES = {
|
||||
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>;
|
||||
|
||||
enum class api_error {
|
||||
|
@@ -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;
|
||||
|
@@ -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{};
|
||||
|
@@ -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();
|
||||
|
@@ -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));
|
||||
|
Reference in New Issue
Block a user