diff --git a/services/distributeddataservice/service/data_share/BUILD.gn b/services/distributeddataservice/service/data_share/BUILD.gn index 01d7396bd3b18b3774ede83f6574e646685bce28..788eceec20f2224e530a7c8ab12c7646d772dd0a 100644 --- a/services/distributeddataservice/service/data_share/BUILD.gn +++ b/services/distributeddataservice/service/data_share/BUILD.gn @@ -60,7 +60,7 @@ ohos_source_set("data_share_service") { "common/rdb_delegate.cpp", "common/scheduler_manager.cpp", "common/seq_strategy.cpp", - "common/uri_utils.cpp", + "common/utils.cpp", "data/published_data.cpp", "data/resultset_json_formatter.cpp", "data/template_data.cpp", diff --git a/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp b/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp index 267a66c32ffa41bc3041f5ce9b2e10b251ae02cf..afd7e1f4f8523c9f76f3fdd4738ced256f1efcd3 100644 --- a/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp +++ b/services/distributeddataservice/service/data_share/common/bundle_mgr_proxy.cpp @@ -23,7 +23,7 @@ #include "iservice_registry.h" #include "log_print.h" #include "system_ability_definition.h" -#include "uri_utils.h" +#include "utils.h" #include "ipc_skeleton.h" #include "hiview_fault_adapter.h" diff --git a/services/distributeddataservice/service/data_share/common/context.h b/services/distributeddataservice/service/data_share/common/context.h index d19ebf6d162a7d690c2f02bce781b0bc98e8c47d..e7043d23f4e195b17ffe15d550135dbc0041b2de 100644 --- a/services/distributeddataservice/service/data_share/common/context.h +++ b/services/distributeddataservice/service/data_share/common/context.h @@ -16,6 +16,7 @@ #ifndef DATASHARESERVICE_CONTEXT_H #define DATASHARESERVICE_CONTEXT_H +#include #include #include #include @@ -34,7 +35,13 @@ class Context { public: explicit Context() {} explicit Context(const std::string &uri) : uri(uri) {} - virtual ~Context() = default; + virtual ~Context() + { + if (secretMetaKey.size() > 0) { + std::fill(secretMetaKey.begin(), secretMetaKey.end(), '\0'); + } + } + std::string uri; int32_t currentUserId = -1; int32_t visitedUserId = -1; diff --git a/services/distributeddataservice/service/data_share/common/db_delegate.cpp b/services/distributeddataservice/service/data_share/common/db_delegate.cpp index 06c408e755353a3c26335a90b119a493a78e4a06..9e77bcbb4dece55fc62f1ac907b7be2f95bbed01 100644 --- a/services/distributeddataservice/service/data_share/common/db_delegate.cpp +++ b/services/distributeddataservice/service/data_share/common/db_delegate.cpp @@ -34,7 +34,7 @@ std::shared_ptr DBDelegate::Create(DistributedData::StoreMetaData &m { if (Account::GetInstance()->IsDeactivating(atoi(metaData.user.c_str()))) { ZLOGW("user %{public}s is deactivating, storeName: %{public}s", metaData.user.c_str(), - metaData.GetStoreAlias().c_str()); + StringUtils::GeneralAnonymous(metaData.GetStoreAlias()).c_str()); return nullptr; } std::shared_ptr store; @@ -63,7 +63,7 @@ std::shared_ptr DBDelegate::Create(DistributedData::StoreMetaData &m if (success) { return store; } - ZLOGE("creator failed, storeName: %{public}s", metaData.GetStoreAlias().c_str()); + ZLOGE("creator failed, storeName: %{public}s", StringUtils::GeneralAnonymous(metaData.GetStoreAlias()).c_str()); auto eraseFunc = [&metaData] (auto &, std::map> &stores) -> bool { stores.erase(metaData.storeId); @@ -167,13 +167,13 @@ void DBDelegate::EraseStoreCache(const int32_t tokenId) storesEncrypt_.Erase(tokenId); } -std::shared_ptr KvDBDelegate::GetInstance(const std::string &dir, - const std::shared_ptr &executors) +std::shared_ptr KvDBDelegate::GetInstance(const std::string &dir, + const std::shared_ptr &executors) { static std::shared_ptr delegate = nullptr; static std::mutex mutex; std::lock_guard lock(mutex); - if (delegate == nullptr && executors != nullptr) { + if (delegate == nullptr && executors != nullptr) { delegate = std::make_shared(dir, executors); } return delegate; @@ -215,4 +215,4 @@ const std::string &KvData::GetId() const } KvData::KvData(const Id &id) : id(DistributedData::Serializable::Marshall(id)) {} -} // namespace OHOS::DataShare +} // namespace OHOS::DataShare diff --git a/services/distributeddataservice/service/data_share/common/extension_ability_manager.cpp b/services/distributeddataservice/service/data_share/common/extension_ability_manager.cpp index 2328285df370c1f67f2b2bcc51788ba1d3e28416..fa1011fde7489a4fadd8730809dbcad0c8f76169 100644 --- a/services/distributeddataservice/service/data_share/common/extension_ability_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/extension_ability_manager.cpp @@ -19,7 +19,7 @@ #include "extension_mgr_proxy.h" #include "log_print.h" #include "datashare_errno.h" -#include "uri_utils.h" +#include "utils.h" namespace OHOS::DataShare { ExtensionAbilityManager &ExtensionAbilityManager::GetInstance() diff --git a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp index 5578adbc1f97de0d12971a6ed0a85acbc7249e0a..e89b5734c65b3c5180e8c5db8b7c8b2bdd28e37e 100644 --- a/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp +++ b/services/distributeddataservice/service/data_share/common/extension_connect_adaptor.cpp @@ -24,7 +24,7 @@ #include "extension_ability_info.h" #include "extension_mgr_proxy.h" #include "log_print.h" -#include "uri_utils.h" +#include "utils.h" namespace OHOS::DataShare { ExtensionConnectAdaptor::ExtensionConnectAdaptor() : data_(std::make_shared>(1)) diff --git a/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.cpp b/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.cpp index dacd6ce8826dc757ba5b0839b4d41bc2d3ecd8c0..fce328cda61ba9d72c575d9dfe4a406eaba3b4f8 100644 --- a/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.cpp +++ b/services/distributeddataservice/service/data_share/common/extension_mgr_proxy.cpp @@ -23,7 +23,7 @@ #include "log_print.h" #include "system_ability_definition.h" #include "want.h" -#include "uri_utils.h" +#include "utils.h" #include "datashare_errno.h" namespace OHOS::DataShare { diff --git a/services/distributeddataservice/service/data_share/common/proxy_data_manager.cpp b/services/distributeddataservice/service/data_share/common/proxy_data_manager.cpp index 61f7cb37ba184d2afc9ab63b52a5902c90ae5685..18a7b53638bba26d8af0210612673f6166ae8932 100644 --- a/services/distributeddataservice/service/data_share/common/proxy_data_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/proxy_data_manager.cpp @@ -20,7 +20,7 @@ #include "dataproxy_handle_common.h" #include "log_print.h" #include "proxy_data_manager.h" -#include "uri_utils.h" +#include "utils.h" #include "utils/anonymous.h" namespace OHOS::DataShare { @@ -201,7 +201,8 @@ int32_t PublishedProxyData::InsertProxyData(std::shared_ptr kvDele kvDelegate->Get(KvDBDelegate::PROXYDATA_TABLE, listFilter, "{}", listQueryResult); if (!listQueryResult.empty()) { if (!ProxyDataListNode::Unmarshall(listQueryResult, proxyDataList)) { - ZLOGE("ProxyDataListNode unmarshall failed, %{private}s", listQueryResult.c_str()); + ZLOGE("ProxyDataListNode unmarshall failed, %{public}s", + StringUtils::GeneralAnonymous(listQueryResult).c_str()); return INNER_ERROR; } } @@ -251,7 +252,7 @@ int32_t PublishedProxyData::Query(const std::string &uri, const BundleInfo &call } ProxyDataNode data; if (!ProxyDataNode::Unmarshall(queryResult, data)) { - ZLOGE("Unmarshall failed, %{private}s", queryResult.c_str()); + ZLOGE("Unmarshall failed, %{public}s", StringUtils::GeneralAnonymous(queryResult).c_str()); return INNER_ERROR; } DataShareProxyData tempProxyData(data.proxyData.uri, data.proxyData.value, data.proxyData.allowList); @@ -290,7 +291,7 @@ int32_t PublishedProxyData::Upsert(const DataShareProxyData &proxyData, const Bu } else { ProxyDataNode oldData; if (!ProxyDataNode::Unmarshall(queryResult, oldData)) { - ZLOGE("ProxyDataNode unmarshall failed, %{private}s", queryResult.c_str()); + ZLOGE("ProxyDataNode unmarshall failed, %{public}s", StringUtils::GeneralAnonymous(queryResult).c_str()); return INNER_ERROR; } if (callerBundleInfo.tokenId != oldData.tokenId) { @@ -384,7 +385,7 @@ int32_t ProxyDataList::Query(uint32_t tokenId, int32_t userId, std::vector RdbDelegate::InsertEx(const std::string &tableName, ValuesBucket bucket = RdbDataShareAdapter::RdbUtils::ToValuesBucket(valuesBucket); int ret = store_->Insert(rowId, tableName, bucket); if (ret != E_OK) { - ZLOGE("Insert failed %{public}s %{public}d", tableName.c_str(), ret); + ZLOGE("Insert failed %{public}s %{public}d", StringUtils::GeneralAnonymous(tableName).c_str(), ret); RADAR_REPORT(__FUNCTION__, RadarReporter::SILENT_ACCESS, RadarReporter::PROXY_CALL_RDB, RadarReporter::FAILED, RadarReporter::ERROR_CODE, RadarReporter::INSERT_RDB_ERROR); if (ret == E_SQLITE_ERROR) { @@ -200,7 +202,7 @@ std::pair RdbDelegate::UpdateEx( RdbPredicates predicates = RdbDataShareAdapter::RdbUtils::ToPredicates(predicate, tableName); int ret = store_->Update(changeCount, bucket, predicates); if (ret != E_OK) { - ZLOGE("Update failed %{public}s %{public}d", tableName.c_str(), ret); + ZLOGE("Update failed %{public}s %{public}d", StringUtils::GeneralAnonymous(tableName).c_str(), ret); RADAR_REPORT(__FUNCTION__, RadarReporter::SILENT_ACCESS, RadarReporter::PROXY_CALL_RDB, RadarReporter::FAILED, RadarReporter::ERROR_CODE, RadarReporter::UPDATE_RDB_ERROR); if (ret == E_SQLITE_ERROR) { @@ -222,7 +224,7 @@ std::pair RdbDelegate::DeleteEx(const std::string &tableName, RdbPredicates predicates = RdbDataShareAdapter::RdbUtils::ToPredicates(predicate, tableName); int ret = store_->Delete(changeCount, predicates); if (ret != E_OK) { - ZLOGE("Delete failed %{public}s %{public}d", tableName.c_str(), ret); + ZLOGE("Delete failed %{public}s %{public}d", StringUtils::GeneralAnonymous(tableName).c_str(), ret); RADAR_REPORT(__FUNCTION__, RadarReporter::SILENT_ACCESS, RadarReporter::PROXY_CALL_RDB, RadarReporter::FAILED, RadarReporter::ERROR_CODE, RadarReporter::DELETE_RDB_ERROR); if (ret == E_SQLITE_ERROR) { @@ -252,7 +254,7 @@ std::pair> RdbDelegate::Query(const std if (resultSet == nullptr) { RADAR_REPORT(__FUNCTION__, RadarReporter::SILENT_ACCESS, RadarReporter::PROXY_CALL_RDB, RadarReporter::FAILED, RadarReporter::ERROR_CODE, RadarReporter::QUERY_RDB_ERROR); - ZLOGE("Query failed %{public}s, pid: %{public}d", tableName.c_str(), callingPid); + ZLOGE("Query failed %{public}s, pid: %{public}d", StringUtils::GeneralAnonymous(tableName).c_str(), callingPid); resultSetCount--; return std::make_pair(E_ERROR, nullptr); } diff --git a/services/distributeddataservice/service/data_share/common/rdb_delegate.h b/services/distributeddataservice/service/data_share/common/rdb_delegate.h index 3fe8b3dce8395ce402089c3db4bf1a72477e0c13..9c8fcd7dd04742a53219e763a77f9bd4f5f12576 100644 --- a/services/distributeddataservice/service/data_share/common/rdb_delegate.h +++ b/services/distributeddataservice/service/data_share/common/rdb_delegate.h @@ -24,17 +24,17 @@ #include "rdb_errno.h" #include "rdb_helper.h" #include "rdb_store.h" -#include "uri_utils.h" +#include "utils.h" #include "rdb_utils.h" namespace OHOS::DataShare { using namespace OHOS::NativeRdb; class RdbDelegate final : public DBDelegate { public: - explicit RdbDelegate(); + explicit RdbDelegate(); ~RdbDelegate(); - bool Init(const DistributedData::StoreMetaData &meta, int version, - bool registerFunction, const std::string &extUri, const std::string &backup) override; + bool Init(const DistributedData::StoreMetaData &meta, int version, + bool registerFunction, const std::string &extUri, const std::string &backup) override; std::pair> Query(const std::string &tableName, const DataSharePredicates &predicates, const std::vector &columns, int32_t callingPid, uint32_t callingTokenId) override; @@ -60,15 +60,15 @@ private: static constexpr int RETRY = 3; static constexpr const char *DUAL_WRITE = "dualWrite"; static constexpr const char *PERIODIC = "periodic"; - uint32_t tokenId_ = 0; - std::string bundleName_ = ""; - std::string storeName_ = ""; - int32_t haMode_ = 0; - std::string extUri_ = ""; - std::string backup_ = ""; - std::string user_ = ""; - std::mutex initMutex_; - bool isInited_ = false; + uint32_t tokenId_ = 0; + std::string bundleName_ = ""; + std::string storeName_ = ""; + int32_t haMode_ = 0; + std::string extUri_ = ""; + std::string backup_ = ""; + std::string user_ = ""; + std::mutex initMutex_; + bool isInited_ = false; }; class DefaultOpenCallback : public RdbOpenCallback { public: diff --git a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp index deb94a7b0cd4813bcc85690dc05f129cf888cbe4..79f19c6012a9a097c8d1f760c96abda2d8583885 100644 --- a/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/scheduler_manager.cpp @@ -20,7 +20,7 @@ #include "log_print.h" #include "timer_info.h" -#include "uri_utils.h" +#include "utils.h" #include "utils/anonymous.h" #include "log_debug.h" diff --git a/services/distributeddataservice/service/data_share/common/uri_utils.cpp b/services/distributeddataservice/service/data_share/common/utils.cpp similarity index 87% rename from services/distributeddataservice/service/data_share/common/uri_utils.cpp rename to services/distributeddataservice/service/data_share/common/utils.cpp index 065dfd75e8cbf4058b1d46668f9a024e249cfc34..6f30af21c9b764f6936aa2dd313e9d25042df2c5 100644 --- a/services/distributeddataservice/service/data_share/common/uri_utils.cpp +++ b/services/distributeddataservice/service/data_share/common/utils.cpp @@ -12,9 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#define LOG_TAG "URIUtils" +#define LOG_TAG "Utils" -#include "uri_utils.h" +#include "utils.h" #include @@ -24,6 +24,10 @@ #include "utils/anonymous.h" namespace OHOS::DataShare { +// Size of the characters that need to be left for both head and tail. +constexpr int32_t REVEAL_SIZE = 4; +constexpr const char *REPLACE_CHAIN = "***"; +constexpr const char *DEFAULT_ANONYMOUS = "******"; bool URIUtils::GetInfoFromURI(const std::string &uri, UriInfo &uriInfo) { Uri uriTemp(uri); @@ -147,7 +151,7 @@ std::pair URIUtils::Strtoul(const std::string &str) } char* end = nullptr; errno = 0; - data = strtoul(str.c_str(), &end, 10); + data = strtoul(str.c_str(), &end, END_LENGTH); if (errno == ERANGE || end == nullptr || end == str || *end != '\0') { return std::make_pair(false, data); } @@ -180,4 +184,20 @@ std::map URIUtils::GetQueryParams(const std::string& u } return params; } + +std::string StringUtils::GeneralAnonymous(const std::string &name) +{ + // To short to be partial anonymized + if (name.length() <= REVEAL_SIZE) { + return DEFAULT_ANONYMOUS; + } + + // only leave HEAD + if (name.length() <= (REVEAL_SIZE + REVEAL_SIZE)) { + return (name.substr(0, REVEAL_SIZE) + REPLACE_CHAIN); + } + // leave 4 char at head and tail respectively + return (name.substr(0, REVEAL_SIZE) + REPLACE_CHAIN + name.substr(name.length() - REVEAL_SIZE, REVEAL_SIZE)); +} + } // namespace OHOS::DataShare \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/common/uri_utils.h b/services/distributeddataservice/service/data_share/common/utils.h similarity index 78% rename from services/distributeddataservice/service/data_share/common/uri_utils.h rename to services/distributeddataservice/service/data_share/common/utils.h index 8f2298506f8c454cfad95dd44f162a7aa23c181c..de55c6b0320315e59fcd5dc96dde027e19eba11a 100644 --- a/services/distributeddataservice/service/data_share/common/uri_utils.h +++ b/services/distributeddataservice/service/data_share/common/utils.h @@ -35,6 +35,24 @@ struct UriConfig { std::string scheme; }; +class StringUtils { +public: + /** + * @brief Anonymizes the input string by preserving specified length at head/tail + * and replacing the middle part with placeholder + * @param name Original string to be processed (non-empty assumed) + * @return std::string Anonymized result according to length rules: + * 1. Length <= 4: Returns DEFAULT_ANONYMOUS ("******") + * 2. 4 < Length <= 8: Returns first 4 chars + REPLACE_CHAIN ("***") + * 3. Length > 8: Returns first 4 chars + REPLACE_CHAIN + last 4 chars + * @example + * "abcdefghi" -> "abcd***fghi" + * "12345" -> "1234***" + * "AB" -> "******" + */ + static std::string GeneralAnonymous(const std::string &name); +}; + class URIUtils { public: static bool GetInfoFromURI(const std::string &uri, UriInfo &uriInfo); @@ -67,7 +85,6 @@ private: PARAM_SIZE }; static constexpr int32_t END_LENGTH = 10; - static constexpr const char *DEFAULT_ANONYMOUS = "******"; }; } // namespace OHOS::DataShare #endif // DATASHARESERVICE_URI_UTILS_H diff --git a/services/distributeddataservice/service/data_share/data/published_data.cpp b/services/distributeddataservice/service/data_share/data/published_data.cpp index 359db675e1d56fa28cfc87985f2e70c07b0c895d..d8c6960a2e0255638522dde7d11eca2f106e9f4e 100644 --- a/services/distributeddataservice/service/data_share/data/published_data.cpp +++ b/services/distributeddataservice/service/data_share/data/published_data.cpp @@ -18,6 +18,7 @@ #include "log_print.h" #include "subscriber_managers/published_data_subscriber_manager.h" #include "utils/base64_utils.h" +#include "utils.h" namespace OHOS::DataShare { bool PublishedData::HasVersion() const @@ -151,7 +152,7 @@ int32_t PublishedData::Query(const std::string &filter, PublishedDataNode::Data } PublishedDataNode data; if (!PublishedDataNode::Unmarshall(queryResult, data)) { - ZLOGE("Unmarshall failed, %{private}s", queryResult.c_str()); + ZLOGE("Unmarshall failed, %{public}s", StringUtils::GeneralAnonymous(queryResult).c_str()); return E_ERROR; } publishedData = std::move(data.value); @@ -235,12 +236,12 @@ void PublishedData::UpdateTimestamp( int32_t status = delegate->Get(KvDBDelegate::DATA_TABLE, Id(GenId(key, bundleName, subscriberId), userId), queryResult); if (status != E_OK) { - ZLOGE("db Get failed, %{private}s %{public}d", queryResult.c_str(), status); + ZLOGE("db Get failed, %{public}s %{public}d", StringUtils::GeneralAnonymous(queryResult).c_str(), status); return; } PublishedDataNode data; if (!PublishedDataNode::Unmarshall(queryResult, data)) { - ZLOGE("Unmarshall failed, %{private}s", queryResult.c_str()); + ZLOGE("Unmarshall failed, %{public}s", StringUtils::GeneralAnonymous(queryResult).c_str()); return; } auto now = time(nullptr); @@ -251,7 +252,7 @@ void PublishedData::UpdateTimestamp( data.timestamp = now; auto [errorCode, count] = delegate->Upsert(KvDBDelegate::DATA_TABLE, PublishedData(data)); if (errorCode == E_OK) { - ZLOGI("update timestamp %{private}s", data.key.c_str()); + ZLOGI("update timestamp %{public}s", StringUtils::GeneralAnonymous(data.key).c_str()); } } diff --git a/services/distributeddataservice/service/data_share/data_provider_config.cpp b/services/distributeddataservice/service/data_share/data_provider_config.cpp index 11c5328cf83505f7ce60bee0ece1a48b4ab78123..f6f13b3d3321c0d0d5cc30ff2659cf6ff9e5039e 100644 --- a/services/distributeddataservice/service/data_share/data_provider_config.cpp +++ b/services/distributeddataservice/service/data_share/data_provider_config.cpp @@ -27,7 +27,7 @@ #include "log_print.h" #include "strategies/general/load_config_common_strategy.h" #include "tokenid_kit.h" -#include "uri_utils.h" +#include "utils.h" #include "utils/anonymous.h" namespace OHOS::DataShare { @@ -243,7 +243,7 @@ std::pair DataProviderConfig::GetProvider if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId) || (result == Security::AccessToken::RET_SUCCESS && !IsInExtList(tokenInfo.bundleName))) { ZLOGE("The URI in the extension, is not allowed for silent access.! ret: %{public}d, bundleName: %{public}s," - "uri: %{public}s", ret, tokenInfo.bundleName.c_str(), providerInfo_.uri.c_str()); + "uri: %{public}s", ret, tokenInfo.bundleName.c_str(), URIUtils::Anonymous(providerInfo_.uri).c_str()); } ret = GetFromExtension(); if (ret != E_OK) { diff --git a/services/distributeddataservice/service/data_share/data_provider_config.h b/services/distributeddataservice/service/data_share/data_provider_config.h index 99099ce8ac4cf8801d32c7f9072aa7dfa25818ce..c1acce432eccbe401c5da4c92b265f231335fac9 100644 --- a/services/distributeddataservice/service/data_share/data_provider_config.h +++ b/services/distributeddataservice/service/data_share/data_provider_config.h @@ -22,7 +22,7 @@ #include "bundle_mgr_proxy.h" #include "data_share_profile_config.h" #include "hap_module_info.h" -#include "uri_utils.h" +#include "utils.h" namespace OHOS::DataShare { using ExtensionAbility = OHOS::AppExecFwk::ExtensionAbilityInfo; diff --git a/services/distributeddataservice/service/data_share/data_share_db_config.cpp b/services/distributeddataservice/service/data_share/data_share_db_config.cpp index fb72f0c29e45cdf7b80da84fa4b6f70e6483cb33..dc25bcafd6563eef8f8c4eb7154c761561db617e 100644 --- a/services/distributeddataservice/service/data_share/data_share_db_config.cpp +++ b/services/distributeddataservice/service/data_share/data_share_db_config.cpp @@ -26,7 +26,7 @@ #include "log_print.h" #include "metadata/meta_data_manager.h" #include "metadata/store_meta_data.h" -#include "uri_utils.h" +#include "utils.h" #include "utils/anonymous.h" #include "ipc_skeleton.h" @@ -74,8 +74,8 @@ std::tuple> Dat auto [errCode, metaData] = GetMetaData(dbConfig); if (errCode != E_OK) { ZLOGE("DB not exist,bundleName:%{public}s,storeName:%{public}s,user:%{public}d,err:%{public}d,uri:%{public}s", - dbConfig.bundleName.c_str(), dbConfig.storeName.c_str(), dbConfig.userId, errCode, - URIUtils::Anonymous(dbConfig.uri).c_str()); + dbConfig.bundleName.c_str(), StringUtils::GeneralAnonymous(dbConfig.storeName).c_str(), dbConfig.userId, + errCode, URIUtils::Anonymous(dbConfig.uri).c_str()); RADAR_REPORT(__FUNCTION__, RadarReporter::SILENT_ACCESS, RadarReporter::PROXY_MATEDATA_EXISTS, RadarReporter::FAILED, RadarReporter::ERROR_CODE, RadarReporter::META_DATA_NOT_EXISTS); return std::make_tuple(errCode, metaData, nullptr); diff --git a/services/distributeddataservice/service/data_share/data_share_db_config.h b/services/distributeddataservice/service/data_share/data_share_db_config.h index 88efe930efe5fd4e58b9db46d822ad5f0f97d081..ff4e32b9f484bad50bf7745ca4f524407eaebbd3 100644 --- a/services/distributeddataservice/service/data_share/data_share_db_config.h +++ b/services/distributeddataservice/service/data_share/data_share_db_config.h @@ -23,7 +23,7 @@ #include "db_delegate.h" #include "extension_ability_info.h" #include "metadata/store_meta_data.h" -#include "uri_utils.h" +#include "utils.h" namespace OHOS::DataShare { class DataShareDbConfig { diff --git a/services/distributeddataservice/service/data_share/data_share_profile_config.cpp b/services/distributeddataservice/service/data_share/data_share_profile_config.cpp index 354a196ed189b69628a73582a3d948f28daebd1c..de4a8f65742af116556df812666f98303ae305bd 100644 --- a/services/distributeddataservice/service/data_share/data_share_profile_config.cpp +++ b/services/distributeddataservice/service/data_share/data_share_profile_config.cpp @@ -26,7 +26,7 @@ #include "bundle_mgr_proxy.h" #include "datashare_errno.h" #include "log_print.h" -#include "uri_utils.h" +#include "utils.h" #include "utils/anonymous.h" #include "log_debug.h" @@ -36,6 +36,7 @@ constexpr const char *PROFILE_FILE_PREFIX = "$profile:"; constexpr const char *SEPARATOR = "/"; static constexpr int PATH_SIZE = 2; static constexpr int MAX_ALLOWLIST_COUNT = 256; +static constexpr size_t MAX_FILE_SIZE = 10 * 1024 * 1024; const size_t PROFILE_PREFIX_LEN = strlen(PROFILE_FILE_PREFIX); bool Config::Marshal(json &node) const { @@ -281,12 +282,13 @@ std::string DataShareProfileConfig::GetResFromResMgr( std::string resPath; RState ret = resMgr.GetProfileByName(profileName.c_str(), resPath); if (ret != RState::SUCCESS) { - ZLOGE("profileName not found, ret is %{public}d, profileName is %{public}s", ret, profileName.c_str()); + ZLOGE("profileName not found, ret is %{public}d, profileName is %{public}s", ret, + StringUtils::GeneralAnonymous(profileName).c_str()); return profileInfo; } std::string profile = ReadProfile(resPath); if (profile.empty()) { - ZLOGE("Read profile failed, resPath is %{public}s", resPath.c_str()); + ZLOGE("Read profile failed, resPath is %{public}s", URIUtils::Anonymous(resPath).c_str()); return profileInfo; } return profile; @@ -298,7 +300,8 @@ bool DataShareProfileConfig::IsFileExisted(const std::string &filePath) return false; } if (access(filePath.c_str(), F_OK) != 0) { - ZLOGE("can not access file, errno is %{public}d, filePath is %{public}s", errno, filePath.c_str()); + ZLOGE("can not access file, errno is %{public}d, filePath is %{public}s", errno, + URIUtils::Anonymous(filePath).c_str()); return false; } return true; @@ -319,7 +322,10 @@ std::string DataShareProfileConfig::ReadProfile(const std::string &resPath) tmp << in.rdbuf(); std::string content = tmp.str(); if (content.empty()) { - ZLOGE("the file is empty, resPath is %{public}s", resPath.c_str()); + ZLOGE("the file is empty, resPath is %{public}s", URIUtils::Anonymous(resPath).c_str()); + return ""; + } else if (content.length() > MAX_FILE_SIZE) { + ZLOGE("the file is too large, resPath is %{public}s,", URIUtils::Anonymous(resPath).c_str()); return ""; } return content; diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index e261fcc0defc5768ee4de34a2204917483f8c915..380db75bd0cac15dd032091cf70835d22d5c0ba1 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -45,7 +45,7 @@ #include "ipc_skeleton.h" #include "iservice_registry.h" #include "log_print.h" -#include "common/uri_utils.h" +#include "common/utils.h" #include "metadata/auto_launch_meta_data.h" #include "metadata/meta_data_manager.h" #include "matching_skills.h" @@ -929,15 +929,16 @@ int32_t DataShareServiceImpl::OnAppUpdate(const std::string &bundleName, int32_t void DataShareServiceImpl::NotifyObserver(const std::string &uri) { - ZLOGD_MACRO("%{private}s try notified", uri.c_str()); + auto anonymous = URIUtils::Anonymous(uri); + ZLOGD_MACRO("%{private}s try notified", anonymous.c_str()); auto context = std::make_shared(uri); if (!GetCallerBundleName(context->callerBundleName)) { - ZLOGE("get bundleName error, %{private}s", uri.c_str()); + ZLOGE("get bundleName error, %{private}s", anonymous.c_str()); return; } auto ret = rdbNotifyStrategy_.Execute(context); if (ret) { - ZLOGI("%{private}s start notified", uri.c_str()); + ZLOGI("%{private}s start notified", anonymous.c_str()); RdbSubscriberManager::GetInstance().Emit(uri, context); } } @@ -1252,7 +1253,7 @@ std::pair DataShareServiceImpl::ExecuteEx(const std::string &u auto [code, metaData, dbDelegate] = dbConfig.GetDbConfig(config); if (code != E_OK) { ZLOGE("Get dbConfig fail,bundleName:%{public}s,tableName:%{public}s,tokenId:0x%{public}x, uri:%{public}s", - providerInfo.bundleName.c_str(), providerInfo.tableName.c_str(), tokenId, + providerInfo.bundleName.c_str(), StringUtils::GeneralAnonymous(providerInfo.tableName).c_str(), tokenId, URIUtils::Anonymous(providerInfo.uri).c_str()); return std::make_pair(code, 0); } @@ -1321,7 +1322,7 @@ int32_t DataShareServiceImpl::GetBMSAndMetaDataStatus(const std::string &uri, co auto [code, metaData] = dbConfig.GetMetaData(dbArg); if (code != E_OK) { ZLOGE("Get metaData fail,bundleName:%{public}s,tableName:%{public}s,tokenId:0x%{public}x, uri:%{public}s", - calledInfo.bundleName.c_str(), DistributedData::Anonymous::Change(calledInfo.tableName).c_str(), tokenId, + calledInfo.bundleName.c_str(), StringUtils::GeneralAnonymous(calledInfo.tableName).c_str(), tokenId, URIUtils::Anonymous(calledInfo.uri).c_str()); return E_METADATA_NOT_EXISTS; } diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.h b/services/distributeddataservice/service/data_share/data_share_service_impl.h index 8408c10f9374d8a8e9700f36e4b206ba675d59f7..1ac35e89988bf6c06c563625df1783ae2e32fbc7 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.h +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.h @@ -40,7 +40,7 @@ #include "rdb_notify_strategy.h" #include "subscribe_strategy.h" #include "template_strategy.h" -#include "uri_utils.h" +#include "utils.h" #include "visibility.h" namespace OHOS::DataShare { diff --git a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp index eb5b6b49837baf0e43598372dceccd6b4205fff5..abaf236fb508a1b39db55636d7d573943b986eef 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_stub.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_stub.cpp @@ -29,7 +29,7 @@ #include "itypes_util.h" #include "log_print.h" #include "qos_manager.h" -#include "uri_utils.h" +#include "utils.h" #include "utils/anonymous.h" #include "dataproxy_handle_common.h" diff --git a/services/distributeddataservice/service/data_share/data_share_silent_config.cpp b/services/distributeddataservice/service/data_share/data_share_silent_config.cpp index 2f71fd3acaf0d7e592fa225a8ecc5dd7f77de173..eee4709aac1988c84b7a832e224acd352aaae53a 100644 --- a/services/distributeddataservice/service/data_share/data_share_silent_config.cpp +++ b/services/distributeddataservice/service/data_share/data_share_silent_config.cpp @@ -23,7 +23,7 @@ #include "hap_token_info.h" #include "ipc_skeleton.h" #include "log_print.h" -#include "uri_utils.h" +#include "utils.h" #include "utils/anonymous.h" namespace OHOS::DataShare { diff --git a/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp index 60d643d4b8145108b87d0783cc86d1de00f1e3e7..1810afacd486f4d77bd5968f8ac1f77bcc9a165b 100644 --- a/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp @@ -17,7 +17,7 @@ #include "load_config_from_data_proxy_node_strategy.h" #include "bundle_mgr_proxy.h" -#include "common/uri_utils.h" +#include "common/utils.h" #include "data_share_profile_config.h" #include "datashare_errno.h" #include "log_print.h" @@ -71,7 +71,7 @@ bool LoadConfigFromDataProxyNodeStrategy::operator()(std::shared_ptr co return true; } context->errCode = E_URI_NOT_EXIST; - ZLOGI("not find DataProperties! %{private}s is private", context->uri.c_str()); + ZLOGI("not find DataProperties! %{public}s is private", URIUtils::Anonymous(context->uri).c_str()); return false; } diff --git a/services/distributeddataservice/service/data_share/strategies/data_share/load_config_from_data_share_bundle_info_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/data_share/load_config_from_data_share_bundle_info_strategy.cpp index e5f3f533725a2372eef256dc41e3cd7911ec26ef..cd5a5aa8a67cc23eb16b5e46ff839e4e0ed5bbe3 100644 --- a/services/distributeddataservice/service/data_share/strategies/data_share/load_config_from_data_share_bundle_info_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/data_share/load_config_from_data_share_bundle_info_strategy.cpp @@ -20,7 +20,7 @@ #include "data_share_profile_config.h" #include "datashare_errno.h" #include "log_print.h" -#include "uri_utils.h" +#include "utils.h" #include "utils/anonymous.h" namespace OHOS::DataShare { diff --git a/services/distributeddataservice/service/data_share/strategies/general/check_is_data_proxy_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/check_is_data_proxy_strategy.cpp index 6842ed8bb71f5fb0ebe57161196e3948276055ba..8d94c9e618ab823cf924aebe78049621bf272aae 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/check_is_data_proxy_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/check_is_data_proxy_strategy.cpp @@ -14,7 +14,7 @@ */ #include "check_is_data_proxy_strategy.h" -#include "uri_utils.h" +#include "utils.h" namespace OHOS::DataShare { bool CheckIsDataProxyStrategy::operator()(std::shared_ptr context) diff --git a/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp index 9a64d37c7eec5db4b2b1e0530b9eff283ea278e1..042ba77968aeb28bfcfb432b5c5e3323eeec004a 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/load_config_common_strategy.cpp @@ -20,7 +20,7 @@ #include "hap_token_info.h" #include "ipc_skeleton.h" #include "log_print.h" -#include "uri_utils.h" +#include "utils.h" namespace OHOS::DataShare { using namespace OHOS::DistributedData; diff --git a/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp index bbd1bd3323787d03e25537273d65d03f8e942a2f..d3966097e0bd75684099791dbc6ea6e46621c73e 100644 --- a/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/general/load_config_data_info_strategy.cpp @@ -22,7 +22,7 @@ #include "metadata/meta_data_manager.h" #include "metadata/store_meta_data.h" #include "rdb_errno.h" -#include "uri_utils.h" +#include "utils.h" namespace OHOS::DataShare { LoadConfigDataInfoStrategy::LoadConfigDataInfoStrategy() diff --git a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp index 1b83078125203c9e8dccb8619ad49b7518f85170..a532d7c52096ee13bbc7993a4fbb645bba4d45ce 100644 --- a/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/get_data_strategy.cpp @@ -20,7 +20,7 @@ #include "data_proxy/load_config_from_data_proxy_node_strategy.h" #include "general/load_config_common_strategy.h" #include "log_print.h" -#include "uri_utils.h" +#include "utils.h" namespace OHOS::DataShare { Data GetDataStrategy::Execute(std::shared_ptr context, int &errorCode) @@ -40,7 +40,7 @@ Data GetDataStrategy::Execute(std::shared_ptr context, int &errorCode) Data data; for (auto &item : result) { if (!CheckPermission(context, item.value.key)) { - ZLOGI("uri: %{private}s not allowed", context->uri.c_str()); + ZLOGI("uri: %{public}s not allowed", URIUtils::Anonymous(context->uri).c_str()); continue; } if (item.GetVersion() > data.version_) { diff --git a/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp index fd277bd4a87c2fe361399275612f9d5654394554..10d4ecba208d6b62d809f9df9edf1775e13b010e 100644 --- a/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/publish_strategy.cpp @@ -22,7 +22,7 @@ #include "general/permission_strategy.h" #include "log_print.h" #include "published_data.h" -#include "uri_utils.h" +#include "utils.h" namespace OHOS::DataShare { int32_t PublishStrategy::Execute(std::shared_ptr context, const PublishedDataItem &item) diff --git a/services/distributeddataservice/service/data_share/strategies/rdb_notify_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/rdb_notify_strategy.cpp index be4d1c54865685d98a27219057d99a332dc3f5c1..552617a4eb6660277452bb293e79eac8b8495ae1 100644 --- a/services/distributeddataservice/service/data_share/strategies/rdb_notify_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/rdb_notify_strategy.cpp @@ -20,7 +20,7 @@ #include "general/load_config_data_info_strategy.h" #include "general/load_config_from_bundle_info_strategy.h" #include "log_print.h" -#include "uri_utils.h" +#include "utils.h" #include "log_debug.h" namespace OHOS::DataShare { diff --git a/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp index 376756243a25dc380eabfa4918d0abc907645082..36b15b452334ab48dec9bdefeea9e6ea6e67ddf7 100644 --- a/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/subscribe_strategy.cpp @@ -21,7 +21,7 @@ #include "general/load_config_data_info_strategy.h" #include "general/permission_strategy.h" #include "log_print.h" -#include "uri_utils.h" +#include "utils.h" namespace OHOS::DataShare { int32_t SubscribeStrategy::Execute(std::shared_ptr context, std::function process) diff --git a/services/distributeddataservice/service/data_share/strategies/template_strategy.cpp b/services/distributeddataservice/service/data_share/strategies/template_strategy.cpp index 7c3439e5cca51451bd23a97f17719df24510d57a..e771c6151bba4880441be78385bfb0e6acb0a4af 100644 --- a/services/distributeddataservice/service/data_share/strategies/template_strategy.cpp +++ b/services/distributeddataservice/service/data_share/strategies/template_strategy.cpp @@ -20,7 +20,7 @@ #include "datashare_errno.h" #include "general/load_config_common_strategy.h" #include "log_print.h" -#include "uri_utils.h" +#include "utils.h" namespace OHOS::DataShare { int32_t TemplateStrategy::Execute(std::shared_ptr context, std::function process) diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/proxy_data_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/proxy_data_subscriber_manager.cpp index 467a8f5e56a8f61c60e6b6ad15e28b75d6559bbd..cea47b58b666c23ec238416fe7896ac8a9e221d2 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/proxy_data_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/proxy_data_subscriber_manager.cpp @@ -21,7 +21,7 @@ #include "ipc_skeleton.h" #include "log_print.h" #include "proxy_data_manager.h" -#include "uri_utils.h" +#include "utils.h" #include "utils/anonymous.h" namespace OHOS::DataShare { diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp index 466fd05451929e23c8d06a5155731add92c5ee25..46ddd990c539cb599829caefac062c9eaddf0225 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp @@ -22,7 +22,7 @@ #include "general/load_config_data_info_strategy.h" #include "log_print.h" #include "published_data.h" -#include "uri_utils.h" +#include "utils.h" #include "utils/anonymous.h" namespace OHOS::DataShare { diff --git a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp index 6c33d72e021d281a1613a8b9b5e3485e6ad598bc..79ccfd8a68bc41298fe0c461b401ba4db984db2b 100644 --- a/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp +++ b/services/distributeddataservice/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp @@ -24,7 +24,7 @@ #include "log_print.h" #include "scheduler_manager.h" #include "template_data.h" -#include "uri_utils.h" +#include "utils.h" #include "utils/anonymous.h" namespace OHOS::DataShare { @@ -116,7 +116,8 @@ int RdbSubscriberManager::Add(const Key &key, const sptr { int result = E_OK; rdbCache_.Compute(key, [&observer, &context, executorPool, this](const auto &key, auto &value) { - ZLOGI("add subscriber, uri %{private}s tokenId 0x%{public}x", key.uri.c_str(), context->callerTokenId); + ZLOGI("add subscriber, uri %{public}s tokenId 0x%{public}x", + URIUtils::Anonymous(key.uri).c_str(), context->callerTokenId); auto callerTokenId = IPCSkeleton::GetCallingTokenID(); auto callerPid = IPCSkeleton::GetCallingPid(); value.emplace_back(observer, context->callerTokenId, callerTokenId, callerPid, context->visitedUserId); diff --git a/services/distributeddataservice/service/test/BUILD.gn b/services/distributeddataservice/service/test/BUILD.gn index da148cd8366a0b381aec63560027bef3bc4ee271..ea605bf5879c2f513a98e87edd77d0fadb4a2d74 100644 --- a/services/distributeddataservice/service/test/BUILD.gn +++ b/services/distributeddataservice/service/test/BUILD.gn @@ -1201,7 +1201,7 @@ ohos_unittest("DataShareServiceImplTest") { "${data_service_path}/service/data_share/common/rdb_delegate.cpp", "${data_service_path}/service/data_share/common/scheduler_manager.cpp", "${data_service_path}/service/data_share/common/seq_strategy.cpp", - "${data_service_path}/service/data_share/common/uri_utils.cpp", + "${data_service_path}/service/data_share/common/utils.cpp", "${data_service_path}/service/data_share/data/published_data.cpp", "${data_service_path}/service/data_share/data/resultset_json_formatter.cpp", "${data_service_path}/service/data_share/data/template_data.cpp", @@ -1245,6 +1245,7 @@ ohos_unittest("DataShareServiceImplTest") { "data_share_types_util_test.cpp", "kv_dalegate_test.cpp", "mock/account_delegate_mock.cpp", + "data_share_uri_utils_test.cpp", ] configs = [ ":module_private_config" ] @@ -1344,7 +1345,7 @@ ohos_unittest("DataShareServiceImplMockTest") { "${data_service_path}/service/data_share/common/rdb_delegate.cpp", "${data_service_path}/service/data_share/common/scheduler_manager.cpp", "${data_service_path}/service/data_share/common/seq_strategy.cpp", - "${data_service_path}/service/data_share/common/uri_utils.cpp", + "${data_service_path}/service/data_share/common/utils.cpp", "${data_service_path}/service/data_share/data/published_data.cpp", "${data_service_path}/service/data_share/data/resultset_json_formatter.cpp", "${data_service_path}/service/data_share/data/template_data.cpp", diff --git a/services/distributeddataservice/service/test/data_share_uri_utils_test.cpp b/services/distributeddataservice/service/test/data_share_uri_utils_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..baccbc53a6dcb98faa05e8387a01bf2fbe995c46 --- /dev/null +++ b/services/distributeddataservice/service/test/data_share_uri_utils_test.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#define LOG_TAG "DatashareURIUtilsTest" +#include "utils.h" + +#include +#include + +namespace OHOS { +namespace DataShare { +using namespace testing::ext; +using namespace OHOS::DataShare; +class DatashareURIUtilsTest : public testing::Test { +public: + static void SetUpTestCase(void){}; + static void TearDownTestCase(void){}; + void SetUp(){}; + void TearDown(){}; +}; + +HWTEST_F(DatashareURIUtilsTest, GeneralAnonymous_001, TestSize.Level0) +{ + EXPECT_EQ(StringUtils::GeneralAnonymous("DataShareTable"), "Data***able"); +} + +HWTEST_F(DatashareURIUtilsTest, GeneralAnonymous_002, TestSize.Level0) +{ + EXPECT_EQ(StringUtils::GeneralAnonymous("1bc"), "******"); +} + +HWTEST_F(DatashareURIUtilsTest, GeneralAnonymous_003, TestSize.Level0) +{ + EXPECT_EQ(StringUtils::GeneralAnonymous("contact"), "cont***"); +} + +HWTEST_F(DatashareURIUtilsTest, GeneralAnonymous_004, TestSize.Level0) +{ + EXPECT_EQ(StringUtils::GeneralAnonymous("name"), "******"); +} + +HWTEST_F(DatashareURIUtilsTest, GeneralAnonymous_005, TestSize.Level0) +{ + EXPECT_EQ(StringUtils::GeneralAnonymous(""), "******"); +} + +HWTEST_F(DatashareURIUtilsTest, GeneralAnonymous_006, TestSize.Level0) +{ + EXPECT_EQ(StringUtils::GeneralAnonymous("store.db"), "stor***"); +} +} // namespace DataShare +} // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/datashareserviceimpl_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/datashareserviceimpl_fuzzer/BUILD.gn index 17ca41e7ea604699c00f5b3795e897e9942db54f..baa4fa6efdd1a20dfbe11b2d162431452b184ad8 100644 --- a/services/distributeddataservice/service/test/fuzztest/datashareserviceimpl_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/datashareserviceimpl_fuzzer/BUILD.gn @@ -64,7 +64,7 @@ ohos_fuzztest("DataShareServiceImplFuzzTest") { "${data_service_path}/service/data_share/common/rdb_delegate.cpp", "${data_service_path}/service/data_share/common/scheduler_manager.cpp", "${data_service_path}/service/data_share/common/seq_strategy.cpp", - "${data_service_path}/service/data_share/common/uri_utils.cpp", + "${data_service_path}/service/data_share/common/utils.cpp", "${data_service_path}/service/data_share/data/published_data.cpp", "${data_service_path}/service/data_share/data/resultset_json_formatter.cpp", "${data_service_path}/service/data_share/data/template_data.cpp", diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn index 8f2dc9fbb4b701f19ee5edffcc26f5b392953b44..5824983758ed23c0ab72fde32937e49601f7e9c2 100644 --- a/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub_fuzzer/BUILD.gn @@ -62,7 +62,7 @@ ohos_fuzztest("DataShareServiceStubFuzzTest") { "${data_service_path}/service/data_share/common/rdb_delegate.cpp", "${data_service_path}/service/data_share/common/scheduler_manager.cpp", "${data_service_path}/service/data_share/common/seq_strategy.cpp", - "${data_service_path}/service/data_share/common/uri_utils.cpp", + "${data_service_path}/service/data_share/common/utils.cpp", "${data_service_path}/service/data_share/data/published_data.cpp", "${data_service_path}/service/data_share/data/resultset_json_formatter.cpp", "${data_service_path}/service/data_share/data/template_data.cpp", diff --git a/services/distributeddataservice/service/test/fuzztest/datasharesubscriber_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/datasharesubscriber_fuzzer/BUILD.gn index 42efc4c2cd66b7e94b1dabd35e920ce2c72739b5..ddfb2cd7bb57b934d81490aeb75a9739e50a4f59 100644 --- a/services/distributeddataservice/service/test/fuzztest/datasharesubscriber_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/datasharesubscriber_fuzzer/BUILD.gn @@ -64,7 +64,7 @@ ohos_fuzztest("DataShareSubscriberFuzzTest") { "${data_service_path}/service/data_share/common/rdb_delegate.cpp", "${data_service_path}/service/data_share/common/scheduler_manager.cpp", "${data_service_path}/service/data_share/common/seq_strategy.cpp", - "${data_service_path}/service/data_share/common/uri_utils.cpp", + "${data_service_path}/service/data_share/common/utils.cpp", "${data_service_path}/service/data_share/data/published_data.cpp", "${data_service_path}/service/data_share/data/resultset_json_formatter.cpp", "${data_service_path}/service/data_share/data/template_data.cpp",