From ad033b5e7b33b887c711aadddc09585ff4c119f2 Mon Sep 17 00:00:00 2001 From: daiyunlong Date: Sat, 26 Jul 2025 21:22:47 +0800 Subject: [PATCH] =?UTF-8?q?DTFuzz=5FAuthConfirm=E9=97=AE=E9=A2=98=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=8F=8ASafetyDump()=E5=87=BD=E6=95=B0=E6=95=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: daiyunlong --- common/include/dm_anonymous.h | 1 - common/src/dm_anonymous.cpp | 7 +- .../native_cpp/src/device_manager_impl.cpp | 4 +- .../kits/js/src/native_devicemanager_js.cpp | 4 +- interfaces/kits/js4.0/src/dm_native_util.cpp | 4 +- json/include/json_object.h | 2 - json/src/json_object_cjson.cpp | 12 +- json/src/json_object_nlohmannjson.cpp | 19 +- .../ability/standard/dm_dialog_manager.cpp | 2 +- .../authentication/auth_message_processor.cpp | 12 +- .../authentication/auth_ui_state_manager.cpp | 2 +- .../src/authentication/dm_auth_manager.cpp | 22 +- .../src/authentication_v2/auth_manager.cpp | 5 +- .../auth_stages/auth_negotiate.cpp | 4 +- .../authentication_v2/dm_freeze_process.cpp | 4 +- .../src/credential/dm_credential_manager.cpp | 4 +- .../hichain/hichain_auth_connector.cpp | 14 +- .../dependency/hichain/hichain_connector.cpp | 38 +- .../hichain/mine_hichain_connector.cpp | 4 +- .../service/src/device_manager_service.cpp | 2 +- .../service/src/hichain/hichain_listener.cpp | 4 +- services/service/src/pinholder/pin_holder.cpp | 28 +- .../service/src/softbus/softbus_listener.cpp | 6 +- .../hichain_connector_fuzzer.cpp | 6 +- .../UTTest_discovery_filter.cpp | 24 +- .../UTTest_dm_auth_manager_first.cpp | 12 +- .../UTTest_dm_auth_manager_second.cpp | 22 +- .../UTTest_dm_auth_manager_third.cpp | 16 +- .../UTTest_dm_credential_manager.cpp | 16 +- .../UTTest_hichain_auth_connector.cpp | 16 +- .../UTTest_hichain_connector.cpp | 10 +- .../UTTest_mine_hichain_connector.cpp | 8 +- test/commonunittest/UTTest_pin_auth.cpp | 6 +- .../auth_confirm_fuzzer.cpp | 443 ++++++++++-------- .../UTTest_mine_softbus_listener.cpp | 10 +- .../UTTest_softbus_session.cpp | 2 +- .../UTTest_auth_message_processor.cpp | 18 +- test/unittest/UTTest_crypto_mgr.cpp | 6 +- test/unittest/UTTest_dm_pin_holder.cpp | 54 +-- test/unittest/UTTest_dp_inited_callback.cpp | 12 +- test/unittest/UTTest_hichain_listener.cpp | 2 +- .../unittest/UTTest_ipc_cmd_parser_client.cpp | 8 +- .../UTTest_ipc_cmd_parser_service.cpp | 4 +- test/unittest/UTTest_json_object.cpp | 11 - test/unittest/UTTest_kv_adapter_manager.cpp | 2 +- utils/src/kvadapter/dm_kv_info.cpp | 2 +- utils/src/kvadapter/kv_adapter.cpp | 2 +- 47 files changed, 475 insertions(+), 441 deletions(-) diff --git a/common/include/dm_anonymous.h b/common/include/dm_anonymous.h index f6ba0fdd8..df4ff3408 100644 --- a/common/include/dm_anonymous.h +++ b/common/include/dm_anonymous.h @@ -103,7 +103,6 @@ bool IsIdLengthValid(const std::string &inputID); bool IsMessageLengthValid(const std::string &inputMessage); bool IsValueExist(const std::multimap unorderedmap, const std::string &udid, int32_t userId); bool IsDmCommonNotifyEventValid(DmCommonNotifyEvent dmCommonNotifyEvent); -DM_EXPORT std::string SafetyDump(const JsonItemObject &jsonObj); std::string GetSubStr(const std::string &rawStr, const std::string &separator, int32_t index); bool IsJsonValIntegerString(const JsonItemObject &jsonObj, const std::string &key); std::string GetAnonyJsonString(const std::string &value); diff --git a/common/src/dm_anonymous.cpp b/common/src/dm_anonymous.cpp index 985e06677..43a0ecfed 100644 --- a/common/src/dm_anonymous.cpp +++ b/common/src/dm_anonymous.cpp @@ -198,7 +198,7 @@ std::string ConvertMapToJsonString(const std::map &par for (const auto &it : paramMap) { jsonObj[it.first] = it.second; } - jsonStr = SafetyDump(jsonObj); + jsonStr = jsonObj.Dump(); } return jsonStr; } @@ -398,11 +398,6 @@ bool IsDmCommonNotifyEventValid(DmCommonNotifyEvent dmCommonNotifyEvent) return false; } -DM_EXPORT std::string SafetyDump(const JsonItemObject &jsonObj) -{ - return jsonObj.DumpIgnoreError(); -} - std::string GetSubStr(const std::string &rawStr, const std::string &separator, int32_t index) { if (rawStr.empty() || separator.empty() || index < 0) { diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index eb9090a9b..75fd0819c 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -698,7 +698,7 @@ int32_t DeviceManagerImpl::AuthenticateDevice(const std::string &pkgName, int32_ std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); - req->SetExtra(SafetyDump(extraJson)); + req->SetExtra(extraJson.Dump()); req->SetAuthType(authType); req->SetDeviceInfo(deviceInfo); int32_t ret = ipcClientProxy_->SendRequest(AUTHENTICATE_DEVICE, req, rsp); @@ -1546,7 +1546,7 @@ int32_t DeviceManagerImpl::BindDevice(const std::string &pkgName, int32_t bindTy std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); - req->SetBindParam(SafetyDump(paramJson)); + req->SetBindParam(paramJson.Dump()); req->SetBindType(bindType); req->SetDeviceId(deviceId); int32_t ret = ipcClientProxy_->SendRequest(BIND_DEVICE, req, rsp); diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index bfdd9d669..820994336 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -1220,7 +1220,7 @@ void DeviceManagerNapi::JsToDmExtra(const napi_env &env, const napi_value &objec jsonObj[CUSTOM_DESCRIPTION] = customDescriptionStr; jsonObj[BIND_LEVEL] = bindLevel; JsToJsonObject(env, object, "extraInfo", jsonObj); - extra = SafetyDump(jsonObj); + extra = jsonObj.Dump(); LOGI("appOperationLen %{public}zu, customDescriptionLen %{public}zu", appOperationStr.size(), customDescriptionStr.size()); } @@ -1291,7 +1291,7 @@ void DeviceManagerNapi::JsToDmAuthInfo(const napi_env &env, const napi_value &ob jsonObj[AUTH_TYPE] = authType; jsonObj[PIN_TOKEN] = token; JsToJsonObject(env, object, "extraInfo", jsonObj); - extra = SafetyDump(jsonObj); + extra = jsonObj.Dump(); } void DeviceManagerNapi::JsToDmDiscoveryExtra(const napi_env &env, const napi_value &object, std::string &extra) diff --git a/interfaces/kits/js4.0/src/dm_native_util.cpp b/interfaces/kits/js4.0/src/dm_native_util.cpp index e551b5280..60a8e66d8 100644 --- a/interfaces/kits/js4.0/src/dm_native_util.cpp +++ b/interfaces/kits/js4.0/src/dm_native_util.cpp @@ -368,7 +368,7 @@ void JsToBindParam(const napi_env &env, const napi_value &object, std::string &b jsonObj[PARAM_KEY_WIFI_IP] = std::string(wifiIP); jsonObj[PARAM_KEY_WIFI_PORT] = wifiPort; jsonObj[BIND_LEVEL] = bindLevel; - bindParam = SafetyDump(jsonObj); + bindParam = jsonObj.Dump(); } bool IsSystemApp() @@ -433,7 +433,7 @@ void JsToDmDiscoveryExtra(const napi_env &env, const napi_value &object, std::st if (deviceType != DM_NAPI_DISCOVER_EXTRA_INIT_ONE) { jsonObj["deviceType"] = deviceType; } - extra = SafetyDump(jsonObj); + extra = jsonObj.Dump(); LOGI("JsToDmDiscoveryExtra, extra :%{public}s", extra.c_str()); } diff --git a/json/include/json_object.h b/json/include/json_object.h index b91a00800..cb86a243b 100644 --- a/json/include/json_object.h +++ b/json/include/json_object.h @@ -50,7 +50,6 @@ public: const JsonItemObject operator[](const std::string &key) const; std::string DumpFormated() const; std::string Dump() const; - std::string DumpIgnoreError() const; bool Contains(const std::string &key) const; bool IsDiscarded() const; bool PushBack(const std::string &strValue); @@ -124,7 +123,6 @@ public: protected: JsonItemObject(); void Delete(); - std::string Dump(bool formatFlag) const; std::string Dump(bool formatFlag, bool isIgnoreError) const; void AddItemToArray(JsonItemObject &item); bool InitItem(JsonItemObject &item); diff --git a/json/src/json_object_cjson.cpp b/json/src/json_object_cjson.cpp index 33fc92509..32fed83eb 100644 --- a/json/src/json_object_cjson.cpp +++ b/json/src/json_object_cjson.cpp @@ -343,15 +343,10 @@ JsonItemObject& JsonItemObject::operator=(const JsonItemObject &object) std::string JsonItemObject::DumpFormated() const { - return Dump(true); + return Dump(true, true); } std::string JsonItemObject::Dump() const -{ - return Dump(false); -} - -std::string JsonItemObject::DumpIgnoreError() const { return Dump(false, true); } @@ -359,11 +354,6 @@ std::string JsonItemObject::DumpIgnoreError() const std::string JsonItemObject::Dump(bool formatFlag, bool isIgnoreError) const { (void) isIgnoreError; - return Dump(formatFlag); -} - -std::string JsonItemObject::Dump(bool formatFlag) const -{ if (item_ == nullptr) { LOGE("item_ is nullptr"); return ""; diff --git a/json/src/json_object_nlohmannjson.cpp b/json/src/json_object_nlohmannjson.cpp index 47975615d..6def1111d 100644 --- a/json/src/json_object_nlohmannjson.cpp +++ b/json/src/json_object_nlohmannjson.cpp @@ -278,15 +278,10 @@ JsonItemObject& JsonItemObject::operator=(const JsonItemObject &object) std::string JsonItemObject::DumpFormated() const { - return Dump(true); + return Dump(true, true); } std::string JsonItemObject::Dump() const -{ - return Dump(false); -} - -std::string JsonItemObject::DumpIgnoreError() const { return Dump(false, true); } @@ -311,18 +306,6 @@ std::string JsonItemObject::Dump(bool formatFlag, bool isIgnoreError) const return GetJsonPointer(item_)->dump(indent, indent_char, ensure_ascii, error_handler); } -std::string JsonItemObject::Dump(bool formatFlag) const -{ - if (item_ == nullptr) { - LOGE("item_ is nullptr"); - return ""; - } - if (formatFlag) { - return GetJsonPointer(item_)->dump(1, '\t', false, nlohmann::detail::error_handler_t::ignore); - } - return GetJsonPointer(item_)->dump(); -} - JsonItemObject JsonItemObject::operator[](const std::string &key) { JsonItemObject itemObject = At(key); diff --git a/services/implementation/src/ability/standard/dm_dialog_manager.cpp b/services/implementation/src/ability/standard/dm_dialog_manager.cpp index 5b93c3a29..4531d332e 100644 --- a/services/implementation/src/ability/standard/dm_dialog_manager.cpp +++ b/services/implementation/src/ability/standard/dm_dialog_manager.cpp @@ -215,7 +215,7 @@ void DmDialogManager::DialogAbilityConnection::OnAbilityConnectDone( param[TAG_TARGET_DEVICE_NAME] = DmDialogManager::GetTargetDeviceName(); param[TAG_HOST_PKGLABEL] = DmDialogManager::GetHostPkgLabel(); param["disableUpGesture"] = 1; - std::string paramStr = SafetyDump(param); + std::string paramStr = param.Dump(); data.WriteString16(Str8ToStr16(paramStr)); LOGI("show dm dialog is begin"); const uint32_t cmdCode = 1; diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index ad8495853..5d4458025 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -136,7 +136,7 @@ std::vector AuthMessageProcessor::CreateAuthRequestMessage() jsonObj[TAG_SLICE_NUM] = thumbnailSlice + 1; jsonObj[TAG_THUMBNAIL_SIZE] = thumbnailSize; GetJsonObj(jsonObj); - jsonStrVec.push_back(SafetyDump(jsonObj)); + jsonStrVec.push_back(jsonObj.Dump()); for (int32_t idx = 0; idx < thumbnailSlice; idx++) { JsonObject jsonThumbnailObj; jsonThumbnailObj[TAG_VER] = DM_ITF_VER; @@ -148,7 +148,7 @@ std::vector AuthMessageProcessor::CreateAuthRequestMessage() int32_t leftLen = thumbnailSize - idx * MSG_MAX_SIZE; int32_t sliceLen = (leftLen > MSG_MAX_SIZE) ? MSG_MAX_SIZE : leftLen; jsonObj[TAG_APP_THUMBNAIL] = authRequestContext_->appThumbnail.substr(idx * MSG_MAX_SIZE, sliceLen); - jsonStrVec.push_back(SafetyDump(jsonThumbnailObj)); + jsonStrVec.push_back(jsonThumbnailObj.Dump()); } return jsonStrVec; } @@ -189,7 +189,7 @@ std::string AuthMessageProcessor::CreateSimpleMessage(int32_t msgType) default: break; } - return SafetyDump(jsonObj); + return jsonObj.Dump(); } void AuthMessageProcessor::CreatePublicKeyMessageExt(JsonObject &json) @@ -211,7 +211,7 @@ void AuthMessageProcessor::CreatePublicKeyMessageExt(JsonObject &json) jsonTemp[TAG_SESSIONKEY_ID] = authResponseContext_->localSessionKeyId; } jsonTemp[TAG_PUBLICKEY] = authResponseContext_->publicKey; - std::string strTemp = SafetyDump(jsonTemp); + std::string strTemp = jsonTemp.Dump(); std::string encryptStr = ""; CHECK_NULL_VOID(cryptoMgr_); if (cryptoMgr_->EncryptMessage(strTemp, encryptStr) != DM_OK) { @@ -714,7 +714,7 @@ std::string AuthMessageProcessor::CreateDeviceAuthMessage(int32_t msgType, const std::string authDataStr = std::string(reinterpret_cast(data), dataLen); jsonObj[TAG_DATA] = authDataStr; jsonObj[TAG_DATA_LEN] = dataLen; - return SafetyDump(jsonObj); + return jsonObj.Dump(); } void AuthMessageProcessor::CreateReqReCheckMessage(JsonObject &jsonObj) @@ -727,7 +727,7 @@ void AuthMessageProcessor::CreateReqReCheckMessage(JsonObject &jsonObj) jsonTemp[TAG_BIND_LEVEL] = authResponseContext_->bindLevel; jsonTemp[TAG_LOCAL_ACCOUNTID] = authResponseContext_->localAccountId; jsonTemp[TAG_TOKENID] = authResponseContext_->tokenId; - std::string strTemp = SafetyDump(jsonTemp); + std::string strTemp = jsonTemp.Dump(); std::string encryptStr = ""; CHECK_NULL_VOID(cryptoMgr_); if (cryptoMgr_->EncryptMessage(strTemp, encryptStr) != DM_OK) { diff --git a/services/implementation/src/authentication/auth_ui_state_manager.cpp b/services/implementation/src/authentication/auth_ui_state_manager.cpp index ba7328400..df081c5a3 100644 --- a/services/implementation/src/authentication/auth_ui_state_manager.cpp +++ b/services/implementation/src/authentication/auth_ui_state_manager.cpp @@ -62,7 +62,7 @@ void AuthUiStateManager::UpdateUiState(const DmUiStateMsg msg) } JsonObject jsonObj; jsonObj[UI_STATE_MSG] = msg; - std::string paramJson = SafetyDump(jsonObj); + std::string paramJson = jsonObj.Dump(); std::lock_guard lock(pkgSetMutex_); for (auto item : pkgSet_) { listener_->OnUiCall(item, paramJson); diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 92c7d607d..88f61775e 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -753,7 +753,7 @@ void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId jsonObj[PIN_TOKEN] = authResponseContext_->token; jsonObj[QR_CODE_KEY] = GenerateGroupName(); jsonObj[NFC_CODE_KEY] = GenerateGroupName(); - authResponseContext_->authToken = SafetyDump(jsonObj); + authResponseContext_->authToken = jsonObj.Dump(); LOGI("DmAuthManager::OnGroupCreated start group id %{public}s", GetAnonyString(groupId).c_str()); authResponseContext_->groupId = groupId; authResponseContext_->code = pinCode; @@ -1341,7 +1341,7 @@ int32_t DmAuthManager::AddMember(const std::string &pinCode) jsonObject[PIN_CODE_KEY] = pinCode; jsonObject[TAG_REQUEST_ID] = authResponseContext_->requestId; jsonObject[TAG_DEVICE_ID] = authResponseContext_->deviceId; - std::string connectInfo = SafetyDump(jsonObject); + std::string connectInfo = jsonObject.Dump(); if (timer_ != nullptr) { timer_->StartTimer(std::string(ADD_TIMEOUT_TASK), GetTaskTimeout(ADD_TIMEOUT_TASK, ADD_TIMEOUT), [this] (std::string name) { @@ -1751,7 +1751,7 @@ void DmAuthManager::ShowConfigDialog() jsonObj[TAG_LOCAL_DEVICE_TYPE] = authResponseContext_->deviceTypeId; jsonObj[TAG_REQUESTER] = authResponseContext_->deviceName; jsonObj[TAG_HOST_PKGLABEL] = authResponseContext_->hostPkgLabel; - const std::string params = SafetyDump(jsonObj); + const std::string params = jsonObj.Dump(); char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); std::string localUdid = static_cast(localDeviceId); @@ -1965,7 +1965,7 @@ bool DmAuthManager::IsIdenticalAccount() { JsonObject jsonObj; jsonObj[FIELD_GROUP_TYPE] = GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP; - std::string queryParams = SafetyDump(jsonObj); + std::string queryParams = jsonObj.Dump(); int32_t osAccountUserId = MultipleUserConnector::GetCurrentAccountUserID(); if (osAccountUserId < 0) { @@ -2006,7 +2006,7 @@ std::string DmAuthManager::GetAccountGroupIdHash() { JsonObject jsonObj; jsonObj[FIELD_GROUP_TYPE] = GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP; - std::string queryParams = SafetyDump(jsonObj); + std::string queryParams = jsonObj.Dump(); int32_t osAccountUserId = MultipleUserConnector::GetCurrentAccountUserID(); if (osAccountUserId < 0) { @@ -2021,7 +2021,7 @@ std::string DmAuthManager::GetAccountGroupIdHash() for (auto &groupInfo : groupList) { jsonAccountObj.PushBack(Crypto::GetGroupIdHash(groupInfo.groupId)); } - return SafetyDump(jsonAccountObj); + return jsonAccountObj.Dump(); } int32_t DmAuthManager::ImportAuthCode(const std::string &pkgName, const std::string &authCode) @@ -2214,7 +2214,7 @@ std::string DmAuthManager::GenerateBindResultContent() jsonObj[TAG_DEVICE_ID] = deviceIdHash; } jsonObj[TAG_CONFIRM_OPERATION] = authResponseContext_->confirmOperation; - std::string content = SafetyDump(jsonObj); + std::string content = jsonObj.Dump(); return content; } @@ -2588,7 +2588,7 @@ char *DmAuthManager::AuthDeviceRequest(int64_t requestId, int operationCode, con std::string deviceId = ""; GetRemoteDeviceId(deviceId); jsonObj[FIELD_PEER_CONN_DEVICE_ID] = deviceId; - std::string jsonStr = SafetyDump(jsonObj); + std::string jsonStr = jsonObj.Dump(); char *buffer = strdup(jsonStr.c_str()); return buffer; } @@ -2720,7 +2720,7 @@ void DmAuthManager::ProcRespNegotiate(const int32_t &sessionId) } } jsonObject[TAG_CRYPTO_SUPPORT] = false; - message = SafetyDump(jsonObject); + message = jsonObject.Dump(); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); } @@ -2731,7 +2731,7 @@ void DmAuthManager::ProcIncompatible(const int32_t &sessionId) respNegotiateMsg[TAG_REPLY] = ERR_DM_VERSION_INCOMPATIBLE; respNegotiateMsg[TAG_VER] = DM_ITF_VER; respNegotiateMsg[TAG_MSG_TYPE] = MSG_TYPE_RESP_NEGOTIATE; - std::string message = SafetyDump(respNegotiateMsg); + std::string message = respNegotiateMsg.Dump(); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); } @@ -2879,7 +2879,7 @@ void DmAuthManager::HandleSessionHeartbeat(std::string name) LOGI("DmAuthManager::HandleSessionHeartbeat name %{public}s", name.c_str()); JsonObject jsonObj; jsonObj[TAG_SESSION_HEARTBEAT] = TAG_SESSION_HEARTBEAT; - std::string message = SafetyDump(jsonObj); + std::string message = jsonObj.Dump(); softbusConnector_->GetSoftbusSession()->SendHeartbeatData(authResponseContext_->sessionId, message); if (authRequestState_ != nullptr) { diff --git a/services/implementation/src/authentication_v2/auth_manager.cpp b/services/implementation/src/authentication_v2/auth_manager.cpp index 4a33f36c8..30e80b08f 100644 --- a/services/implementation/src/authentication_v2/auth_manager.cpp +++ b/services/implementation/src/authentication_v2/auth_manager.cpp @@ -154,7 +154,10 @@ AuthManager::~AuthManager() if (context_ != nullptr) { context_->successFinished = true; context_->authStateMachine->Stop(); // Stop statemMachine thread - context_->timer->DeleteAll(); + + if (context_->timer != nullptr) { + context_->timer->DeleteAll(); + } LOGI("AuthManager context variables destroy successful."); } { diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_negotiate.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_negotiate.cpp index 0faacf702..a5c05303a 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_negotiate.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_negotiate.cpp @@ -72,7 +72,7 @@ std::string AuthSrcNegotiateStateMachine::GetAccountGroupIdHash(std::shared_ptr< { JsonObject jsonObj; jsonObj[FIELD_GROUP_TYPE] = GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP; - std::string queryParams = SafetyDump(jsonObj); + std::string queryParams = jsonObj.Dump(); int32_t osAccountUserId = MultipleUserConnector::GetCurrentAccountUserID(); if (osAccountUserId < 0) { @@ -87,7 +87,7 @@ std::string AuthSrcNegotiateStateMachine::GetAccountGroupIdHash(std::shared_ptr< for (auto &groupInfo : groupList) { jsonAccountObj.PushBack(Crypto::GetGroupIdHash(groupInfo.groupId)); } - return SafetyDump(jsonAccountObj); + return jsonAccountObj.Dump(); } int32_t AuthSrcNegotiateStateMachine::Action(std::shared_ptr context) diff --git a/services/implementation/src/authentication_v2/dm_freeze_process.cpp b/services/implementation/src/authentication_v2/dm_freeze_process.cpp index 3acd87cb6..9e7d4a1e3 100644 --- a/services/implementation/src/authentication_v2/dm_freeze_process.cpp +++ b/services/implementation/src/authentication_v2/dm_freeze_process.cpp @@ -230,7 +230,7 @@ void FreezeProcess::ConvertBindFailedEventsToJson(const BindFailedEvents &value, JsonObject jsonObj; jsonObj[FAILED_TIMES_STAMPS_KEY] = value.failedTimeStamps; jsonObj[FREEZE_TIMES_STAMPS_KEY] = value.freezeTimeStamps; - result = SafetyDump(jsonObj); + result = jsonObj.Dump(); } void FreezeProcess::ConvertDeviceFreezeStateToJson(const DeviceFreezeState &value, std::string &result) @@ -238,7 +238,7 @@ void FreezeProcess::ConvertDeviceFreezeStateToJson(const DeviceFreezeState &valu JsonObject jsonObj; jsonObj[START_FREEZE_TIME_KEY] = value.startFreezeTimeStamp; jsonObj[STOP_FREEZE_TIME_KEY] = value.stopFreezeTimeStamp; - result = SafetyDump(jsonObj); + result = jsonObj.Dump(); } int32_t FreezeProcess::DeleteFreezeRecord() diff --git a/services/implementation/src/credential/dm_credential_manager.cpp b/services/implementation/src/credential/dm_credential_manager.cpp index 6df6c33ea..a41f67390 100644 --- a/services/implementation/src/credential/dm_credential_manager.cpp +++ b/services/implementation/src/credential/dm_credential_manager.cpp @@ -115,7 +115,7 @@ int32_t DmCredentialManager::RequestCredential(const std::string &reqJsonStr, st jsonObj[FIELD_CREDENTIAL_VERSION] = credentialVersion; jsonObj[FIELD_USER_ID] = userId; jsonObj[FIELD_DEVICE_ID] = localDeviceId; - std::string tmpStr = SafetyDump(jsonObj); + std::string tmpStr = jsonObj.Dump(); return hiChainConnector_->getRegisterInfo(tmpStr.c_str(), returnJsonStr); } @@ -366,7 +366,7 @@ void FromJson(const JsonItemObject &jsonObject, CredentialDataInfo &credentialDa } if (IsString(jsonObject, FIELD_PKINFO)) { JsonItemObject jsonPkInfo = jsonObject[FIELD_PKINFO]; - credentialDataInfo.pkInfo = SafetyDump(jsonPkInfo); + credentialDataInfo.pkInfo = jsonPkInfo.Dump(); } } else if (credentialDataInfo.credentialType == SYMMETRY_CREDENTIAL_TYPE) { if (IsString(jsonObject, FIELD_AUTH_CODE)) { diff --git a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp index b1f2fd031..a5bb0d325 100644 --- a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp @@ -121,7 +121,7 @@ int32_t HiChainAuthConnector::AuthDevice(const std::string &pinCode, int32_t osA authParamJson["osAccountId"] = osAccountId; authParamJson["pinCode"] = pinCode; authParamJson["acquireType"] = AcquireType::P2P_BIND; - std::string authParam = SafetyDump(authParamJson); + std::string authParam = authParamJson.Dump(); LOGI("StartAuthDevice authParam %{public}s ,requestId %{public}" PRId64, GetAnonyString(authParam).c_str(), requestId); int32_t ret = StartAuthDevice(requestId, authParam.c_str(), &deviceAuthCallback_); @@ -138,7 +138,7 @@ int32_t HiChainAuthConnector::ProcessAuthData(int64_t requestId, std::string aut JsonObject jsonAuthParam; jsonAuthParam["osAccountId"] = osAccountId; jsonAuthParam["data"] = authData; - int32_t ret = ProcessAuthDevice(requestId, SafetyDump(jsonAuthParam).c_str(), &deviceAuthCallback_); + int32_t ret = ProcessAuthDevice(requestId, jsonAuthParam.Dump().c_str(), &deviceAuthCallback_); if (ret != HC_SUCCESS) { LOGE("Hichain processData failed ret %{public}d.", ret); return ERR_DM_FAILED; @@ -353,7 +353,7 @@ int32_t HiChainAuthConnector::GenerateCredential(std::string &localUdid, int32_t jsonObj["deviceId"] = localUdid; jsonObj["acquireType"] = AcquireType::P2P_BIND; jsonObj["flag"] = 1; - std::string requestParam = SafetyDump(jsonObj); + std::string requestParam = jsonObj.Dump(); char *returnData = nullptr; if (ProcessCredential(CRED_OP_CREATE, requestParam.c_str(), &returnData) != HC_SUCCESS) { LOGE("Hichain generate credential failed."); @@ -449,7 +449,7 @@ bool HiChainAuthConnector::QueryCredential(std::string &localUdid, int32_t osAcc jsonObj["deviceId"] = localUdid; jsonObj["acquireType"] = AcquireType::P2P_BIND; jsonObj["flag"] = 1; - std::string requestParam = SafetyDump(jsonObj); + std::string requestParam = jsonObj.Dump(); char *returnData = nullptr; if (ProcessCredential(CRED_OP_QUERY, requestParam.c_str(), &returnData) != HC_SUCCESS) { LOGE("Hichain query credential failed."); @@ -478,7 +478,7 @@ int32_t HiChainAuthConnector::GetCredential(std::string &localUdid, int32_t osAc jsonObj["deviceId"] = localUdid; jsonObj["acquireType"] = AcquireType::P2P_BIND; jsonObj["flag"] = 1; - std::string requestParam = SafetyDump(jsonObj); + std::string requestParam = jsonObj.Dump(); char *returnData = nullptr; if (ProcessCredential(CRED_OP_QUERY, requestParam.c_str(), &returnData) != HC_SUCCESS) { LOGE("Hichain query credential failed."); @@ -511,7 +511,7 @@ int32_t HiChainAuthConnector::ImportCredential(int32_t osAccountId, int32_t peer jsonObj["deviceId"] = deviceId; jsonObj["acquireType"] = AcquireType::P2P_BIND; jsonObj["publicKey"] = publicKey; - std::string requestParam = SafetyDump(jsonObj); + std::string requestParam = jsonObj.Dump(); char *returnData = nullptr; if (ProcessCredential(CRED_OP_IMPORT, requestParam.c_str(), &returnData) != HC_SUCCESS) { LOGE("Hichain query credential failed."); @@ -531,7 +531,7 @@ int32_t HiChainAuthConnector::DeleteCredential(const std::string &deviceId, int3 jsonObj["acquireType"] = AcquireType::P2P_BIND; jsonObj["osAccountId"] = userId; jsonObj["peerOsAccountId"] = peerUserId; - std::string requestParam = SafetyDump(jsonObj); + std::string requestParam = jsonObj.Dump(); char *returnData = nullptr; if (ProcessCredential(CRED_OP_DELETE, requestParam.c_str(), &returnData) != HC_SUCCESS) { LOGE("Hichain query credential failed."); diff --git a/services/implementation/src/dependency/hichain/hichain_connector.cpp b/services/implementation/src/dependency/hichain/hichain_connector.cpp index 5cb929ffe..6b3fda504 100644 --- a/services/implementation/src/dependency/hichain/hichain_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_connector.cpp @@ -164,7 +164,7 @@ int32_t HiChainConnector::CreateGroup(int64_t requestId, const std::string &grou LOGE("get current process account user id failed"); return ERR_DM_FAILED; } - int32_t ret = deviceGroupManager_->createGroup(userId, requestId, DM_PKG_NAME, SafetyDump(jsonObj).c_str()); + int32_t ret = deviceGroupManager_->createGroup(userId, requestId, DM_PKG_NAME, jsonObj.Dump().c_str()); struct RadarInfo info = { .funcName = "CreateGroup", .toCallPkg = HICHAINNAME, @@ -188,7 +188,7 @@ bool HiChainConnector::IsGroupCreated(std::string groupName, GroupInfo &groupInf { JsonObject jsonObj; jsonObj[FIELD_GROUP_NAME] = groupName.c_str(); - std::string queryParams = SafetyDump(jsonObj); + std::string queryParams = jsonObj.Dump(); std::vector groupList; if (GetGroupInfo(queryParams, groupList)) { groupInfo = groupList[0]; @@ -201,7 +201,7 @@ bool HiChainConnector::IsRedundanceGroup(const std::string &userId, int32_t auth { JsonObject jsonObj; jsonObj[FIELD_GROUP_TYPE] = authType; - std::string queryParams = SafetyDump(jsonObj); + std::string queryParams = jsonObj.Dump(); int32_t osAccountUserId = MultipleUserConnector::GetCurrentAccountUserID(); if (osAccountUserId < 0) { @@ -358,7 +358,7 @@ int32_t HiChainConnector::AddMember(const std::string &deviceId, const std::stri jsonObj[FIELD_DEVICE_ID] = localDeviceId; jsonObj[FIELD_GROUP_NAME] = jsonObject[TAG_GROUP_NAME].Get(); jsonObj[FIELD_CONNECT_PARAMS] = connectInfomation.c_str(); - std::string tmpStr = SafetyDump(jsonObj); + std::string tmpStr = jsonObj.Dump(); int64_t requestId = jsonObject[TAG_REQUEST_ID].Get(); int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); if (userId < 0) { @@ -501,7 +501,7 @@ char *HiChainConnector::onRequest(int64_t requestId, int operationCode, const ch GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); jsonObj[FIELD_DEVICE_ID] = localDeviceId; - std::string jsonStr = SafetyDump(jsonObj); + std::string jsonStr = jsonObj.Dump(); char *buffer = strdup(jsonStr.c_str()); return buffer; } @@ -526,7 +526,7 @@ std::string HiChainConnector::GetConnectPara(std::string deviceId, std::string r } jsonObject[DEVICE_ID] = reqDeviceId; - return SafetyDump(jsonObject); + return jsonObject.Dump(); } int32_t HiChainConnector::GetRelatedGroups(const std::string &deviceId, std::vector &groupList) @@ -627,7 +627,7 @@ int32_t HiChainConnector::DelMemberFromGroup(const std::string &groupId, const s JsonObject jsonObj; jsonObj[FIELD_GROUP_ID] = groupId; jsonObj[FIELD_DELETE_ID] = deviceId; - std::string deleteParams = SafetyDump(jsonObj); + std::string deleteParams = jsonObj.Dump(); int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); if (userId < 0) { LOGE("get current process account user id failed"); @@ -646,7 +646,7 @@ int32_t HiChainConnector::DeleteGroup(std::string &groupId) int64_t requestId = GenRequestId(); JsonObject jsonObj; jsonObj[FIELD_GROUP_ID] = groupId; - std::string disbandParams = SafetyDump(jsonObj); + std::string disbandParams = jsonObj.Dump(); int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); if (userId < 0) { LOGE("get current process account user id failed"); @@ -666,7 +666,7 @@ int32_t HiChainConnector::DeleteGroupExt(std::string &groupId) int64_t requestId = GenRequestId(); JsonObject jsonObj; jsonObj[FIELD_GROUP_ID] = groupId; - std::string disbandParams = SafetyDump(jsonObj); + std::string disbandParams = jsonObj.Dump(); int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); if (userId < 0) { LOGE("get current process account user id failed"); @@ -686,7 +686,7 @@ int32_t HiChainConnector::DeleteGroupExt(int32_t userId, std::string &groupId) int64_t requestId = GenRequestId(); JsonObject jsonObj; jsonObj[FIELD_GROUP_ID] = groupId; - std::string disbandParams = SafetyDump(jsonObj); + std::string disbandParams = jsonObj.Dump(); int32_t ret = deviceGroupManager_->deleteGroup(userId, requestId, DM_PKG_NAME_EXT, disbandParams.c_str()); if (ret != 0) { LOGE("[HICHAIN]fail to delete group with ret:%{public}d.", ret); @@ -700,7 +700,7 @@ int32_t HiChainConnector::DeleteGroup(int64_t requestId_, const std::string &use networkStyle_ = CREDENTIAL_NETWORK; JsonObject jsonObj; jsonObj[FIELD_GROUP_TYPE] = authType; - std::string queryParams = SafetyDump(jsonObj); + std::string queryParams = jsonObj.Dump(); std::vector groupList; if (!GetGroupInfo(queryParams, groupList)) { LOGE("failed to get device join groups"); @@ -721,7 +721,7 @@ int32_t HiChainConnector::DeleteGroup(int64_t requestId_, const std::string &use return ERR_DM_FAILED; } jsonObj[FIELD_GROUP_ID] = groupId; - std::string disbandParams = SafetyDump(jsonObj); + std::string disbandParams = jsonObj.Dump(); g_deleteGroupFlag = false; int32_t osAccountUserId = MultipleUserConnector::GetCurrentAccountUserID(); if (osAccountUserId < 0) { @@ -831,7 +831,7 @@ int32_t HiChainConnector::CreateGroup(int64_t requestId, int32_t authType, const return ERR_DM_FAILED; } int32_t ret = deviceGroupManager_->createGroup(osAccountUserId, requestId, DM_PKG_NAME, - SafetyDump(jsonObj).c_str()); + jsonObj.Dump().c_str()); if (ret != DM_OK) { LOGE("[HICHAIN]fail to create group with ret:%{public}d, requestId:%{public}" PRId64, ret, requestId); return ERR_DM_CREATE_GROUP_FAILED; @@ -882,7 +882,7 @@ int32_t HiChainConnector::GetGroupId(const std::string &userId, const int32_t gr { JsonObject jsonObjGroup; jsonObjGroup[FIELD_GROUP_TYPE] = groupType; - std::string queryParams = SafetyDump(jsonObjGroup); + std::string queryParams = jsonObjGroup.Dump(); std::vector groupList; if (!GetGroupInfo(queryParams.c_str(), groupList)) { @@ -918,7 +918,7 @@ int32_t HiChainConnector::ParseRemoteCredential(const int32_t groupType, const s JsonObject jsonArray(JsonCreateType::JSON_CREATE_TYPE_ARRAY); jsonArray.Parse(jsonStr); jsonObj.Insert(FIELD_DEVICE_LIST, jsonArray); - params = SafetyDump(jsonObj); + params = jsonObj.Dump(); osAccountUserId = MultipleUserConnector::GetCurrentAccountUserID(); if (osAccountUserId < 0) { LOGE("get current process account user id failed"); @@ -972,7 +972,7 @@ int32_t HiChainConnector::GetGroupIdExt(const std::string &userId, const int32_t { JsonObject jsonObjGroup; jsonObjGroup[FIELD_GROUP_TYPE] = groupType; - std::string queryParams = SafetyDump(jsonObjGroup); + std::string queryParams = jsonObjGroup.Dump(); std::vector groupList; if (!GetGroupInfo(queryParams.c_str(), groupList)) { @@ -1029,7 +1029,7 @@ int32_t HiChainConnector::ParseRemoteCredentialExt(const std::string &credential JsonObject jsonArray(JsonCreateType::JSON_CREATE_TYPE_ARRAY); jsonArray.Parse(jsonStr); jsonObj.Insert(FIELD_DEVICE_LIST, jsonArray); - params = SafetyDump(jsonObj); + params = jsonObj.Dump(); return DM_OK; } @@ -1216,7 +1216,7 @@ int32_t HiChainConnector::DeleteGroup(const int32_t userId, std::string &groupId int64_t requestId = GenRequestId(); JsonObject jsonObj; jsonObj[FIELD_GROUP_ID] = groupId; - std::string disbandParams = SafetyDump(jsonObj); + std::string disbandParams = jsonObj.Dump(); int32_t ret = deviceGroupManager_->deleteGroup(userId, requestId, DM_PKG_NAME, disbandParams.c_str()); if (ret != 0) { LOGE("[HICHAIN]fail to delete group with ret:%{public}d.", ret); @@ -1304,7 +1304,7 @@ int32_t HiChainConnector::DeleteGroupByACL(std::vector groupList; if (!GetGroupInfo(userId, queryParams, groupList)) { diff --git a/services/implementation/src/dependency/hichain/mine_hichain_connector.cpp b/services/implementation/src/dependency/hichain/mine_hichain_connector.cpp index ec4da1957..e4a243401 100644 --- a/services/implementation/src/dependency/hichain/mine_hichain_connector.cpp +++ b/services/implementation/src/dependency/hichain/mine_hichain_connector.cpp @@ -136,7 +136,7 @@ int32_t MineHiChainConnector::DeleteCredentialAndGroup(void) { JsonObject jsonObj; jsonObj[FIELD_IS_DELETE_ALL] = true; - std::string params = SafetyDump(jsonObj); + std::string params = jsonObj.Dump(); #if (defined(MINE_HARMONY)) char *returnInfo = nullptr; int32_t retValue = g_deviceGroupManager->processCredential(DELETE_SELF_CREDENTIAL, params.c_str(), &returnInfo); @@ -174,7 +174,7 @@ int32_t MineHiChainConnector::CreateGroup(const std::string &reqJsonStr) jsonObj[FIELD_GROUP_NAME] = DEVICE_MANAGER_GROUPNAME; jsonObj[FIELD_DEVICE_ID] = std::string(deviceUdid); jsonObj[FIELD_GROUP_TYPE] = IDENTICAL_ACCOUNT_GROUP; - std::string createParams = SafetyDump(jsonObj); + std::string createParams = jsonObj.Dump(); retValue = g_deviceGroupManager->createGroup(DEFAULT_OS_ACCOUNT, requestId, DM_PKG_NAME, createParams.c_str()); if (retValue != HC_SUCCESS) { LOGE("failed to create group with ret:%{public}d.", retValue); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index ea4524253..a1333d81e 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -2305,7 +2305,7 @@ void DeviceManagerService::PutLocalUserIdToDataBase(const std::vector & JsonObject jsonObj; jsonObj[LOCAL_FOREGROUND_USERID] = foregroundUsers; jsonObj[LOCAL_BACKGROUND_USERID] = backgroundUsers; - std::string localUserIdStr = SafetyDump(jsonObj); + std::string localUserIdStr = jsonObj.Dump(); KVAdapterManager::GetInstance().PutLocalUserIdData(LOCAL_ALL_USERID, localUserIdStr); } diff --git a/services/service/src/hichain/hichain_listener.cpp b/services/service/src/hichain/hichain_listener.cpp index 499cc6843..002683238 100644 --- a/services/service/src/hichain/hichain_listener.cpp +++ b/services/service/src/hichain/hichain_listener.cpp @@ -296,7 +296,7 @@ int32_t HichainListener::DeleteGroup(const int32_t userId, std::string &groupId) int64_t requestId = GenRequestId(); JsonObject jsonObj; jsonObj[FIELD_GROUP_ID] = groupId; - std::string disbandParams = SafetyDump(jsonObj); + std::string disbandParams = jsonObj.Dump(); int32_t ret = deviceGroupManager_->deleteGroup(userId, requestId, DM_PKG_NAME, disbandParams.c_str()); if (ret != 0) { LOGE("[HICHAIN]fail to delete group with ret:%{public}d.", ret); @@ -310,7 +310,7 @@ int32_t HichainListener::DeleteGroupExt(int32_t userId, std::string &groupId) int64_t requestId = GenRequestId(); JsonObject jsonObj; jsonObj[FIELD_GROUP_ID] = groupId; - std::string disbandParams = SafetyDump(jsonObj); + std::string disbandParams = jsonObj.Dump(); int32_t ret = deviceGroupManager_->deleteGroup(userId, requestId, DM_PKG_NAME_EXT, disbandParams.c_str()); if (ret != 0) { LOGE("[HICHAIN]fail to delete group with ret:%{public}d.", ret); diff --git a/services/service/src/pinholder/pin_holder.cpp b/services/service/src/pinholder/pin_holder.cpp index 240a435fa..33099a52f 100644 --- a/services/service/src/pinholder/pin_holder.cpp +++ b/services/service/src/pinholder/pin_holder.cpp @@ -184,7 +184,7 @@ int32_t PinHolder::DestroyPinHolder(const std::string &pkgName, const PeerTarget jsonObj[TAG_PIN_TYPE] = pinType; jsonObj[TAG_PAYLOAD] = payload; pinType_ = pinType; - std::string message = SafetyDump(jsonObj); + std::string message = jsonObj.Dump(); LOGI("DestroyPinHolder, message type is: %{public}d, pin type is: %{public}d.", MSG_TYPE_DESTROY_PIN_HOLDER, pinType); ret = session_->SendData(sessionId_, message); @@ -218,7 +218,7 @@ int32_t PinHolder::CreateGeneratePinHolderMsg() jsonObj[TAG_PAYLOAD] = payload_; jsonObj[TAG_MSG_TYPE] = MSG_TYPE_CREATE_PIN_HOLDER; jsonObj[TAG_DM_VERSION] = ""; - std::string message = SafetyDump(jsonObj); + std::string message = jsonObj.Dump(); LOGI("CreateGeneratePinHolderMsg, message type is: %{public}d, pin type is: %{public}d.", MSG_TYPE_CREATE_PIN_HOLDER, pinType_); int32_t ret = session_->SendData(sessionId_, message); @@ -296,12 +296,12 @@ void PinHolder::ProcessCreateMsg(const std::string &message) jsonContent[TAG_PIN_TYPE] = pinType; jsonContent[TAG_PAYLOAD] = payload; jsonContent[TAG_REMOTE_DEVICE_ID] = remoteDeviceId_; - std::string content = SafetyDump(jsonContent); + std::string content = jsonContent.Dump(); listener_->OnPinHolderEvent(processInfo_, DmPinHolderEvent::CREATE, DM_OK, content); } jsonObj[TAG_DM_VERSION] = ""; - std::string msg = SafetyDump(jsonObj); + std::string msg = jsonObj.Dump(); LOGI("ProcessCreateMsg, message type is: %{public}d.", MSG_TYPE_CREATE_PIN_HOLDER_RESP); int32_t ret = session_->SendData(sessionId_, msg); if (ret != DM_OK) { @@ -376,13 +376,13 @@ void PinHolder::ProcessDestroyMsg(const std::string &message) JsonObject jsonContent; jsonContent[TAG_PIN_TYPE] = pinType; jsonContent[TAG_PAYLOAD] = payload; - std::string content = SafetyDump(jsonContent); + std::string content = jsonContent.Dump(); listener_->OnPinHolderEvent(processInfo_, DmPinHolderEvent::DESTROY, DM_OK, content); isDestroy_.store(true); } } - std::string msg = SafetyDump(jsonObj); + std::string msg = jsonObj.Dump(); LOGI("ProcessDestroyMsg, message type is: %{public}d.", MSG_TYPE_DESTROY_PIN_HOLDER_RESP); int32_t ret = session_->SendData(sessionId_, msg); if (ret != DM_OK) { @@ -400,13 +400,13 @@ void PinHolder::CloseSession(const std::string &name) } JsonObject jsonObj; jsonObj[DM_CONNECTION_DISCONNECTED] = true; - std::string payload = SafetyDump(jsonObj); + std::string payload = jsonObj.Dump(); if (listener_ != nullptr && !isDestroy_.load()) { listener_->OnPinHolderDestroy(processInfo_, pinType_, payload); JsonObject jsonContent; jsonContent[TAG_PIN_TYPE] = pinType_; jsonContent[TAG_PAYLOAD] = payload; - std::string content = SafetyDump(jsonContent); + std::string content = jsonContent.Dump(); listener_->OnPinHolderEvent(processInfo_, DmPinHolderEvent::DESTROY, ERR_DM_TIME_OUT, content); isDestroy_.store(true); } @@ -467,7 +467,7 @@ void PinHolder::OnDataReceived(int32_t sessionId, std::string message) LOGE("another session opened, close this sessionId: %{public}d.", sessionId); JsonObject jsonObj; jsonObj[TAG_MSG_TYPE] = MSG_TYPE_PIN_CLOSE_SESSION; - std::string msg = SafetyDump(jsonObj); + std::string msg = jsonObj.Dump(); int32_t ret = session_->SendData(sessionId, msg); if (ret != DM_OK) { LOGE("[SOFTBUS] SendBytes failed. ret: %{public}d.", ret); @@ -569,13 +569,13 @@ void PinHolder::OnSessionClosed(int32_t sessionId) isRemoteSupported_ = false; JsonObject jsonObj; jsonObj[DM_CONNECTION_DISCONNECTED] = true; - std::string payload = SafetyDump(jsonObj); + std::string payload = jsonObj.Dump(); if (listener_ != nullptr && !isDestroy_.load()) { listener_->OnPinHolderDestroy(processInfo_, pinType_, payload); JsonObject jsonContent; jsonContent[TAG_PIN_TYPE] = pinType_; jsonContent[TAG_PAYLOAD] = payload; - std::string content = SafetyDump(jsonContent); + std::string content = jsonContent.Dump(); if (destroyState_ == STATE_UNKNOW) { listener_->OnPinHolderEvent(processInfo_, DmPinHolderEvent::DESTROY, sessionId, content); } else if (destroyState_ == STATE_REMOTE_WRONG) { @@ -635,7 +635,7 @@ int32_t PinHolder::NotifyPinHolderEvent(const std::string &pkgName, const std::s JsonObject jsonObj; jsonObj[TAG_MSG_TYPE] = MSG_TYPE_PIN_HOLDER_CHANGE; jsonObj[TAG_PIN_TYPE] = pinType; - std::string message = SafetyDump(jsonObj); + std::string message = jsonObj.Dump(); LOGI("NotifyPinHolderEvent, message type is: %{public}d, pin type is: %{public}d.", MSG_TYPE_PIN_HOLDER_CHANGE, pinType); int32_t ret = session_->SendData(sessionId_, message); @@ -672,7 +672,7 @@ void PinHolder::ProcessChangeMsg(const std::string &message) jsonObj[TAG_REPLY] = REPLY_SUCCESS; JsonObject jsonContent; jsonContent[TAG_PIN_TYPE] = pinType; - std::string content = SafetyDump(jsonContent); + std::string content = jsonContent.Dump(); listener_->OnPinHolderEvent(processInfo_, DmPinHolderEvent::PIN_TYPE_CHANGE, DM_OK, content); if (timer_ != nullptr) { timer_->DeleteAll(); @@ -683,7 +683,7 @@ void PinHolder::ProcessChangeMsg(const std::string &message) } } - std::string msg = SafetyDump(jsonObj); + std::string msg = jsonObj.Dump(); LOGI("ProcessChangeMsg, message type is: %{public}d.", MSG_TYPE_PIN_HOLDER_CHANGE_RESP); int32_t ret = session_->SendData(sessionId_, msg); if (ret != DM_OK) { diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index f834a08e3..d19720175 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -958,13 +958,13 @@ void SoftbusListener::ConvertDeviceInfoToDmDevice(const DeviceInfo &device, DmDe const ConnectionAddr *addrInfo = &(device.addr)[0]; if (addrInfo == nullptr) { LOGE("ConvertDeviceInfoToDmDevice: addrInfo is nullptr."); - dmDevice.extraData = SafetyDump(jsonObj); + dmDevice.extraData = jsonObj.Dump(); return; } jsonObj[PARAM_KEY_DISC_CAPABILITY] = device.capabilityBitmap[0]; ParseConnAddrInfo(addrInfo, jsonObj); jsonObj[PARAM_KEY_ACCOUNT_HASH] = std::string(device.accountHash); - dmDevice.extraData = SafetyDump(jsonObj); + dmDevice.extraData = jsonObj.Dump(); } void SoftbusListener::ParseConnAddrInfo(const ConnectionAddr *addrInfo, JsonObject &jsonObj) @@ -1468,7 +1468,7 @@ void SoftbusListener::ConvertOsTypeToJson(int32_t osType, std::string &osTypeStr JsonObject jsonObj; jsonObj[PEER_OSTYPE] = osType; jsonObj[TIME_STAMP] = nowTime; - osTypeStr = SafetyDump(jsonObj); + osTypeStr = jsonObj.Dump(); } bool SoftbusListener::CheckPeerUdidTrusted(const std::string &udid) diff --git a/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp b/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp index 856d739cf..65e598d6e 100644 --- a/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp +++ b/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp @@ -334,13 +334,13 @@ void HiChainConnectorSixthFuzzTest(const uint8_t* data, size_t size) jsonObj[key] = 1; jsonObj["deviceName"] = "devieName1"; hichainConnector->GetJsonInt(jsonObj, "devieName"); - hichainConnector->AddMember(deviceId, SafetyDump(jsonObj)); + hichainConnector->AddMember(deviceId, jsonObj.Dump()); jsonObj[TAG_DEVICE_ID] = "deviceId_001"; jsonObj[PIN_CODE_KEY] = 1; jsonObj[TAG_GROUP_ID] = "groupId"; jsonObj[TAG_REQUEST_ID] = 1; jsonObj[TAG_GROUP_NAME] = "groupName"; - hichainConnector->AddMember(deviceId, SafetyDump(jsonObj)); + hichainConnector->AddMember(deviceId, jsonObj.Dump()); JsonObject jsonObjCre; std::string params; @@ -350,7 +350,7 @@ void HiChainConnectorSixthFuzzTest(const uint8_t* data, size_t size) jsonObjCre[FIELD_OPERATION_CODE] = 1; jsonObjCre[FIELD_META_NODE_TYPE] = "metaNode_002"; jsonObjCre[FIELD_DEVICE_LIST] = "deviceList"; - std::string credentialInfo = SafetyDump(jsonObjCre); + std::string credentialInfo = jsonObjCre.Dump(); hichainConnector->ParseRemoteCredentialExt(credentialInfo, params, groupOwner); int32_t groupType = *(reinterpret_cast(data)); JsonObject jsonDeviceList; diff --git a/test/commonunittest/UTTest_discovery_filter.cpp b/test/commonunittest/UTTest_discovery_filter.cpp index ce734d15a..3ab9af7b5 100644 --- a/test/commonunittest/UTTest_discovery_filter.cpp +++ b/test/commonunittest/UTTest_discovery_filter.cpp @@ -47,7 +47,7 @@ HWTEST_F(DiscoveryFilterTest, ParseFilterJson_002, testing::ext::TestSize.Level0 { DeviceFilterOption filterOption; JsonObject jsonObject; - std::string str = SafetyDump(jsonObject); + std::string str = jsonObject.Dump(); int32_t ret = filterOption.ParseFilterJson(str); EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); } @@ -57,7 +57,7 @@ HWTEST_F(DiscoveryFilterTest, ParseFilterJson_003, testing::ext::TestSize.Level0 DeviceFilterOption filterOption; JsonObject jsonObject; jsonObject[FILTERS_KEY] = "filters"; - std::string str = SafetyDump(jsonObject); + std::string str = jsonObject.Dump(); int32_t ret = filterOption.ParseFilterJson(str); EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); } @@ -68,7 +68,7 @@ HWTEST_F(DiscoveryFilterTest, ParseFilterJson_004, testing::ext::TestSize.Level0 JsonObject jsonObject; std::vector myArray; jsonObject[FILTERS_KEY] = myArray; - std::string str = SafetyDump(jsonObject); + std::string str = jsonObject.Dump(); int32_t ret = filterOption.ParseFilterJson(str); EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); } @@ -79,7 +79,7 @@ HWTEST_F(DiscoveryFilterTest, ParseFilterJson_005, testing::ext::TestSize.Level0 JsonObject jsonObject; std::vector myArray = {1, 2, 3, 4, 5}; jsonObject[FILTERS_KEY] = myArray; - std::string str = SafetyDump(jsonObject); + std::string str = jsonObject.Dump(); int32_t ret = filterOption.ParseFilterJson(str); EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); } @@ -91,7 +91,7 @@ HWTEST_F(DiscoveryFilterTest, ParseFilterJson_006, testing::ext::TestSize.Level0 std::vector myArray = {1, 2, 3, 4, 5}; jsonObject[FILTERS_KEY] = myArray; jsonObject[FILTER_OP_KEY] = 12345; - std::string str = SafetyDump(jsonObject); + std::string str = jsonObject.Dump(); int32_t ret = filterOption.ParseFilterJson(str); EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); } @@ -103,7 +103,7 @@ HWTEST_F(DiscoveryFilterTest, ParseFilterJson_007, testing::ext::TestSize.Level0 std::vector myArray = {1, 2, 3, 4, 5}; jsonObject[FILTERS_KEY] = myArray; jsonObject[FILTER_OP_KEY] = "filter_op"; - std::string str = SafetyDump(jsonObject); + std::string str = jsonObject.Dump(); int32_t ret = filterOption.ParseFilterJson(str); EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); } @@ -167,7 +167,7 @@ HWTEST_F(DiscoveryFilterTest, ParseFilterOptionJson_002, testing::ext::TestSize. { DeviceFilterOption filterOption; JsonObject jsonObject; - std::string str = SafetyDump(jsonObject); + std::string str = jsonObject.Dump(); filterOption.ParseFilterOptionJson(str); EXPECT_EQ(filterOption.filterOp_ == "AND", true); } @@ -177,7 +177,7 @@ HWTEST_F(DiscoveryFilterTest, ParseFilterOptionJson_003, testing::ext::TestSize. DeviceFilterOption filterOption; JsonObject jsonObject; jsonObject["credible"] = "123"; - std::string str = SafetyDump(jsonObject); + std::string str = jsonObject.Dump(); filterOption.ParseFilterOptionJson(str); EXPECT_EQ(filterOption.filterOp_ == "AND", true); } @@ -188,7 +188,7 @@ HWTEST_F(DiscoveryFilterTest, ParseFilterOptionJson_004, testing::ext::TestSize. JsonObject jsonObject; jsonObject["credible"] = 1; jsonObject["isTrusted"] = "123"; - std::string str = SafetyDump(jsonObject); + std::string str = jsonObject.Dump(); filterOption.ParseFilterOptionJson(str); EXPECT_EQ(filterOption.filterOp_ == "AND", true); } @@ -200,7 +200,7 @@ HWTEST_F(DiscoveryFilterTest, ParseFilterOptionJson_005, testing::ext::TestSize. jsonObject["credible"] = 1; jsonObject["isTrusted"] = 2; jsonObject["authForm"] = "3"; - std::string str = SafetyDump(jsonObject); + std::string str = jsonObject.Dump(); filterOption.ParseFilterOptionJson(str); EXPECT_EQ(filterOption.filterOp_ == "AND", true); } @@ -213,7 +213,7 @@ HWTEST_F(DiscoveryFilterTest, ParseFilterOptionJson_006, testing::ext::TestSize. jsonObject["isTrusted"] = 2; jsonObject["authForm"] = 3; jsonObject["deviceType"] = "4"; - std::string str = SafetyDump(jsonObject); + std::string str = jsonObject.Dump(); filterOption.ParseFilterOptionJson(str); EXPECT_EQ(filterOption.filterOp_ == "AND", true); } @@ -226,7 +226,7 @@ HWTEST_F(DiscoveryFilterTest, ParseFilterOptionJson_007, testing::ext::TestSize. jsonObject["isTrusted"] = 2; jsonObject["authForm"] = 3; jsonObject["deviceType"] = 4; - std::string str = SafetyDump(jsonObject); + std::string str = jsonObject.Dump(); filterOption.ParseFilterOptionJson(str); EXPECT_EQ(filterOption.filterOp_ == "AND", true); } diff --git a/test/commonunittest/UTTest_dm_auth_manager_first.cpp b/test/commonunittest/UTTest_dm_auth_manager_first.cpp index e82099835..68638d2dd 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_first.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_first.cpp @@ -1140,7 +1140,7 @@ HWTEST_F(DmAuthManagerTest, OnAuthDeviceDataReceived002, testing::ext::TestSize. int32_t sessionId = 0; JsonObject jsonObject; jsonObject[TAG_DATA] = 123; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); authManager_->OnAuthDeviceDataReceived(sessionId, message); ASSERT_EQ(authManager_->isAuthDevice_, false); } @@ -1151,7 +1151,7 @@ HWTEST_F(DmAuthManagerTest, OnAuthDeviceDataReceived003, testing::ext::TestSize. JsonObject jsonObject; jsonObject[TAG_DATA] = "123"; jsonObject[TAG_DATA_LEN] = "123"; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); authManager_->OnAuthDeviceDataReceived(sessionId, message); ASSERT_EQ(authManager_->isAuthDevice_, false); } @@ -1163,7 +1163,7 @@ HWTEST_F(DmAuthManagerTest, OnAuthDeviceDataReceived004, testing::ext::TestSize. jsonObject[TAG_DATA] = "123"; jsonObject[TAG_DATA_LEN] = 123; jsonObject[TAG_MSG_TYPE] = "123"; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); authManager_->OnAuthDeviceDataReceived(sessionId, message); ASSERT_EQ(authManager_->isAuthDevice_, false); } @@ -1175,7 +1175,7 @@ HWTEST_F(DmAuthManagerTest, OnAuthDeviceDataReceived005, testing::ext::TestSize. jsonObject[TAG_DATA] = "123"; jsonObject[TAG_DATA_LEN] = 123; jsonObject[TAG_MSG_TYPE] = 123; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); authManager_->OnAuthDeviceDataReceived(sessionId, message); ASSERT_EQ(authManager_->isAuthDevice_, false); } @@ -1404,7 +1404,7 @@ HWTEST_F(DmAuthManagerTest, CheckAuthParamVaildExtra_001, testing::ext::TestSize int32_t ret = authManager_->CheckAuthParamVaildExtra(extra, ""); EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); - extra = SafetyDump(jsonObject); + extra = jsonObject.Dump(); EXPECT_CALL(*appManagerMock_, IsSystemSA()).WillOnce(Return(false)); ret = authManager_->CheckAuthParamVaildExtra(extra, ""); EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); @@ -1414,7 +1414,7 @@ HWTEST_F(DmAuthManagerTest, CheckAuthParamVaildExtra_001, testing::ext::TestSize EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); jsonObject["bindLevel"] = 15; - extra = SafetyDump(jsonObject); + extra = jsonObject.Dump(); ret = authManager_->CheckAuthParamVaildExtra(extra, ""); EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); } diff --git a/test/commonunittest/UTTest_dm_auth_manager_second.cpp b/test/commonunittest/UTTest_dm_auth_manager_second.cpp index 93497bc7f..7e654c117 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_second.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_second.cpp @@ -118,7 +118,7 @@ HWTEST_F(DmAuthManagerTest, OnDataReceived_007, testing::ext::TestSize.Level1) int32_t sessionId = 0; JsonObject jsonObject; jsonObject[TAG_MSG_TYPE] = 200; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); authManager_->OnDataReceived(sessionId, message); authManager_->authRequestState_ = nullptr; authManager_->authResponseState_ = nullptr; @@ -1380,7 +1380,7 @@ HWTEST_F(DmAuthManagerTest, GetAuthParam_002, testing::ext::TestSize.Level1) { JsonObject jsonObject; jsonObject["targetPkgName"] = 1234; - std::string extra = SafetyDump(jsonObject); + std::string extra = jsonObject.Dump(); int32_t authType = 5; std::string pkgName = "ohos_test"; std::string deviceId = "512156"; @@ -1393,7 +1393,7 @@ HWTEST_F(DmAuthManagerTest, GetAuthParam_003, testing::ext::TestSize.Level1) JsonObject jsonObject; jsonObject["targetPkgName"] = "1234"; jsonObject["appOperation"] = 1234; - std::string extra = SafetyDump(jsonObject); + std::string extra = jsonObject.Dump(); int32_t authType = 5; std::string pkgName = "ohos_test"; std::string deviceId = "512156"; @@ -1407,7 +1407,7 @@ HWTEST_F(DmAuthManagerTest, GetAuthParam_004, testing::ext::TestSize.Level1) jsonObject["targetPkgName"] = "1234"; jsonObject["appOperation"] = "1234"; jsonObject["customDescription"] = 1234; - std::string extra = SafetyDump(jsonObject); + std::string extra = jsonObject.Dump(); int32_t authType = 5; std::string pkgName = "ohos_test"; std::string deviceId = "512156"; @@ -1422,7 +1422,7 @@ HWTEST_F(DmAuthManagerTest, GetAuthParam_005, testing::ext::TestSize.Level1) jsonObject["appOperation"] = "1234"; jsonObject["customDescription"] = "1234"; jsonObject["appThumbnail"] = 1234; - std::string extra = SafetyDump(jsonObject); + std::string extra = jsonObject.Dump(); int32_t authType = 5; std::string pkgName = "ohos_test"; std::string deviceId = "512156"; @@ -1438,7 +1438,7 @@ HWTEST_F(DmAuthManagerTest, GetAuthParam_006, testing::ext::TestSize.Level1) jsonObject["customDescription"] = "1234"; jsonObject["appThumbnail"] = "1234"; jsonObject["tokenId"] = "1234"; - std::string extra = SafetyDump(jsonObject); + std::string extra = jsonObject.Dump(); int32_t authType = 5; std::string pkgName = "ohos_test"; std::string deviceId = "512156"; @@ -1455,7 +1455,7 @@ HWTEST_F(DmAuthManagerTest, GetAuthParam_007, testing::ext::TestSize.Level1) jsonObject["appThumbnail"] = "1234"; jsonObject["tokenId"] = 1234; jsonObject["bindLevel"] = "1234"; - std::string extra = SafetyDump(jsonObject); + std::string extra = jsonObject.Dump(); int32_t authType = 5; std::string pkgName = "ohos_test"; std::string deviceId = "512156"; @@ -1472,7 +1472,7 @@ HWTEST_F(DmAuthManagerTest, GetAuthParam_008, testing::ext::TestSize.Level1) jsonObject["appThumbnail"] = "1234"; jsonObject["tokenId"] = 1234; jsonObject["bindLevel"] = 1234; - std::string extra = SafetyDump(jsonObject); + std::string extra = jsonObject.Dump(); int32_t authType = 5; std::string pkgName = "ohos_test"; std::string deviceId = "512156"; @@ -1484,7 +1484,7 @@ HWTEST_F(DmAuthManagerTest, GetAuthParam_009, testing::ext::TestSize.Level1) { JsonObject jsonObject; jsonObject["DM_CLOSE_SESSION_DELAY_SECONDS"] = 1234; - std::string extra = SafetyDump(jsonObject); + std::string extra = jsonObject.Dump(); int32_t authType = 5; std::string pkgName = "ohos_test"; std::string deviceId = "512156"; @@ -1496,7 +1496,7 @@ HWTEST_F(DmAuthManagerTest, GetAuthParam_010, testing::ext::TestSize.Level1) { JsonObject jsonObject; jsonObject["DM_CLOSE_SESSION_DELAY_SECONDS"] = "1234"; - std::string extra = SafetyDump(jsonObject); + std::string extra = jsonObject.Dump(); int32_t authType = 5; std::string pkgName = "ohos_test"; std::string deviceId = "512156"; @@ -1590,7 +1590,7 @@ HWTEST_F(DmAuthManagerTest, IsIdenticalAccount_201, testing::ext::TestSize.Level JsonObject jsonPeerGroupIdObj; jsonPeerGroupIdObj["groupId"] = "123456"; - authManager_->authResponseContext_->accountGroupIdHash = SafetyDump(jsonPeerGroupIdObj); + authManager_->authResponseContext_->accountGroupIdHash = jsonPeerGroupIdObj.Dump(); EXPECT_CALL(*multipleUserConnectorMock_, GetCurrentAccountUserID()).WillOnce(Return(0)); EXPECT_CALL(*hiChainConnectorMock_, GetGroupInfo(_, _, _)).WillOnce(Return(true)); EXPECT_CALL(*cryptoMock_, GetGroupIdHash(_)).WillOnce(Return("123")); diff --git a/test/commonunittest/UTTest_dm_auth_manager_third.cpp b/test/commonunittest/UTTest_dm_auth_manager_third.cpp index 559b079e2..3ddc8c5dc 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_third.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_third.cpp @@ -133,13 +133,13 @@ void DmAuthManagerTest::TearDownTestCase() {} HWTEST_F(DmAuthManagerTest, ProcRespNegotiate001, testing::ext::TestSize.Level1) { JsonObject jsonObject; - g_createSimpleMessageReturnDataStr = SafetyDump(jsonObject); + g_createSimpleMessageReturnDataStr = jsonObject.Dump(); int32_t sessionId = 0; authManager_->remoteDeviceId_ = "ProcRespNegotiate001"; authManager_->ProcRespNegotiate(sessionId); jsonObject[TAG_CRYPTO_SUPPORT] = false; - g_createSimpleMessageReturnDataStr = SafetyDump(jsonObject); + g_createSimpleMessageReturnDataStr = jsonObject.Dump(); g_isIdenticalAccountReturnBoolValue = true; authManager_->authResponseContext_ = std::make_shared(); authManager_->authResponseContext_->authType = AUTH_TYPE_CRE; @@ -148,7 +148,7 @@ HWTEST_F(DmAuthManagerTest, ProcRespNegotiate001, testing::ext::TestSize.Level1) authManager_->authResponseContext_ = std::make_shared(); authManager_->authResponseState_->context_ = std::make_shared(); jsonObject[TAG_CRYPTO_SUPPORT] = true; - g_createSimpleMessageReturnDataStr = SafetyDump(jsonObject); + g_createSimpleMessageReturnDataStr = jsonObject.Dump(); g_isIdenticalAccountReturnBoolValue = true; authManager_->importAuthCode_ = ""; authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE; @@ -156,7 +156,7 @@ HWTEST_F(DmAuthManagerTest, ProcRespNegotiate001, testing::ext::TestSize.Level1) authManager_->ProcRespNegotiate(sessionId); authManager_->authResponseState_->context_ = std::make_shared(); - g_createSimpleMessageReturnDataStr = SafetyDump(jsonObject); + g_createSimpleMessageReturnDataStr = jsonObject.Dump(); g_isIdenticalAccountReturnBoolValue = true; authManager_->importAuthCode_ = "test"; authManager_->authResponseContext_ = std::make_shared(); @@ -166,7 +166,7 @@ HWTEST_F(DmAuthManagerTest, ProcRespNegotiate001, testing::ext::TestSize.Level1) authManager_->authResponseState_->context_ = std::make_shared(); jsonObject[TAG_CRYPTO_NAME] = "test"; - g_createSimpleMessageReturnDataStr = SafetyDump(jsonObject); + g_createSimpleMessageReturnDataStr = jsonObject.Dump(); g_isIdenticalAccountReturnBoolValue = true; authManager_->importAuthCode_ = "test"; authManager_->authResponseContext_ = std::make_shared(); @@ -179,13 +179,13 @@ HWTEST_F(DmAuthManagerTest, ProcRespNegotiate001, testing::ext::TestSize.Level1) HWTEST_F(DmAuthManagerTest, ProcRespNegotiate002, testing::ext::TestSize.Level1) { JsonObject jsonObject; - g_createSimpleMessageReturnDataStr = SafetyDump(jsonObject); + g_createSimpleMessageReturnDataStr = jsonObject.Dump(); int32_t sessionId = 0; authManager_->authResponseState_->context_ = std::make_shared(); jsonObject[TAG_CRYPTO_SUPPORT] = true; jsonObject[TAG_CRYPTO_NAME] = "test"; jsonObject[TAG_CRYPTO_VERSION] = "test"; - g_createSimpleMessageReturnDataStr = SafetyDump(jsonObject); + g_createSimpleMessageReturnDataStr = jsonObject.Dump(); g_isIdenticalAccountReturnBoolValue = false; authManager_->remoteDeviceId_ = "ProcRespNegotiate002"; authManager_->importAuthCode_ = "test"; @@ -199,7 +199,7 @@ HWTEST_F(DmAuthManagerTest, ProcRespNegotiate002, testing::ext::TestSize.Level1) jsonObject[TAG_CRYPTO_SUPPORT] = true; jsonObject[TAG_CRYPTO_NAME] = "test"; jsonObject[TAG_CRYPTO_VERSION] = "test"; - g_createSimpleMessageReturnDataStr = SafetyDump(jsonObject); + g_createSimpleMessageReturnDataStr = jsonObject.Dump(); g_isIdenticalAccountReturnBoolValue = false; authManager_->importAuthCode_ = "test"; authManager_->authResponseContext_ = std::make_shared(); diff --git a/test/commonunittest/UTTest_dm_credential_manager.cpp b/test/commonunittest/UTTest_dm_credential_manager.cpp index 6d882bc20..389213391 100644 --- a/test/commonunittest/UTTest_dm_credential_manager.cpp +++ b/test/commonunittest/UTTest_dm_credential_manager.cpp @@ -181,7 +181,7 @@ HWTEST_F(DmCredentialManagerTest, RequestCredential_001, testing::ext::TestSize. JsonObject jsonObject; jsonObject["userId"] = "test"; jsonObject["version"] = "test"; - reqJsonStr = SafetyDump(jsonObject); + reqJsonStr = jsonObject.Dump(); ret = dmCreMgr_->RequestCredential(reqJsonStr, returnJsonStr); ASSERT_EQ(ret, ERR_DM_FAILED); } @@ -279,22 +279,22 @@ HWTEST_F(DmCredentialManagerTest, ImportCredential_001, testing::ext::TestSize.L JsonObject jsonObject(credentialInfo); jsonObject["TType"] = 1; jsonObject["processType"] = 1; - credentialInfo = SafetyDump(jsonObject); + credentialInfo = jsonObject.Dump(); ret = dmCreMgr_->ImportCredential(pkgName, credentialInfo); EXPECT_EQ(ret, ERR_DM_FAILED); jsonObject["processType"] = -1; - credentialInfo = SafetyDump(jsonObject); + credentialInfo = jsonObject.Dump(); ret = dmCreMgr_->ImportCredential(pkgName, credentialInfo); EXPECT_EQ(ret, ERR_DM_FAILED); jsonObject["processType"] = 2; - credentialInfo = SafetyDump(jsonObject); + credentialInfo = jsonObject.Dump(); ret = dmCreMgr_->ImportCredential(pkgName, credentialInfo); EXPECT_EQ(ret, ERR_DM_FAILED); jsonObject["TType"] = "test"; - credentialInfo = SafetyDump(jsonObject); + credentialInfo = jsonObject.Dump(); ret = dmCreMgr_->ImportCredential(pkgName, credentialInfo); EXPECT_EQ(ret, ERR_DM_FAILED); } @@ -718,13 +718,13 @@ HWTEST_F(DmCredentialManagerTest, ImportRemoteCredential_001, testing::ext::Test jsonObject[FIELD_USER_ID] = 0; jsonObject[FIELD_PEER_USER_ID] = "peerUserId"; - std::string credentialInfo = SafetyDump(jsonObject); + std::string credentialInfo = jsonObject.Dump(); dmCreMgr_->hiChainConnector_->deviceGroupManager_ = nullptr; int32_t ret = dmCreMgr_->ImportRemoteCredential(credentialInfo); EXPECT_EQ(ret, ERR_DM_FAILED); jsonObject[FIELD_CREDENTIAL_DATA] = 0; - credentialInfo = SafetyDump(jsonObject); + credentialInfo = jsonObject.Dump(); ret = dmCreMgr_->ImportRemoteCredential(credentialInfo); EXPECT_EQ(ret, ERR_DM_FAILED); } @@ -1656,7 +1656,7 @@ HWTEST_F(DmCredentialManagerTest, from_json_001, testing::ext::TestSize.Level1) JsonObject jsonPkInfo; jsonOutObj[FIELD_SERVER_PK] = "serverPk"; jsonOutObj[FIELD_PKINFO_SIGNATURE] = "pkInfoSignature"; - jsonOutObj[FIELD_PKINFO] = SafetyDump(jsonPkInfo); + jsonOutObj[FIELD_PKINFO] = jsonPkInfo.Dump(); jsonOutObj[FIELD_PEER_DEVICE_ID] = "peerDeviceId"; FromJson(jsonOutObj, credentialDataInfo); EXPECT_FALSE(credentialDataInfo.serverPk.empty()); diff --git a/test/commonunittest/UTTest_hichain_auth_connector.cpp b/test/commonunittest/UTTest_hichain_auth_connector.cpp index 447e195b5..96c032ccd 100644 --- a/test/commonunittest/UTTest_hichain_auth_connector.cpp +++ b/test/commonunittest/UTTest_hichain_auth_connector.cpp @@ -233,7 +233,7 @@ HWTEST_F(HiChainAuthConnectorTest, GenerateCredential_002, testing::ext::TestSiz int32_t osAccountId = 0; std::string publicKey; g_processCredentialResultCode = HC_SUCCESS; - g_processCredentialReturnDataStr = "{invalid_json}";; + g_processCredentialReturnDataStr = "{invalid_json}"; int32_t ret = hiChain_->GenerateCredential(localUdid, osAccountId, publicKey); EXPECT_NE(ret, DM_OK); } @@ -296,7 +296,7 @@ HWTEST_F(HiChainAuthConnectorTest, QueryCredential_002, testing::ext::TestSize.L JsonObject jsonObject; jsonObject["result"] = 15; jsonObject["publicKey"] = 0; - std::string localUdid = SafetyDump(jsonObject); + std::string localUdid = jsonObject.Dump(); int32_t osAccountId = 1245; int32_t peerOsAccountId = -1; bool ret = hiChain_->QueryCredential(localUdid, osAccountId, peerOsAccountId); @@ -308,7 +308,7 @@ HWTEST_F(HiChainAuthConnectorTest, QueryCredential_003, testing::ext::TestSize.L JsonObject jsonObject; jsonObject["result"] = 15; jsonObject["publicKey"] = 0; - std::string localUdid = SafetyDump(jsonObject); + std::string localUdid = jsonObject.Dump(); g_processCredentialResultCode = HC_SUCCESS; g_processCredentialReturnDataStr = "{invalid_json}"; int32_t osAccountId = 1245; @@ -322,7 +322,7 @@ HWTEST_F(HiChainAuthConnectorTest, QueryCredential_004, testing::ext::TestSize.L JsonObject jsonObject; jsonObject["result"] = 15; jsonObject["publicKey"] = 0; - std::string localUdid = SafetyDump(jsonObject); + std::string localUdid = jsonObject.Dump(); g_processCredentialResultCode = HC_SUCCESS; g_processCredentialReturnDataStr = R"({"result": "not_an_int", "publicKey": "key"})"; int32_t osAccountId = 1245; @@ -336,7 +336,7 @@ HWTEST_F(HiChainAuthConnectorTest, QueryCredential_005, testing::ext::TestSize.L JsonObject jsonObject; jsonObject["result"] = 15; jsonObject["publicKey"] = 0; - std::string localUdid = SafetyDump(jsonObject); + std::string localUdid = jsonObject.Dump(); g_processCredentialResultCode = HC_SUCCESS; g_processCredentialReturnDataStr = R"({"result": -1, "publicKey": "key"})"; int32_t osAccountId = 1245; @@ -350,7 +350,7 @@ HWTEST_F(HiChainAuthConnectorTest, QueryCredential_006, testing::ext::TestSize.L JsonObject jsonObject; jsonObject["result"] = 15; jsonObject["publicKey"] = 0; - std::string localUdid = SafetyDump(jsonObject); + std::string localUdid = jsonObject.Dump(); g_processCredentialResultCode = HC_SUCCESS; g_processCredentialReturnDataStr = R"({"result": 1, "publicKey": 0})"; int32_t osAccountId = 1245; @@ -364,7 +364,7 @@ HWTEST_F(HiChainAuthConnectorTest, QueryCredential_007, testing::ext::TestSize.L JsonObject jsonObject; jsonObject["result"] = 15; jsonObject["publicKey"] = 0; - std::string localUdid = SafetyDump(jsonObject); + std::string localUdid = jsonObject.Dump(); g_processCredentialResultCode = HC_SUCCESS; g_processCredentialReturnDataStr = R"({"result": 1, "publicKey": "string"})"; int32_t osAccountId = 1245; @@ -378,7 +378,7 @@ HWTEST_F(HiChainAuthConnectorTest, QueryCredential_008, testing::ext::TestSize.L JsonObject jsonObject; jsonObject["result"] = 15; jsonObject["publicKey"] = 0; - std::string localUdid = SafetyDump(jsonObject); + std::string localUdid = jsonObject.Dump(); g_processCredentialResultCode = HC_SUCCESS; g_processCredentialReturnDataStr = R"({"result": 2, "publicKey": "string"})"; int32_t osAccountId = 1245; diff --git a/test/commonunittest/UTTest_hichain_connector.cpp b/test/commonunittest/UTTest_hichain_connector.cpp index 81ea90399..9784668e4 100755 --- a/test/commonunittest/UTTest_hichain_connector.cpp +++ b/test/commonunittest/UTTest_hichain_connector.cpp @@ -1202,7 +1202,7 @@ HWTEST_F(HichainConnectorTest, ParseRemoteCredentialExt_001, testing::ext::TestS HWTEST_F(HichainConnectorTest, ParseRemoteCredentialExt_002, testing::ext::TestSize.Level1) { JsonObject jsonObj; - std::string credentialInfo = SafetyDump(jsonObj); + std::string credentialInfo = jsonObj.Dump(); std::string params; std::string groupOwner; std::shared_ptr hiChainConnector = std::make_shared(); @@ -1221,7 +1221,7 @@ HWTEST_F(HichainConnectorTest, ParseRemoteCredentialExt_003, testing::ext::TestS JsonObject jsonObj; jsonObj["authType"] = 1; jsonObj[FIELD_USER_ID] = "156103"; - std::string credentialInfo = SafetyDump(jsonObj); + std::string credentialInfo = jsonObj.Dump(); std::string params; std::string groupOwner; std::shared_ptr hiChainConnector = std::make_shared(); @@ -1240,7 +1240,7 @@ HWTEST_F(HichainConnectorTest, ParseRemoteCredentialExt_004, testing::ext::TestS JsonObject jsonObj; jsonObj["authType"] = 4; jsonObj[FIELD_USER_ID] = "156103"; - std::string credentialInfo = SafetyDump(jsonObj); + std::string credentialInfo = jsonObj.Dump(); std::string params; std::string groupOwner; std::shared_ptr hiChainConnector = std::make_shared(); @@ -1272,7 +1272,7 @@ HWTEST_F(HichainConnectorTest, addMultiMembersExt_001, testing::ext::TestSize.Le HWTEST_F(HichainConnectorTest, addMultiMembersExt_002, testing::ext::TestSize.Level1) { JsonObject jsonObj; - std::string credentialInfo = SafetyDump(jsonObj); + std::string credentialInfo = jsonObj.Dump(); std::shared_ptr hiChainConnector = std::make_shared(); int32_t ret = hiChainConnector->addMultiMembersExt(credentialInfo); EXPECT_EQ(ret, ERR_DM_FAILED); @@ -1316,7 +1316,7 @@ HWTEST_F(HichainConnectorTest, GetTrustedDevicesUdid_001, testing::ext::TestSize HWTEST_F(HichainConnectorTest, GetTrustedDevicesUdid_002, testing::ext::TestSize.Level1) { JsonObject jsonObj; - std::string jsonStr = SafetyDump(jsonObj); + std::string jsonStr = jsonObj.Dump(); std::vector udidList; std::shared_ptr hiChainConnector = std::make_shared(); int32_t ret = hiChainConnector->GetTrustedDevicesUdid(jsonStr.c_str(), udidList); diff --git a/test/commonunittest/UTTest_mine_hichain_connector.cpp b/test/commonunittest/UTTest_mine_hichain_connector.cpp index 017d2775b..133110c9b 100644 --- a/test/commonunittest/UTTest_mine_hichain_connector.cpp +++ b/test/commonunittest/UTTest_mine_hichain_connector.cpp @@ -113,7 +113,7 @@ HWTEST_F(MiniHiChainAuthConnectorTest, CreateGroup_002, testing::ext::TestSize.L std::shared_ptr minHiChain = std::make_shared(); JsonObject jsonObject; jsonObject["userId"] = 123456789; - std::string reqJsonStr = SafetyDump(jsonObject); + std::string reqJsonStr = jsonObject.Dump(); int32_t ret = minHiChain->CreateGroup(reqJsonStr); EXPECT_EQ(ret, ERR_DM_FAILED); } @@ -123,7 +123,7 @@ HWTEST_F(MiniHiChainAuthConnectorTest, CreateGroup_003, testing::ext::TestSize.L std::shared_ptr minHiChain = std::make_shared(); JsonObject jsonObject; jsonObject["userId"] = "123456789"; - std::string reqJsonStr = SafetyDump(jsonObject); + std::string reqJsonStr = jsonObject.Dump(); int32_t ret = minHiChain->CreateGroup(reqJsonStr); EXPECT_EQ(ret, ERR_DM_FAILED); } @@ -133,7 +133,7 @@ HWTEST_F(MiniHiChainAuthConnectorTest, RequestCredential_001, testing::ext::Test std::shared_ptr minHiChain = std::make_shared(); JsonObject jsonObject; jsonObject["userId"] = "123456789"; - std::string returnJsonStr = SafetyDump(jsonObject); + std::string returnJsonStr = jsonObject.Dump(); int32_t ret = minHiChain->RequestCredential(returnJsonStr); EXPECT_EQ(ret, DM_OK); } @@ -170,7 +170,7 @@ HWTEST_F(MiniHiChainAuthConnectorTest, ImportCredential_002, testing::ext::TestS std::shared_ptr minHiChain = std::make_shared(); JsonObject jsonObject; jsonObject["userId"] = 123456789; - std::string reqJsonStr = SafetyDump(jsonObject); + std::string reqJsonStr = jsonObject.Dump(); std::string returnJsonStr; int32_t ret = minHiChain->ImportCredential(reqJsonStr, returnJsonStr); EXPECT_EQ(ret, ERR_DM_HICHAIN_REGISTER_CALLBACK); diff --git a/test/commonunittest/UTTest_pin_auth.cpp b/test/commonunittest/UTTest_pin_auth.cpp index 3f5c47ef2..bb9bb20e7 100644 --- a/test/commonunittest/UTTest_pin_auth.cpp +++ b/test/commonunittest/UTTest_pin_auth.cpp @@ -74,7 +74,7 @@ HWTEST_F(PinAuthTest, ShowAuthInfo_002, testing::ext::TestSize.Level0) std::shared_ptr pinAuth = std::make_shared(); JsonObject jsonObject; jsonObject[PIN_TOKEN] = 123456; - std::string authToken = SafetyDump(jsonObject); + std::string authToken = jsonObject.Dump(); int32_t ret = pinAuth->ShowAuthInfo(authToken, authManager); ASSERT_EQ(ret, ERR_DM_FAILED); } @@ -90,7 +90,7 @@ HWTEST_F(PinAuthTest, ShowAuthInfo_003, testing::ext::TestSize.Level0) std::shared_ptr pinAuth = std::make_shared(); JsonObject jsonObject; jsonObject[PIN_CODE_KEY] = 123456; - std::string authToken = SafetyDump(jsonObject); + std::string authToken = jsonObject.Dump(); int32_t ret = pinAuth->ShowAuthInfo(authToken, nullptr); ASSERT_EQ(ret, ERR_DM_FAILED); } @@ -106,7 +106,7 @@ HWTEST_F(PinAuthTest, ShowAuthInfo_004, testing::ext::TestSize.Level0) std::shared_ptr pinAuth = std::make_shared(); JsonObject jsonObject; jsonObject[PIN_CODE_KEY] = 123456; - std::string authToken = SafetyDump(jsonObject); + std::string authToken = jsonObject.Dump(); int32_t ret = pinAuth->ShowAuthInfo(authToken, authManager); ASSERT_EQ(ret, ERR_DM_FAILED); } diff --git a/test/servicesfuzztest/authconfirm_fuzzer/auth_confirm_fuzzer.cpp b/test/servicesfuzztest/authconfirm_fuzzer/auth_confirm_fuzzer.cpp index 0571eab22..c9000432b 100644 --- a/test/servicesfuzztest/authconfirm_fuzzer/auth_confirm_fuzzer.cpp +++ b/test/servicesfuzztest/authconfirm_fuzzer/auth_confirm_fuzzer.cpp @@ -32,67 +32,132 @@ namespace OHOS { namespace DistributedHardware { -namespace { -std::shared_ptr authSrcConfirmState_ = std::make_shared(); -std::shared_ptr authSinkConfirmState_ = std::make_shared(); -std::shared_ptr authSinkStatePinAuthComm_ = std::make_shared(); -std::shared_ptr softbusConnector = std::make_shared(); -std::shared_ptr listener = std::make_shared(); -std::shared_ptr hiChainAuthConnector = std::make_shared(); -std::shared_ptr hiChainConnector = std::make_shared(); -std::shared_ptr authManager = std::make_shared(softbusConnector, hiChainConnector, - listener, hiChainAuthConnector); -std::shared_ptr context_ = authManager->GetAuthContext(); -std::shared_ptr authSrcPinAuthStartState_ = std::make_shared(); -std::shared_ptr authSinkPinAuthStartState_ = std::make_shared(); -std::shared_ptr authSrcPinAuthMsgNegotiateState_ = - std::make_shared(); -std::shared_ptr authSinkPinAuthMsgNegotiateState_ = - std::make_shared(); -std::shared_ptr authSinkPinAuthDoneState_ = std::make_shared(); -std::shared_ptr authSrcPinAuthDoneState_ = std::make_shared(); -std::shared_ptr authSrcPinNegotiateStartState_ = - std::make_shared(); -std::shared_ptr authSrcPinInputState_ = std::make_shared(); -std::shared_ptr authSinkPinNegotiateStartState_ = - std::make_shared(); -std::shared_ptr authSinkPinDisplayState_ = std::make_shared(); -std::shared_ptr authSrcReverseUltrasonicStartState_ = - std::make_shared(); -std::shared_ptr authSrcReverseUltrasonicDoneState_ = - std::make_shared(); -std::shared_ptr authSrcForwardUltrasonicStartState_ = - std::make_shared(); -std::shared_ptr authSrcForwardUltrasonicDoneState_ = - std::make_shared(); -std::shared_ptr authSinkReverseUltrasonicStartState_ = - std::make_shared(); -std::shared_ptr authSinkReverseUltrasonicDoneState_ = - std::make_shared(); -std::shared_ptr authSinkForwardUltrasonicStartState_ = - std::make_shared(); -std::shared_ptr authSinkForwardUltrasonicDoneState_ = - std::make_shared(); -std::shared_ptr authSrcCredentialAuthNegotiateState_ = - std::make_shared(); -std::shared_ptr authSrcCredentialAuthDoneState_ = - std::make_shared(); -std::shared_ptr authSinkCredentialAuthStartState_ = - std::make_shared(); -std::shared_ptr authSinkCredentialAuthNegotiateState_ = - std::make_shared(); -std::shared_ptr authSrcCredentialExchangeState_ = - std::make_shared(); -std::shared_ptr authSinkCredentialExchangeState_ = - std::make_shared(); -std::shared_ptr authSrcCredentialAuthStartState_ = - std::make_shared(); -std::shared_ptr authSrcStartState_ = std::make_shared(); -std::shared_ptr authSrcNegotiateStateMachine_ = - std::make_shared(); -std::shared_ptr authSinkNegotiateStateMachine_ = - std::make_shared(); -} + +class FuzzTestContext { +public: + FuzzTestContext() + { + softbusConnector = std::make_shared(); + listener = std::make_shared(); + hiChainAuthConnector = std::make_shared(); + hiChainConnector = std::make_shared(); + authManager = std::make_shared( + softbusConnector, hiChainConnector, listener, hiChainAuthConnector); + context_ = authManager->GetAuthContext(); + + // 初始化状态机相关对象 + authSrcConfirmState_ = std::make_shared(); + authSinkConfirmState_ = std::make_shared(); + authSinkStatePinAuthComm_ = std::make_shared(); + authSrcPinAuthStartState_ = std::make_shared(); + authSinkPinAuthStartState_ = std::make_shared(); + authSrcPinAuthMsgNegotiateState_ = std::make_shared(); + authSinkPinAuthMsgNegotiateState_ = std::make_shared(); + authSinkPinAuthDoneState_ = std::make_shared(); + authSrcPinAuthDoneState_ = std::make_shared(); + authSrcPinNegotiateStartState_ = std::make_shared(); + authSrcPinInputState_ = std::make_shared(); + authSinkPinNegotiateStartState_ = std::make_shared(); + authSinkPinDisplayState_ = std::make_shared(); + authSrcReverseUltrasonicStartState_ = std::make_shared(); + authSrcReverseUltrasonicDoneState_ = std::make_shared(); + authSrcForwardUltrasonicStartState_ = std::make_shared(); + authSrcForwardUltrasonicDoneState_ = std::make_shared(); + authSinkReverseUltrasonicStartState_ = std::make_shared(); + authSinkReverseUltrasonicDoneState_ = std::make_shared(); + authSinkForwardUltrasonicStartState_ = std::make_shared(); + authSinkForwardUltrasonicDoneState_ = std::make_shared(); + authSrcCredentialAuthNegotiateState_ = std::make_shared(); + authSrcCredentialAuthDoneState_ = std::make_shared(); + authSinkCredentialAuthStartState_ = std::make_shared(); + authSinkCredentialAuthNegotiateState_ = std::make_shared(); + authSrcCredentialExchangeState_ = std::make_shared(); + authSinkCredentialExchangeState_ = std::make_shared(); + authSrcCredentialAuthStartState_ = std::make_shared(); + authSrcStartState_ = std::make_shared(); + authSrcNegotiateStateMachine_ = std::make_shared(); + authSinkNegotiateStateMachine_ = std::make_shared(); + } + + ~FuzzTestContext() + { + authSrcNegotiateStateMachine_.reset(); + authSinkNegotiateStateMachine_.reset(); + + authSrcConfirmState_.reset(); + authSinkConfirmState_.reset(); + authSinkStatePinAuthComm_.reset(); + authSrcPinAuthStartState_.reset(); + authSinkPinAuthStartState_.reset(); + authSrcPinAuthMsgNegotiateState_.reset(); + authSinkPinAuthMsgNegotiateState_.reset(); + authSinkPinAuthDoneState_.reset(); + authSrcPinAuthDoneState_.reset(); + authSrcPinNegotiateStartState_.reset(); + authSrcPinInputState_.reset(); + authSinkPinNegotiateStartState_.reset(); + authSinkPinDisplayState_.reset(); + authSrcReverseUltrasonicStartState_.reset(); + authSrcReverseUltrasonicDoneState_.reset(); + authSrcForwardUltrasonicStartState_.reset(); + authSrcForwardUltrasonicDoneState_.reset(); + authSinkReverseUltrasonicStartState_.reset(); + authSinkReverseUltrasonicDoneState_.reset(); + authSinkForwardUltrasonicStartState_.reset(); + authSinkForwardUltrasonicDoneState_.reset(); + authSrcCredentialAuthNegotiateState_.reset(); + authSrcCredentialAuthDoneState_.reset(); + authSinkCredentialAuthStartState_.reset(); + authSinkCredentialAuthNegotiateState_.reset(); + authSrcCredentialExchangeState_.reset(); + authSinkCredentialExchangeState_.reset(); + authSrcCredentialAuthStartState_.reset(); + authSrcStartState_.reset(); + context_.reset(); + authManager.reset(); + } + +public: + std::shared_ptr softbusConnector; + std::shared_ptr listener; + std::shared_ptr hiChainAuthConnector; + std::shared_ptr hiChainConnector; + std::shared_ptr authManager; + std::shared_ptr context_; + + std::shared_ptr authSrcConfirmState_; + std::shared_ptr authSinkConfirmState_; + std::shared_ptr authSinkStatePinAuthComm_; + std::shared_ptr authSrcPinAuthStartState_; + std::shared_ptr authSinkPinAuthStartState_; + std::shared_ptr authSrcPinAuthMsgNegotiateState_; + std::shared_ptr authSinkPinAuthMsgNegotiateState_; + std::shared_ptr authSinkPinAuthDoneState_; + std::shared_ptr authSrcPinAuthDoneState_; + std::shared_ptr authSrcPinNegotiateStartState_; + std::shared_ptr authSrcPinInputState_; + std::shared_ptr authSinkPinNegotiateStartState_; + std::shared_ptr authSinkPinDisplayState_; + std::shared_ptr authSrcReverseUltrasonicStartState_; + std::shared_ptr authSrcReverseUltrasonicDoneState_; + std::shared_ptr authSrcForwardUltrasonicStartState_; + std::shared_ptr authSrcForwardUltrasonicDoneState_; + std::shared_ptr authSinkReverseUltrasonicStartState_; + std::shared_ptr authSinkReverseUltrasonicDoneState_; + std::shared_ptr authSinkForwardUltrasonicStartState_; + std::shared_ptr authSinkForwardUltrasonicDoneState_; + std::shared_ptr authSrcCredentialAuthNegotiateState_; + std::shared_ptr authSrcCredentialAuthDoneState_; + std::shared_ptr authSinkCredentialAuthStartState_; + std::shared_ptr authSinkCredentialAuthNegotiateState_; + std::shared_ptr authSrcCredentialExchangeState_; + std::shared_ptr authSinkCredentialExchangeState_; + std::shared_ptr authSrcCredentialAuthStartState_; + std::shared_ptr authSrcStartState_; + std::shared_ptr authSrcNegotiateStateMachine_; + std::shared_ptr authSinkNegotiateStateMachine_; +}; + void GenerateStrings(std::vector &strings, FuzzedDataProvider &fdp) { @@ -121,125 +186,122 @@ void GenerateJsonObject(JsonObject &jsonObject, FuzzedDataProvider &fdp) jsonObject[DM_BUSINESS_ID] = fdp.ConsumeRandomLengthString(); } -void ActionFuzzTest() +void ActionFuzzTest(FuzzTestContext &ctx) { - authSrcPinAuthStartState_->Action(context_); - authSinkPinAuthStartState_->Action(context_); - authSrcPinAuthMsgNegotiateState_->Action(context_); - authSinkPinAuthMsgNegotiateState_->Action(context_); - authSinkPinAuthDoneState_->Action(context_); - authSrcPinAuthDoneState_->Action(context_); - authSrcPinNegotiateStartState_->Action(context_); - authSinkPinNegotiateStartState_->Action(context_); - authSinkPinDisplayState_->Action(context_); - authSrcReverseUltrasonicStartState_->Action(context_); - authSrcReverseUltrasonicDoneState_->Action(context_); - authSrcForwardUltrasonicStartState_->Action(context_); - authSrcForwardUltrasonicDoneState_->Action(context_); - authSinkReverseUltrasonicStartState_->Action(context_); - authSinkReverseUltrasonicDoneState_->Action(context_); - authSinkForwardUltrasonicStartState_->Action(context_); - authSinkForwardUltrasonicDoneState_->Action(context_); - authSrcCredentialAuthNegotiateState_->Action(context_); - authSrcCredentialAuthDoneState_->Action(context_); - authSinkCredentialAuthStartState_->Action(context_); - authSinkCredentialAuthNegotiateState_->Action(context_); - authSrcCredentialExchangeState_->Action(context_); - authSinkCredentialExchangeState_->Action(context_); - authSrcCredentialAuthStartState_->Action(context_); - authSrcConfirmState_->Action(context_); - authSinkConfirmState_->Action(context_); - authSrcStartState_->Action(context_); - authSrcNegotiateStateMachine_->Action(context_); - authSinkNegotiateStateMachine_->Action(context_); + ctx.authSrcPinAuthStartState_->Action(ctx.context_); + ctx.authSinkPinAuthStartState_->Action(ctx.context_); + ctx.authSrcPinAuthMsgNegotiateState_->Action(ctx.context_); + ctx.authSinkPinAuthMsgNegotiateState_->Action(ctx.context_); + ctx.authSinkPinAuthDoneState_->Action(ctx.context_); + ctx.authSrcPinAuthDoneState_->Action(ctx.context_); + ctx.authSrcPinNegotiateStartState_->Action(ctx.context_); + ctx.authSinkPinNegotiateStartState_->Action(ctx.context_); + ctx.authSinkPinDisplayState_->Action(ctx.context_); + ctx.authSrcReverseUltrasonicStartState_->Action(ctx.context_); + ctx.authSrcReverseUltrasonicDoneState_->Action(ctx.context_); + ctx.authSrcForwardUltrasonicStartState_->Action(ctx.context_); + ctx.authSrcForwardUltrasonicDoneState_->Action(ctx.context_); + ctx.authSinkReverseUltrasonicStartState_->Action(ctx.context_); + ctx.authSinkReverseUltrasonicDoneState_->Action(ctx.context_); + ctx.authSinkForwardUltrasonicStartState_->Action(ctx.context_); + ctx.authSinkForwardUltrasonicDoneState_->Action(ctx.context_); + ctx.authSrcCredentialAuthNegotiateState_->Action(ctx.context_); + ctx.authSrcCredentialAuthDoneState_->Action(ctx.context_); + ctx.authSinkCredentialAuthStartState_->Action(ctx.context_); + ctx.authSinkCredentialAuthNegotiateState_->Action(ctx.context_); + ctx.authSrcCredentialExchangeState_->Action(ctx.context_); + ctx.authSinkCredentialExchangeState_->Action(ctx.context_); + ctx.authSrcCredentialAuthStartState_->Action(ctx.context_); + ctx.authSrcConfirmState_->Action(ctx.context_); + ctx.authSinkConfirmState_->Action(ctx.context_); + ctx.authSrcStartState_->Action(ctx.context_); + ctx.authSrcNegotiateStateMachine_->Action(ctx.context_); + ctx.authSinkNegotiateStateMachine_->Action(ctx.context_); } -void AuthConfirmFuzzTestNext(JsonObject &jsonObject, FuzzedDataProvider &fdp) +void AuthConfirmFuzzTestNext(FuzzTestContext &ctx, JsonObject &jsonObject, FuzzedDataProvider &fdp) { DistributedDeviceProfile::Accesser accesser; DistributedDeviceProfile::Accessee accessee; accesser.SetAccesserExtraData(fdp.ConsumeRandomLengthString()); accessee.SetAccesseeExtraData(fdp.ConsumeRandomLengthString()); - authSrcConfirmState_->NegotiateCredential(context_, jsonObject); - authSrcConfirmState_->NegotiateAcl(context_, jsonObject); - authSrcConfirmState_->GetIdenticalCredentialInfo(context_, jsonObject); - authSrcConfirmState_->GetShareCredentialInfo(context_, jsonObject); - authSrcConfirmState_->GetP2PCredentialInfo(context_, jsonObject); - authSinkConfirmState_->CreateProxyData(context_, jsonObject); - authSinkConfirmState_->NegotiateCredential(context_, jsonObject); - authSinkConfirmState_->NegotiateAcl(context_, jsonObject); - authSinkNegotiateStateMachine_->GetIdenticalCredentialInfo(context_, jsonObject); - authSinkNegotiateStateMachine_->GetShareCredentialInfo(context_, jsonObject); - authSinkNegotiateStateMachine_->GetP2PCredentialInfo(context_, jsonObject); - authSrcConfirmState_->GetCustomDescBySinkLanguage(context_); - authSinkConfirmState_->ShowConfigDialog(context_); - authSinkConfirmState_->ReadServiceInfo(context_); - authSinkConfirmState_->ProcessBindAuthorize(context_); - authSinkConfirmState_->ProcessNoBindAuthorize(context_); - authSinkStatePinAuthComm_->IsAuthCodeReady(context_); - authSinkStatePinAuthComm_->GeneratePincode(context_); - authSinkStatePinAuthComm_->ShowAuthInfoDialog(context_); - authSinkNegotiateStateMachine_->RespQueryAcceseeIds(context_); - authSinkNegotiateStateMachine_->ProcRespNegotiate5_1_0(context_); - authSrcConfirmState_->IdenticalAccountAclCompare(context_, accesser, accessee); - authSrcConfirmState_->ShareAclCompare(context_, accesser, accessee); - authSrcConfirmState_->Point2PointAclCompare(context_, accesser, accessee); - authSrcConfirmState_->LnnAclCompare(context_, accesser, accessee); - authSinkNegotiateStateMachine_->IdenticalAccountAclCompare(context_, accesser, accessee); - authSinkNegotiateStateMachine_->ShareAclCompare(context_, accesser, accessee); - authSinkNegotiateStateMachine_->Point2PointAclCompare(context_, accesser, accessee); - authSinkNegotiateStateMachine_->LnnAclCompare(context_, accesser, accessee); - authSrcPinInputState_->ShowStartAuthDialog(context_); - authSrcPinInputState_->Action(context_); - context_->importAuthCode = "123456"; - context_->importPkgName = "pkgName"; - authSinkStatePinAuthComm_->IsAuthCodeReady(context_); - authSinkStatePinAuthComm_->IsPinCodeValid(context_->importAuthCode); + ctx.authSrcConfirmState_->NegotiateCredential(ctx.context_, jsonObject); + ctx.authSrcConfirmState_->NegotiateAcl(ctx.context_, jsonObject); + ctx.authSrcConfirmState_->GetIdenticalCredentialInfo(ctx.context_, jsonObject); + ctx.authSrcConfirmState_->GetShareCredentialInfo(ctx.context_, jsonObject); + ctx.authSrcConfirmState_->GetP2PCredentialInfo(ctx.context_, jsonObject); + ctx.authSinkConfirmState_->CreateProxyData(ctx.context_, jsonObject); + ctx.authSinkConfirmState_->NegotiateCredential(ctx.context_, jsonObject); + ctx.authSinkConfirmState_->NegotiateAcl(ctx.context_, jsonObject); + ctx.authSinkNegotiateStateMachine_->GetIdenticalCredentialInfo(ctx.context_, jsonObject); + ctx.authSinkNegotiateStateMachine_->GetShareCredentialInfo(ctx.context_, jsonObject); + ctx.authSinkNegotiateStateMachine_->GetP2PCredentialInfo(ctx.context_, jsonObject); + ctx.authSrcConfirmState_->GetCustomDescBySinkLanguage(ctx.context_); + ctx.authSinkConfirmState_->ShowConfigDialog(ctx.context_); + ctx.authSinkConfirmState_->ReadServiceInfo(ctx.context_); + ctx.authSinkConfirmState_->ProcessBindAuthorize(ctx.context_); + ctx.authSinkConfirmState_->ProcessNoBindAuthorize(ctx.context_); + ctx.authSinkStatePinAuthComm_->IsAuthCodeReady(ctx.context_); + ctx.authSinkStatePinAuthComm_->GeneratePincode(ctx.context_); + ctx.authSinkStatePinAuthComm_->ShowAuthInfoDialog(ctx.context_); + ctx.authSinkNegotiateStateMachine_->RespQueryAcceseeIds(ctx.context_); + ctx.authSinkNegotiateStateMachine_->ProcRespNegotiate5_1_0(ctx.context_); + ctx.authSrcConfirmState_->IdenticalAccountAclCompare(ctx.context_, accesser, accessee); + ctx.authSrcConfirmState_->ShareAclCompare(ctx.context_, accesser, accessee); + ctx.authSrcConfirmState_->Point2PointAclCompare(ctx.context_, accesser, accessee); + ctx.authSrcConfirmState_->LnnAclCompare(ctx.context_, accesser, accessee); + ctx.authSinkNegotiateStateMachine_->IdenticalAccountAclCompare(ctx.context_, accesser, accessee); + ctx.authSinkNegotiateStateMachine_->ShareAclCompare(ctx.context_, accesser, accessee); + ctx.authSinkNegotiateStateMachine_->Point2PointAclCompare(ctx.context_, accesser, accessee); + ctx.authSinkNegotiateStateMachine_->LnnAclCompare(ctx.context_, accesser, accessee); + ctx.authSrcPinInputState_->ShowStartAuthDialog(ctx.context_); + ctx.authSrcPinInputState_->Action(ctx.context_); + ctx.context_->importAuthCode = "123456"; + ctx.context_->importPkgName = "pkgName"; + ctx.authSinkStatePinAuthComm_->IsAuthCodeReady(ctx.context_); + ctx.authSinkStatePinAuthComm_->IsPinCodeValid(ctx.context_->importAuthCode); } -void AuthConfirmFuzzTestThird(FuzzedDataProvider &fdp) +void AuthConfirmFuzzTestThird(FuzzTestContext &ctx, FuzzedDataProvider &fdp) { std::string businessId = fdp.ConsumeRandomLengthString(); std::string businessValue = fdp.ConsumeRandomLengthString(); std::string authorizeInfo = fdp.ConsumeRandomLengthString(); std::vector deleteCredInfo; DistributedDeviceProfile::AccessControlProfile acl; - authSinkNegotiateStateMachine_->IsAntiDisturbanceMode(businessId); - authSinkNegotiateStateMachine_->IsAntiDisturbanceMode(""); - authSinkNegotiateStateMachine_->ParseAndCheckAntiDisturbanceMode(businessId, businessValue); + ctx.authSinkNegotiateStateMachine_->IsAntiDisturbanceMode(businessId); + ctx.authSinkNegotiateStateMachine_->IsAntiDisturbanceMode(""); + ctx.authSinkNegotiateStateMachine_->ParseAndCheckAntiDisturbanceMode(businessId, businessValue); businessId = "test_business_id"; businessValue = "{\"business_id\":\"test_business_id\",\"is_in_anti_disturbance_mode\":true}"; - authSinkNegotiateStateMachine_->ParseAndCheckAntiDisturbanceMode(businessId, businessValue); - authSrcNegotiateStateMachine_->GetStateType(); - authSrcPinAuthStartState_->GetStateType(); - authSinkPinAuthDoneState_->GetStateType(); - authSrcReverseUltrasonicStartState_->GetStateType(); - authSrcForwardUltrasonicStartState_->GetStateType(); - authSinkReverseUltrasonicStartState_->GetStateType(); - authSinkForwardUltrasonicDoneState_->GetStateType(); - authSrcPinNegotiateStartState_->ProcessCredAuth(context_); + ctx.authSinkNegotiateStateMachine_->ParseAndCheckAntiDisturbanceMode(businessId, businessValue); + ctx.authSrcNegotiateStateMachine_->GetStateType(); + ctx.authSrcPinAuthStartState_->GetStateType(); + ctx.authSinkPinAuthDoneState_->GetStateType(); + ctx.authSrcReverseUltrasonicStartState_->GetStateType(); + ctx.authSrcForwardUltrasonicStartState_->GetStateType(); + ctx.authSinkReverseUltrasonicStartState_->GetStateType(); + ctx.authSinkForwardUltrasonicDoneState_->GetStateType(); + ctx.authSrcPinNegotiateStartState_->ProcessCredAuth(ctx.context_); int32_t credType = fdp.ConsumeIntegral(); - authSrcPinNegotiateStartState_->GetCredIdByCredType(context_, credType); - context_->IsProxyBind = true; - authSrcConfirmState_->NegotiateProxyCredential(context_); - authSrcConfirmState_->NegotiateProxyAcl(context_); - authSrcConfirmState_->ResetBindLevel(context_); - authSinkConfirmState_->GetBundleLabel(context_); - authSinkConfirmState_->NegotiateProxyAcl(context_); - authSinkConfirmState_->ProcessUserAuthorize(context_); - authSinkConfirmState_->ProcessServerAuthorize(context_); - authSinkConfirmState_->NegotiateProxyCredential(context_); - authSrcConfirmState_->GetSrcProxyCredTypeForP2P(context_, deleteCredInfo); - authSinkConfirmState_->ProcessUserOption(context_, authorizeInfo); - authSrcConfirmState_->GetSrcProxyAclInfoForP2P(context_, acl); + ctx.authSrcPinNegotiateStartState_->GetCredIdByCredType(ctx.context_, credType); + ctx.context_->IsProxyBind = true; + ctx.authSrcConfirmState_->NegotiateProxyCredential(ctx.context_); + ctx.authSrcConfirmState_->NegotiateProxyAcl(ctx.context_); + ctx.authSrcConfirmState_->ResetBindLevel(ctx.context_); + ctx.authSinkConfirmState_->GetBundleLabel(ctx.context_); + ctx.authSinkConfirmState_->NegotiateProxyAcl(ctx.context_); + ctx.authSinkConfirmState_->ProcessUserAuthorize(ctx.context_); + ctx.authSinkConfirmState_->ProcessServerAuthorize(ctx.context_); + ctx.authSinkConfirmState_->NegotiateProxyCredential(ctx.context_); + ctx.authSrcConfirmState_->GetSrcProxyCredTypeForP2P(ctx.context_, deleteCredInfo); + ctx.authSinkConfirmState_->ProcessUserOption(ctx.context_, authorizeInfo); + ctx.authSrcConfirmState_->GetSrcProxyAclInfoForP2P(ctx.context_, acl); } -void AuthConfirmFuzzTest(const uint8_t* data, size_t size) +void SetupContextAndGenerateData(FuzzTestContext &ctx, FuzzedDataProvider &fdp, JsonObject &jsonObject, + JsonObject &jsonObjectTwo, JsonObject &jsonObjectThree) { - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - FuzzedDataProvider fdp(data, size); uint32_t bindType = fdp.ConsumeIntegralInRange(0, 1024); int32_t credType = fdp.ConsumeIntegral(); int32_t numpin = fdp.ConsumeIntegral(); @@ -253,37 +315,52 @@ void AuthConfirmFuzzTest(const uint8_t* data, size_t size) acl.SetExtraData(fdp.ConsumeRandomLengthString()); accesser.SetAccesserExtraData(fdp.ConsumeRandomLengthString()); accessee.SetAccesseeExtraData(fdp.ConsumeRandomLengthString()); + std::vector deleteCredInfo; + GenerateStrings(deleteCredInfo, fdp); + ctx.context_->extraInfo = fdp.ConsumeRandomLengthString(); + ctx.authSrcConfirmState_->GetSrcAclInfoForP2P(ctx.context_, acl, jsonObject, jsonObjectTwo); + ctx.authSrcConfirmState_->CheckCredIdInAcl(ctx.context_, acl, jsonObject, bindType); + ctx.authSrcConfirmState_->CheckCredIdInAclForP2P(ctx.context_, credId, acl, jsonObjectTwo, bindType, checkResult); + ctx.authSrcConfirmState_->GetSrcCredType(ctx.context_, jsonObject, jsonObjectTwo, jsonObjectThree); + ctx.authSrcConfirmState_->GetSrcCredTypeForP2P(ctx.context_, jsonObject, jsonObjectTwo, jsonObjectThree, credType, + deleteCredInfo); + ctx.authSinkConfirmState_->MatchFallBackCandidateList(ctx.context_, DmAuthType::AUTH_TYPE_PIN); + ctx.authSinkConfirmState_->GetCredIdByCredType(ctx.context_, credType); + ctx.authSinkStatePinAuthComm_->HandleSessionHeartbeat(ctx.context_, name); + ctx.authSinkStatePinAuthComm_->IsPinCodeValid(numpin); + ctx.authSinkStatePinAuthComm_->IsPinCodeValid(strpin); + ctx.authSinkNegotiateStateMachine_->GetSinkAclInfo(ctx.context_, jsonObject, jsonObjectTwo); + ctx.authSinkNegotiateStateMachine_->GetSinkAclInfoForP2P(ctx.context_, acl, jsonObject, jsonObjectTwo); + ctx.authSinkNegotiateStateMachine_->CheckCredIdInAcl(ctx.context_, acl, jsonObject, bindType); + ctx.authSinkNegotiateStateMachine_->CheckCredIdInAclForP2P(ctx.context_, credId, acl, jsonObject, bindType, + checkResult); + ctx.authSinkNegotiateStateMachine_->GetSinkCredType(ctx.context_, jsonObject, jsonObjectTwo, jsonObjectThree); + ctx.authSinkNegotiateStateMachine_->GetSinkCredTypeForP2P(ctx.context_, jsonObject, jsonObjectTwo, jsonObjectThree, + credType, deleteCredInfo); + ctx.authSrcConfirmState_->GetSrcAclInfo(ctx.context_, jsonObject, jsonObjectTwo); +} + +void AuthConfirmFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + + FuzzTestContext ctx; + FuzzedDataProvider fdp(data, size); + JsonObject jsonObject; JsonObject jsonObjectTwo; JsonObject jsonObjectThree; GenerateJsonObject(jsonObject, fdp); GenerateJsonObject(jsonObjectTwo, fdp); GenerateJsonObject(jsonObjectThree, fdp); - std::vector deleteCredInfo; - GenerateStrings(deleteCredInfo, fdp); - context_->extraInfo = fdp.ConsumeRandomLengthString(); - authSrcConfirmState_->GetSrcAclInfoForP2P(context_, acl, jsonObject, jsonObjectTwo); - authSrcConfirmState_->CheckCredIdInAcl(context_, acl, jsonObject, bindType); - authSrcConfirmState_->CheckCredIdInAclForP2P(context_, credId, acl, jsonObjectTwo, bindType, checkResult); - authSrcConfirmState_->GetSrcCredType(context_, jsonObject, jsonObjectTwo, jsonObjectThree); - authSrcConfirmState_->GetSrcCredTypeForP2P(context_, jsonObject, jsonObjectTwo, jsonObjectThree, credType, - deleteCredInfo); - authSinkConfirmState_->MatchFallBackCandidateList(context_, DmAuthType::AUTH_TYPE_PIN); - authSinkConfirmState_->GetCredIdByCredType(context_, credType); - authSinkStatePinAuthComm_->HandleSessionHeartbeat(context_, name); - authSinkStatePinAuthComm_->IsPinCodeValid(numpin); - authSinkStatePinAuthComm_->IsPinCodeValid(strpin); - authSinkNegotiateStateMachine_->GetSinkAclInfo(context_, jsonObject, jsonObjectTwo); - authSinkNegotiateStateMachine_->GetSinkAclInfoForP2P(context_, acl, jsonObject, jsonObjectTwo); - authSinkNegotiateStateMachine_->CheckCredIdInAcl(context_, acl, jsonObject, bindType); - authSinkNegotiateStateMachine_->CheckCredIdInAclForP2P(context_, credId, acl, jsonObject, bindType, checkResult); - authSinkNegotiateStateMachine_->GetSinkCredType(context_, jsonObject, jsonObjectTwo, jsonObjectThree); - authSinkNegotiateStateMachine_->GetSinkCredTypeForP2P(context_, jsonObject, jsonObjectTwo, jsonObjectThree, - credType, deleteCredInfo); - authSrcConfirmState_->GetSrcAclInfo(context_, jsonObject, jsonObjectTwo); - ActionFuzzTest(); - AuthConfirmFuzzTestNext(jsonObject, fdp); - AuthConfirmFuzzTestThird(fdp); + + SetupContextAndGenerateData(ctx, fdp, jsonObject, jsonObjectTwo, jsonObjectThree); + + ActionFuzzTest(ctx); + AuthConfirmFuzzTestNext(ctx, jsonObject, fdp); + AuthConfirmFuzzTestThird(ctx, fdp); } } } diff --git a/test/softbusunittest/UTTest_mine_softbus_listener.cpp b/test/softbusunittest/UTTest_mine_softbus_listener.cpp index f8a6979c2..07efb7705 100644 --- a/test/softbusunittest/UTTest_mine_softbus_listener.cpp +++ b/test/softbusunittest/UTTest_mine_softbus_listener.cpp @@ -67,7 +67,7 @@ HWTEST_F(MineSoftbusListenerTest, RefreshSoftbusLNN_002, testing::ext::TestSize. JsonObject jsonObj; jsonObj["findDeviceMode"] = 4; string pkgName; - string searchJson = SafetyDump(jsonObj); + string searchJson = jsonObj.Dump(); DmSubscribeInfo dmSubscribeInfo; std::shared_ptr mineListener = std::make_shared(); int32_t ret = mineListener->RefreshSoftbusLNN(pkgName, searchJson, dmSubscribeInfo); @@ -145,7 +145,7 @@ HWTEST_F(MineSoftbusListenerTest, ParseSearchJson_002, testing::ext::TestSize.Le JsonObject jsonObj; jsonObj["findDeviceMode"] = static_cast(1); string pkgName; - string searchJson = SafetyDump(jsonObj); + string searchJson = jsonObj.Dump(); std::shared_ptr mineListener = std::make_shared(); int32_t ret = mineListener->ParseSearchJson(pkgName, searchJson, output, &outLen); EXPECT_EQ(ret, ERR_DM_FAILED); @@ -158,7 +158,7 @@ HWTEST_F(MineSoftbusListenerTest, ParseSearchJson_003, testing::ext::TestSize.Le JsonObject jsonObj; jsonObj["findDeviceMode"] = static_cast(2); string pkgName; - string searchJson = SafetyDump(jsonObj); + string searchJson = jsonObj.Dump(); std::shared_ptr mineListener = std::make_shared(); int32_t ret = mineListener->ParseSearchJson(pkgName, searchJson, output, &outLen); EXPECT_EQ(ret, ERR_DM_FAILED); @@ -171,7 +171,7 @@ HWTEST_F(MineSoftbusListenerTest, ParseSearchJson_004, testing::ext::TestSize.Le JsonObject jsonObj; jsonObj["findDeviceMode"] = static_cast(3); string pkgName; - string searchJson = SafetyDump(jsonObj); + string searchJson = jsonObj.Dump(); std::shared_ptr mineListener = std::make_shared(); int32_t ret = mineListener->ParseSearchJson(pkgName, searchJson, output, &outLen); EXPECT_EQ(ret, ERR_DM_FAILED); @@ -184,7 +184,7 @@ HWTEST_F(MineSoftbusListenerTest, ParseSearchJson_005, testing::ext::TestSize.Le JsonObject jsonObj; jsonObj["findDeviceMode"] = static_cast(4); string pkgName; - string searchJson = SafetyDump(jsonObj); + string searchJson = jsonObj.Dump(); std::shared_ptr mineListener = std::make_shared(); int32_t ret = mineListener->ParseSearchJson(pkgName, searchJson, output, &outLen); EXPECT_EQ(ret, DM_OK); diff --git a/test/softbusunittest/UTTest_softbus_session.cpp b/test/softbusunittest/UTTest_softbus_session.cpp index 3559e9d18..9892e61b8 100644 --- a/test/softbusunittest/UTTest_softbus_session.cpp +++ b/test/softbusunittest/UTTest_softbus_session.cpp @@ -107,7 +107,7 @@ HWTEST_F(SoftbusSessionTest, SendData_002, testing::ext::TestSize.Level1) JsonObject jsonObj; jsonObj[TAG_VER] = DM_ITF_VER; jsonObj[TAG_MSG_TYPE] = msgType; - std::string message = SafetyDump(jsonObj); + std::string message = jsonObj.Dump(); int32_t sessionId = 0; if (softbusSession == nullptr) { softbusSession = std::make_shared(); diff --git a/test/unittest/UTTest_auth_message_processor.cpp b/test/unittest/UTTest_auth_message_processor.cpp index 21fd2b8de..b07c58489 100644 --- a/test/unittest/UTTest_auth_message_processor.cpp +++ b/test/unittest/UTTest_auth_message_processor.cpp @@ -148,7 +148,7 @@ HWTEST_F(AuthMessageProcessorTest, CreateNegotiateMessage_001, testing::ext::Tes authManager->importPkgName_ = "hostPkgName"; authMessageProcessor->authMgr_ = authManager; authMessageProcessor->CreateNegotiateMessage(jsonObj); - std::string str1 = SafetyDump(jsonObj); + std::string str1 = jsonObj.Dump(); authMessageProcessor->cryptoAdapter_ = std::make_shared(); authMessageProcessor->authRequestContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE; authMessageProcessor->CreateNegotiateMessage(jsonObj); @@ -162,7 +162,7 @@ HWTEST_F(AuthMessageProcessorTest, CreateNegotiateMessage_001, testing::ext::Tes jsonObject[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply; jsonObject[TAG_LOCAL_DEVICE_ID] = authMessageProcessor->authResponseContext_->localDeviceId; jsonObject[TAG_HOST] = ""; - std::string str2 = SafetyDump(jsonObject); + std::string str2 = jsonObject.Dump(); ASSERT_NE(str1, str2); } @@ -188,8 +188,8 @@ HWTEST_F(AuthMessageProcessorTest, CreateSyncGroupMessage_001, testing::ext::Tes jsona[TAG_DEVICE_ID] = authMessageProcessor->authRequestContext_->deviceId; jsona[TAG_GROUPIDS] = authMessageProcessor->authRequestContext_->syncGroupList; authMessageProcessor->CreateSyncGroupMessage(jsonObj); - std::string str1 = SafetyDump(jsona); - std::string str2 = SafetyDump(jsonObj); + std::string str1 = jsona.Dump(); + std::string str2 = jsonObj.Dump(); ASSERT_EQ(str1, str2); } @@ -214,7 +214,7 @@ HWTEST_F(AuthMessageProcessorTest, CreateResponseAuthMessage_001, testing::ext:: JsonObject jsonB; jsonB[TAG_GROUP_ID] = "123456"; authMessageProcessor->authResponseContext_->groupId = - SafetyDump(jsonB); + jsonB.Dump(); authMessageProcessor->authResponseContext_->authToken = "123456"; authMessageProcessor->authResponseContext_->networkId = "11112222"; authMessageProcessor->authResponseContext_->requestId = 222222; @@ -228,8 +228,8 @@ HWTEST_F(AuthMessageProcessorTest, CreateResponseAuthMessage_001, testing::ext:: jsonA[TAG_GROUP_NAME] = authMessageProcessor->authResponseContext_->groupName; jsonA[TAG_AUTH_TOKEN] = authMessageProcessor->authResponseContext_->authToken; authMessageProcessor->CreateResponseAuthMessage(jsonObj); - std::string str1 = SafetyDump(jsonA); - std::string str2 = SafetyDump(jsonObj); + std::string str1 = jsonA.Dump(); + std::string str2 = jsonObj.Dump(); ASSERT_EQ(str1, str2); } @@ -252,8 +252,8 @@ HWTEST_F(AuthMessageProcessorTest, CreateResponseFinishMessage_001, testing::ext jsona[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply; jsona[TAG_AUTH_FINISH] = authMessageProcessor->authResponseContext_->isFinish; authMessageProcessor->CreateResponseFinishMessage(jsonObj); - std::string str1 = SafetyDump(jsona); - std::string str2 = SafetyDump(jsonObj); + std::string str1 = jsona.Dump(); + std::string str2 = jsonObj.Dump(); ASSERT_EQ(str1, str2); } diff --git a/test/unittest/UTTest_crypto_mgr.cpp b/test/unittest/UTTest_crypto_mgr.cpp index 27510007c..21fc22f33 100644 --- a/test/unittest/UTTest_crypto_mgr.cpp +++ b/test/unittest/UTTest_crypto_mgr.cpp @@ -42,7 +42,7 @@ HWTEST_F(CryptoMgrTest, EncryptAndDecryptMessage_001, testing::ext::TestSize.Lev JsonObject jsonObj; jsonObj[TAG_DEVICE_ID] = "51352xxxx"; jsonObj[TAG_CRYPTO_SUPPORT] = true; - std::string message = SafetyDump(jsonObj); + std::string message = jsonObj.Dump(); std::string encryptData; std::string decryptData; ret = cryptoMgr->EncryptMessage(message, encryptData); @@ -61,7 +61,7 @@ HWTEST_F(CryptoMgrTest, EncryptAndDecryptMessage_002, testing::ext::TestSize.Lev JsonObject jsonObj; jsonObj[TAG_DEVICE_ID] = "51352xxxx"; jsonObj[TAG_CRYPTO_SUPPORT] = true; - std::string message = SafetyDump(jsonObj); + std::string message = jsonObj.Dump(); std::string encryptData1; std::string encryptData2; std::string decryptData; @@ -115,7 +115,7 @@ HWTEST_F(CryptoMgrTest, EncryptAndDecryptMessage_005, testing::ext::TestSize.Lev JsonObject jsonObj; jsonObj[TAG_DEVICE_ID] = "51352xxxx"; jsonObj[TAG_CRYPTO_SUPPORT] = true; - std::string message = SafetyDump(jsonObj); + std::string message = jsonObj.Dump(); std::string encryptData; std::string decryptData; auto ret = cryptoMgr->EncryptMessage(message, encryptData); diff --git a/test/unittest/UTTest_dm_pin_holder.cpp b/test/unittest/UTTest_dm_pin_holder.cpp index c5c0a8f11..ebeb19395 100644 --- a/test/unittest/UTTest_dm_pin_holder.cpp +++ b/test/unittest/UTTest_dm_pin_holder.cpp @@ -470,7 +470,7 @@ HWTEST_F(DmPinHolderTest, ProcessCreateMsg_103, testing::ext::TestSize.Level1) std::shared_ptr listener = std::make_shared(); std::shared_ptr pinHolder = std::make_shared(listener); JsonObject jsonObject; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); pinHolder->ProcessCreateMsg(message); ASSERT_NE(pinHolder->timer_, nullptr); } @@ -481,7 +481,7 @@ HWTEST_F(DmPinHolderTest, ProcessCreateMsg_104, testing::ext::TestSize.Level1) std::shared_ptr pinHolder = std::make_shared(listener); JsonObject jsonObject; jsonObject[TAG_PIN_TYPE] = "TAG_PIN_TYPE"; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); pinHolder->ProcessCreateMsg(message); ASSERT_NE(pinHolder->timer_, nullptr); } @@ -493,7 +493,7 @@ HWTEST_F(DmPinHolderTest, ProcessCreateMsg_105, testing::ext::TestSize.Level1) JsonObject jsonObject; jsonObject[TAG_PIN_TYPE] = DmPinType::SUPER_SONIC; jsonObject[TAG_PAYLOAD] = DmPinType::SUPER_SONIC; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); pinHolder->ProcessCreateMsg(message); ASSERT_NE(pinHolder->timer_, nullptr); } @@ -503,7 +503,7 @@ HWTEST_F(DmPinHolderTest, ProcessCreateRespMsg_101, testing::ext::TestSize.Level std::shared_ptr listener = std::make_shared(); std::shared_ptr pinHolder = std::make_shared(listener); JsonObject jsonObject; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); pinHolder->ProcessCreateRespMsg(message); ASSERT_NE(pinHolder->timer_, nullptr); } @@ -514,7 +514,7 @@ HWTEST_F(DmPinHolderTest, ProcessCreateRespMsg_102, testing::ext::TestSize.Level std::shared_ptr pinHolder = std::make_shared(listener); JsonObject jsonObject; jsonObject[TAG_REPLY] = DmPinType::NUMBER_PIN_CODE; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); pinHolder->listener_ = nullptr; pinHolder->ProcessCreateRespMsg(message); ASSERT_NE(pinHolder->timer_, nullptr); @@ -526,7 +526,7 @@ HWTEST_F(DmPinHolderTest, ProcessCreateRespMsg_103, testing::ext::TestSize.Level std::shared_ptr pinHolder = std::make_shared(listener); JsonObject jsonObject; jsonObject[TAG_REPLY] = DmPinType::SUPER_SONIC; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); pinHolder->session_ = nullptr; pinHolder->ProcessCreateRespMsg(message); ASSERT_NE(pinHolder->timer_, nullptr); @@ -538,7 +538,7 @@ HWTEST_F(DmPinHolderTest, ProcessCreateRespMsg_104, testing::ext::TestSize.Level std::shared_ptr pinHolder = std::make_shared(listener); JsonObject jsonObject; jsonObject[TAG_REPLY] = DmPinType::NUMBER_PIN_CODE; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); pinHolder->session_ = nullptr; pinHolder->ProcessCreateRespMsg(message); ASSERT_NE(pinHolder->timer_, nullptr); @@ -569,7 +569,7 @@ HWTEST_F(DmPinHolderTest, ProcessDestroyMsg_103, testing::ext::TestSize.Level1) std::shared_ptr listener = std::make_shared(); std::shared_ptr pinHolder = std::make_shared(listener); JsonObject jsonObject; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); pinHolder->ProcessDestroyMsg(message); ASSERT_NE(pinHolder->timer_, nullptr); } @@ -580,7 +580,7 @@ HWTEST_F(DmPinHolderTest, ProcessDestroyMsg_104, testing::ext::TestSize.Level1) std::shared_ptr pinHolder = std::make_shared(listener); JsonObject jsonObject; jsonObject[TAG_PIN_TYPE] = "TAG_PIN_TYPE"; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); pinHolder->ProcessDestroyMsg(message); ASSERT_NE(pinHolder->timer_, nullptr); } @@ -592,7 +592,7 @@ HWTEST_F(DmPinHolderTest, ProcessDestroyMsg_105, testing::ext::TestSize.Level1) JsonObject jsonObject; jsonObject[TAG_PIN_TYPE] = DmPinType::SUPER_SONIC; jsonObject[TAG_PAYLOAD] = DmPinType::SUPER_SONIC; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); pinHolder->ProcessDestroyMsg(message); ASSERT_NE(pinHolder->timer_, nullptr); } @@ -614,7 +614,7 @@ HWTEST_F(DmPinHolderTest, OnDataReceived_101, testing::ext::TestSize.Level1) int32_t sessionId = 1; JsonObject jsonObject; jsonObject[TAG_MSG_TYPE] = MSG_TYPE_CREATE_PIN_HOLDER; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); pinHolder->OnDataReceived(sessionId, message); ASSERT_NE(pinHolder->timer_, nullptr); } @@ -626,7 +626,7 @@ HWTEST_F(DmPinHolderTest, OnDataReceived_102, testing::ext::TestSize.Level1) int32_t sessionId = 1; JsonObject jsonObject; jsonObject[TAG_MSG_TYPE] = MSG_TYPE_CREATE_PIN_HOLDER_RESP; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); pinHolder->OnDataReceived(sessionId, message); ASSERT_NE(pinHolder->timer_, nullptr); } @@ -638,7 +638,7 @@ HWTEST_F(DmPinHolderTest, OnDataReceived_103, testing::ext::TestSize.Level1) int32_t sessionId = 1; JsonObject jsonObject; jsonObject[TAG_MSG_TYPE] = MSG_TYPE_DESTROY_PIN_HOLDER; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); pinHolder->OnDataReceived(sessionId, message); ASSERT_NE(pinHolder->timer_, nullptr); } @@ -650,7 +650,7 @@ HWTEST_F(DmPinHolderTest, OnDataReceived_104, testing::ext::TestSize.Level1) int32_t sessionId = 1; JsonObject jsonObject; jsonObject[TAG_MSG_TYPE] = MSG_TYPE_DESTROY_PIN_HOLDER_RESP; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); pinHolder->OnDataReceived(sessionId, message); ASSERT_NE(pinHolder->timer_, nullptr); } @@ -663,7 +663,7 @@ HWTEST_F(DmPinHolderTest, OnDataReceived_105, testing::ext::TestSize.Level1) int32_t data = 300; JsonObject jsonObject; jsonObject[TAG_MSG_TYPE] = data; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); pinHolder->OnDataReceived(sessionId, message); ASSERT_NE(pinHolder->timer_, nullptr); } @@ -940,14 +940,14 @@ HWTEST_F(DmPinHolderTest, CreateMsgScene_101, testing::ext::TestSize.Level1) sourceJson[TAG_MSG_TYPE] = MSG_TYPE_CREATE_PIN_HOLDER; sourceJson[TAG_PIN_TYPE] = DmPinType::QR_CODE; sourceJson[TAG_PAYLOAD] = PAY_LOAD; - std::string sourceMessage = SafetyDump(sourceJson); + std::string sourceMessage = sourceJson.Dump(); JsonObject sinkJson; sinkJson[TAG_MSG_TYPE] = MSG_TYPE_CREATE_PIN_HOLDER_RESP; sinkJson[TAG_PIN_TYPE] = DmPinType::QR_CODE; sinkJson[TAG_PAYLOAD] = PAY_LOAD; sinkJson[TAG_REPLY] = REPLY_SUCCESS; - std::string sinkMessage = SafetyDump(sourceJson); + std::string sinkMessage = sinkJson.Dump(); std::shared_ptr listener = std::make_shared(); std::shared_ptr pinHolder = std::make_shared(listener); @@ -967,7 +967,7 @@ HWTEST_F(DmPinHolderTest, CreateRespMsgScene_101, testing::ext::TestSize.Level2) jsonObject[TAG_PIN_TYPE] = DmPinType::QR_CODE; jsonObject[TAG_PAYLOAD] = PAY_LOAD; jsonObject[TAG_REPLY] = REPLY_FAILED; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); std::shared_ptr listener = std::make_shared(); std::shared_ptr pinHolder = std::make_shared(listener); @@ -983,7 +983,7 @@ HWTEST_F(DmPinHolderTest, DestroyMsgScene_101, testing::ext::TestSize.Level1) jsonObject[TAG_MSG_TYPE] = MSG_TYPE_DESTROY_PIN_HOLDER; jsonObject[TAG_PIN_TYPE] = DmPinType::QR_CODE; jsonObject[TAG_PAYLOAD] = PAY_LOAD; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); std::shared_ptr listener = std::make_shared(); std::shared_ptr pinHolder = std::make_shared(listener); @@ -999,7 +999,7 @@ HWTEST_F(DmPinHolderTest, DestroyResMsgScene_101, testing::ext::TestSize.Level1) jsonObject[TAG_MSG_TYPE] = MSG_TYPE_DESTROY_PIN_HOLDER_RESP; jsonObject[TAG_PIN_TYPE] = DmPinType::QR_CODE; jsonObject[TAG_PAYLOAD] = PAY_LOAD; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); std::shared_ptr listener = std::make_shared(); std::shared_ptr pinHolder = std::make_shared(listener); @@ -1015,7 +1015,7 @@ HWTEST_F(DmPinHolderTest, ChangeMsgScene_101, testing::ext::TestSize.Level1) jsonObject[TAG_MSG_TYPE] = MSG_TYPE_PIN_HOLDER_CHANGE; jsonObject[TAG_PIN_TYPE] = DmPinType::QR_CODE; jsonObject[TAG_PAYLOAD] = PAY_LOAD; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); std::shared_ptr listener = std::make_shared(); std::shared_ptr pinHolder = std::make_shared(listener); @@ -1031,7 +1031,7 @@ HWTEST_F(DmPinHolderTest, ChangeRespMsgScene_101, testing::ext::TestSize.Level1) jsonObject[TAG_MSG_TYPE] = MSG_TYPE_PIN_HOLDER_CHANGE_RESP; jsonObject[TAG_PIN_TYPE] = DmPinType::QR_CODE; jsonObject[TAG_PAYLOAD] = PAY_LOAD; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); std::shared_ptr listener = std::make_shared(); std::shared_ptr pinHolder = std::make_shared(listener); @@ -1047,7 +1047,7 @@ HWTEST_F(DmPinHolderTest, CloseSessionMsgScene_101, testing::ext::TestSize.Level jsonObject[TAG_MSG_TYPE] = MSG_TYPE_PIN_CLOSE_SESSION; jsonObject[TAG_PIN_TYPE] = DmPinType::QR_CODE; jsonObject[TAG_PAYLOAD] = PAY_LOAD; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); std::shared_ptr listener = std::make_shared(); std::shared_ptr pinHolder = std::make_shared(listener); @@ -1251,7 +1251,7 @@ HWTEST_F(DmPinHolderTest, ProcessCloseSessionMsg_102, testing::ext::TestSize.Lev JsonObject jsonObject; jsonObject[TAG_PIN_TYPE] = DmPinType::SUPER_SONIC; jsonObject[TAG_PAYLOAD] = DmPinType::SUPER_SONIC; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); pinHolder->sinkState_ = SINK_CREATE; pinHolder->ProcessDestroyMsg(message); ASSERT_NE(pinHolder->timer_, nullptr); @@ -1290,7 +1290,7 @@ HWTEST_F(DmPinHolderTest, ProcessDestroyResMsg_102, testing::ext::TestSize.Level JsonObject jsonObject; std::shared_ptr listener = std::make_shared(); std::shared_ptr pinHolder = std::make_shared(listener); - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); jsonObject[TAG_REPLY] = DmPinType::NUMBER_PIN_CODE; pinHolder->ProcessDestroyResMsg(message); ASSERT_NE(pinHolder->timer_, nullptr); @@ -1301,7 +1301,7 @@ HWTEST_F(DmPinHolderTest, ProcessDestroyResMsg_103, testing::ext::TestSize.Level JsonObject jsonObject; std::shared_ptr listener = std::make_shared(); std::shared_ptr pinHolder = std::make_shared(listener); - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); jsonObject[TAG_REPLY] = DmPinType::NUMBER_PIN_CODE; pinHolder->session_ = nullptr; pinHolder->ProcessDestroyResMsg(message); @@ -1313,7 +1313,7 @@ HWTEST_F(DmPinHolderTest, ProcessDestroyResMsg_104, testing::ext::TestSize.Level JsonObject jsonObject; std::shared_ptr listener = std::make_shared(); std::shared_ptr pinHolder = std::make_shared(listener); - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); jsonObject[TAG_REPLY] = DmPinType::NUMBER_PIN_CODE; pinHolder->listener_ = nullptr; pinHolder->ProcessDestroyResMsg(message); diff --git a/test/unittest/UTTest_dp_inited_callback.cpp b/test/unittest/UTTest_dp_inited_callback.cpp index 534e2b4fa..4e5594999 100644 --- a/test/unittest/UTTest_dp_inited_callback.cpp +++ b/test/unittest/UTTest_dp_inited_callback.cpp @@ -73,7 +73,7 @@ HWTEST_F(DpInitedCallbackTest, PutAllTrustedDevices_001, testing::ext::TestSize. JsonObject jsonObject; jsonObject[PARAM_KEY_OS_VERSION] = "5.0.3"; jsonObject[PARAM_KEY_OS_TYPE] = 1; - std::string extraData = SafetyDump(jsonObject); + std::string extraData = jsonObject.Dump(); auto ret = CreateDmDeviceInfo(networkId, extraData, deviceInfo); ASSERT_TRUE(ret); @@ -172,7 +172,7 @@ HWTEST_F(DpInitedCallbackTest, PutAllTrustedDevices_005, testing::ext::TestSize. JsonObject jsonObject; jsonObject[PARAM_KEY_OS_VERSION] = 1; - std::string extraData = SafetyDump(jsonObject); + std::string extraData = jsonObject.Dump(); auto ret = CreateDmDeviceInfo(networkId, extraData, deviceInfo); ASSERT_TRUE(ret); @@ -206,7 +206,7 @@ HWTEST_F(DpInitedCallbackTest, PutAllTrustedDevices_006, testing::ext::TestSize. JsonObject jsonObject; jsonObject[PARAM_KEY_OS_VERSION] = "5.0.3"; jsonObject[PARAM_KEY_OS_TYPE] = "1"; - std::string extraData = SafetyDump(jsonObject); + std::string extraData = jsonObject.Dump(); auto ret = CreateDmDeviceInfo(networkId, extraData, deviceInfo); ASSERT_TRUE(ret); @@ -239,7 +239,7 @@ HWTEST_F(DpInitedCallbackTest, PutAllTrustedDevices_007, testing::ext::TestSize. JsonObject jsonObject; jsonObject[PARAM_KEY_OS_VERSION] = "5.0.3"; jsonObject[PARAM_KEY_OS_TYPE] = 1; - std::string extraData = SafetyDump(jsonObject); + std::string extraData = jsonObject.Dump(); auto ret = CreateDmDeviceInfo(networkId, extraData, deviceInfo); ASSERT_TRUE(ret); @@ -275,7 +275,7 @@ HWTEST_F(DpInitedCallbackTest, PutAllTrustedDevices_008, testing::ext::TestSize. JsonObject jsonObject; jsonObject[PARAM_KEY_OS_VERSION] = "5.0.3"; jsonObject[PARAM_KEY_OS_TYPE] = 1; - std::string extraData = SafetyDump(jsonObject); + std::string extraData = jsonObject.Dump(); auto ret = CreateDmDeviceInfo(networkId, extraData, deviceInfo); ASSERT_TRUE(ret); std::vector deviceInfos = { deviceInfo }; @@ -310,7 +310,7 @@ HWTEST_F(DpInitedCallbackTest, PutAllTrustedDevices_009, testing::ext::TestSize. JsonObject jsonObject; jsonObject[PARAM_KEY_OS_VERSION] = "5.0.3"; jsonObject[PARAM_KEY_OS_TYPE] = 1; - std::string extraData = SafetyDump(jsonObject); + std::string extraData = jsonObject.Dump(); auto ret = CreateDmDeviceInfo(networkId, extraData, deviceInfo); ASSERT_TRUE(ret); diff --git a/test/unittest/UTTest_hichain_listener.cpp b/test/unittest/UTTest_hichain_listener.cpp index 329b0aa3e..6a542ba94 100644 --- a/test/unittest/UTTest_hichain_listener.cpp +++ b/test/unittest/UTTest_hichain_listener.cpp @@ -70,7 +70,7 @@ HWTEST_F(HichainListenerTest, OnHichainDeviceUnBound_001, testing::ext::TestSize jsonObject[FIELD_GROUP_TYPE] = DM_IDENTICAL_ACCOUNT; jsonObject[FIELD_USER_ID] = "hdaoiudhifvafiouoahf-ZhangSan"; jsonObject[FIELD_OS_ACCOUNT_ID] = 128; - const char *groupInfoPtr = SafetyDump(jsonObject).c_str(); + const char *groupInfoPtr = jsonObject.Dump().c_str(); listerner.OnHichainDeviceUnBound(peerUdid, groupInfoPtr); EXPECT_TRUE(groupInfoPtr != nullptr); } diff --git a/test/unittest/UTTest_ipc_cmd_parser_client.cpp b/test/unittest/UTTest_ipc_cmd_parser_client.cpp index 58f9bd3ed..e4d411df2 100644 --- a/test/unittest/UTTest_ipc_cmd_parser_client.cpp +++ b/test/unittest/UTTest_ipc_cmd_parser_client.cpp @@ -1079,7 +1079,7 @@ HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_037, testing::ext::TestSize.Le JsonObject jsonObject; jsonObject[DM_CREDENTIAL_TYPE] = DM_TYPE_OH; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); MessageParcel data; data.WriteString(message); @@ -1097,7 +1097,7 @@ HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_038, testing::ext::TestSize.Le JsonObject jsonObject; jsonObject[DM_CREDENTIAL_TYPE] = DM_TYPE_MINE; jsonObject[DM_CREDENTIAL_RETURNJSONSTR] = credential; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); MessageParcel data; data.WriteString(message); @@ -1113,7 +1113,7 @@ HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_039, testing::ext::TestSize.Le JsonObject jsonObject; jsonObject[DM_CREDENTIAL_TYPE] = DM_TYPE_OH; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); MessageParcel data; data.WriteString(message); @@ -1131,7 +1131,7 @@ HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_040, testing::ext::TestSize.Le JsonObject jsonObject; jsonObject[DM_CREDENTIAL_TYPE] = DM_TYPE_MINE; jsonObject[DM_CREDENTIAL_RETURNJSONSTR] = credential; - std::string message = SafetyDump(jsonObject); + std::string message = jsonObject.Dump(); MessageParcel data; data.WriteString(message); diff --git a/test/unittest/UTTest_ipc_cmd_parser_service.cpp b/test/unittest/UTTest_ipc_cmd_parser_service.cpp index 719df2374..21cc9a364 100644 --- a/test/unittest/UTTest_ipc_cmd_parser_service.cpp +++ b/test/unittest/UTTest_ipc_cmd_parser_service.cpp @@ -1252,7 +1252,7 @@ HWTEST_F(IpcCmdParserServiceTest, OnIpcCmdFunc_053, testing::ext::TestSize.Level JsonObject jsonObject; jsonObject[DM_CREDENTIAL_TYPE] = DM_TYPE_OH; jsonObject[DM_CREDENTIAL_REQJSONSTR] = ""; - std::string credentialInfo = SafetyDump(jsonObject); + std::string credentialInfo = jsonObject.Dump(); data.WriteString(pkgName); data.WriteString(credentialInfo); OnIpcCmdFunc ptr = GetIpcCmdFunc(cmdCode); @@ -1290,7 +1290,7 @@ HWTEST_F(IpcCmdParserServiceTest, OnIpcCmdFunc_054, testing::ext::TestSize.Level JsonObject jsonObject; jsonObject[DM_CREDENTIAL_TYPE] = DM_TYPE_MINE; jsonObject[DM_CREDENTIAL_REQJSONSTR] = ""; - std::string credentialInfo = SafetyDump(jsonObject); + std::string credentialInfo = jsonObject.Dump(); data.WriteString(pkgName); data.WriteString(credentialInfo); OnIpcCmdFunc ptr = GetIpcCmdFunc(cmdCode); diff --git a/test/unittest/UTTest_json_object.cpp b/test/unittest/UTTest_json_object.cpp index 901963d83..91e98df71 100644 --- a/test/unittest/UTTest_json_object.cpp +++ b/test/unittest/UTTest_json_object.cpp @@ -230,17 +230,6 @@ HWTEST_F(JsonObjectTest, SetValue_012, testing::ext::TestSize.Level1) EXPECT_EQ(strRet, object1.Dump()); } -HWTEST_F(JsonObjectTest, DumpIgnoreError_01, testing::ext::TestSize.Level1) -{ - JsonObject object; - object["TEST1"] = "special_characters!@#.123"; - object["TEST2"] = 1; - object["TEST3"] = 0.0; - object["TEST4"] = true; - std::string strRet = R"({"TEST1":"special_characters!@#.123","TEST2":1,"TEST3":0.0,"TEST4":true})"; - EXPECT_EQ(strRet, object.DumpIgnoreError()); -} - HWTEST_F(JsonObjectTest, Dump_01, testing::ext::TestSize.Level1) { JsonObject object; diff --git a/test/unittest/UTTest_kv_adapter_manager.cpp b/test/unittest/UTTest_kv_adapter_manager.cpp index 0dccf5670..fb8c18d97 100644 --- a/test/unittest/UTTest_kv_adapter_manager.cpp +++ b/test/unittest/UTTest_kv_adapter_manager.cpp @@ -94,7 +94,7 @@ std::string KVAdapterManagerTest::CreateDmKVValueStr(const std::string &appId, i jsonObject[ANOY_DEVICE_ID_KEY] = "anoy_device"; jsonObject[SALT_KEY] = "salt"; jsonObject[LAST_MODIFY_TIME_KEY] = lastModifyTime; - return SafetyDump(jsonObject); + return jsonObject.Dump(); } HWTEST_F(KVAdapterManagerTest, Init_001, testing::ext::TestSize.Level1) diff --git a/utils/src/kvadapter/dm_kv_info.cpp b/utils/src/kvadapter/dm_kv_info.cpp index 8c880bd49..2f9893682 100644 --- a/utils/src/kvadapter/dm_kv_info.cpp +++ b/utils/src/kvadapter/dm_kv_info.cpp @@ -33,7 +33,7 @@ void ConvertDmKVValueToJson(const DmKVValue &kvValue, std::string &result) jsonObj[ANOY_DEVICE_ID_KEY] = kvValue.anoyDeviceId; jsonObj[SALT_KEY] = kvValue.salt; jsonObj[LAST_MODIFY_TIME_KEY] = kvValue.lastModifyTime; - result = SafetyDump(jsonObj); + result = jsonObj.Dump(); } void ConvertJsonToDmKVValue(const std::string &result, DmKVValue &kvValue) diff --git a/utils/src/kvadapter/kv_adapter.cpp b/utils/src/kvadapter/kv_adapter.cpp index f0b8d0a53..15b5c226a 100644 --- a/utils/src/kvadapter/kv_adapter.cpp +++ b/utils/src/kvadapter/kv_adapter.cpp @@ -298,7 +298,7 @@ int32_t KVAdapter::GetAllOstypeData(const std::string &key, std::vector(); jsonObj[TIME_STAMP] = osTyoeJson[TIME_STAMP].Get(); - values.push_back(SafetyDump(jsonObj)); + values.push_back(jsonObj.Dump()); } return DM_OK; } -- Gitee