diff --git a/common/include/dm_anonymous.h b/common/include/dm_anonymous.h index 5ba9498fdb3f5df9c81b5296e9ad5c82fd56592c..3a6f331c322fa565597802e66fe6c965875cb3d9 100644 --- a/common/include/dm_anonymous.h +++ b/common/include/dm_anonymous.h @@ -36,6 +36,7 @@ bool IsString(const JsonItemObject &jsonObj, const std::string &key); EXPORT bool IsInt32(const JsonItemObject &jsonObj, const std::string &key); bool IsUint32(const JsonItemObject &jsonObj, const std::string &key); bool IsInt64(const JsonItemObject &jsonObj, const std::string &key); +bool IsUint64(const JsonItemObject &jsonObj, const std::string &key); bool IsArray(const JsonItemObject &jsonObj, const std::string &key); bool IsBool(const JsonItemObject &jsonObj, const std::string &key); std::string ConvertMapToJsonString(const std::map ¶mMap); diff --git a/common/src/dm_anonymous.cpp b/common/src/dm_anonymous.cpp index e2ac8903f2301380a39cb2cd9be1eaf4b5e55ab1..fdc5f5e359054ce9bae245396abf43bfa1f4c01d 100644 --- a/common/src/dm_anonymous.cpp +++ b/common/src/dm_anonymous.cpp @@ -156,6 +156,16 @@ bool IsInt64(const JsonItemObject &jsonObj, const std::string &key) return res; } +bool IsUint64(const JsonItemObject &jsonObj, const std::string &key) +{ + bool res = jsonObj.Contains(key) && jsonObj[key].IsNumberInteger() && jsonObj[key].Get() >= 0 && + jsonObj[key].Get() <= UINT64_MAX; + if (!res) { + LOGE("the key %{public}s in jsonObj is invalid.", key.c_str()); + } + return res; +} + bool IsArray(const JsonItemObject &jsonObj, const std::string &key) { bool res = jsonObj.Contains(key) && jsonObj[key].IsArray(); diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 48aca95761a5ab83531384a836bf6c1e965de7e7..056624e8e567b3f7f1e9059f38e2eaab3eb47e7b 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -418,7 +418,7 @@ void DeviceProfileConnector::ParseExtra(const std::string &extra, uint64_t &peer LOGE("ParseExtra extraInfoJson error"); return; } - if (!extraInfoJson[TAG_PEER_BUNDLE_NAME].IsString() || !extraInfoJson[TAG_PEER_TOKENID].IsString()) { + if (!extraInfoJson[TAG_PEER_BUNDLE_NAME].IsString() || !extraInfoJson[TAG_PEER_TOKENID].IsNumberInteger()) { LOGE("ParseExtra TAG_PEER_BUNDLE_NAME or TAG_PEER_TOKENID error"); return; } diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index bfbe86e5f3c1801b5b47c4a447ad632e835e00cb..3755199f839e2c4ab168aed8c977f68aac4388fb 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -195,19 +195,19 @@ void DeviceManagerServiceImpl::CleanWorker() logicalSessionId); CleanAuthMgrByLogicalSessionId(logicalSessionId); } + while (!cleanEventQueue_.empty()) { + uint64_t logicalSessionId = cleanEventQueue_.front(); + cleanEventQueue_.pop(); + CleanAuthMgrByLogicalSessionId(logicalSessionId); + } LOGI("DeviceManagerServiceImpl::CleanWorker end"); } void DeviceManagerServiceImpl::Stop() { + std::lock_guard lock(cleanEventMutex_); running_.store(false); cleanEventCv_.notify_all(); - std::lock_guard lock(cleanEventMutex_); - while (!cleanEventQueue_.empty()) { - uint64_t logicalSessionId = cleanEventQueue_.front(); - cleanEventQueue_.pop(); - CleanAuthMgrByLogicalSessionId(logicalSessionId); - } } void DeviceManagerServiceImpl::NotifyCleanEvent(uint64_t logicalSessionId) @@ -339,7 +339,7 @@ void DeviceManagerServiceImpl::CleanAuthMgrByLogicalSessionId(uint64_t logicalSe } CleanSessionMapByLogicalSessionId(logicalSessionId); - if (logicalSessionId == 0) { + if (logicalSessionId == 0 && authMgr_ != nullptr) { authMgr_->SetTransferReady(true); authMgr_->ClearSoftbusSessionCallback(); } @@ -963,13 +963,13 @@ void DeviceManagerServiceImpl::OnBytesReceived(int sessionId, const void *data, LOGI("start, sessionId: %{public}d, dataLen: %{public}d.", sessionId, dataLen); JsonObject jsonObject = GetJsonObjectFromData(data, dataLen); - if (jsonObject.IsDiscarded() || !jsonObject[TAG_MSG_TYPE].IsNumberInteger()) { + if (jsonObject.IsDiscarded() || !IsInt32(jsonObject, TAG_MSG_TYPE)) { LOGE("OnBytesReceived, MSG_TYPE parse failed."); return; } int32_t msgType = jsonObject[TAG_MSG_TYPE].Get(); uint64_t logicalSessionId = 0; - if (jsonObject[DM_TAG_LOGICAL_SESSION_ID].IsNumberInteger()) { + if (IsUint64(jsonObject, DM_TAG_LOGICAL_SESSION_ID)) { logicalSessionId = jsonObject[DM_TAG_LOGICAL_SESSION_ID].Get(); } diff --git a/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp b/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp index e65a30cf223b143948136a89d32c6a03cfa78d3e..4e8f148016301f3633103deaeeb7e2483a0e9075 100644 --- a/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp +++ b/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp @@ -343,10 +343,11 @@ void HiChainConnectorSixthFuzzTest(const uint8_t* data, size_t size) std::string credentialInfo = SafetyDump(jsonObjCre); hichainConnector->ParseRemoteCredentialExt(credentialInfo, params, groupOwner); int32_t groupType = *(reinterpret_cast(data)); - JsonObject jsonDeviceList(JsonCreateType::JSON_CREATE_TYPE_ARRAY); + JsonObject jsonDeviceList; int32_t osAccountUserId = 0; std::string userId = "user_002"; - jsonDeviceList[FIELD_DEVICE_LIST] = "deviceList"; + std::vector fieldDeviceList = {"deviceList"}; + jsonDeviceList[FIELD_DEVICE_LIST] = fieldDeviceList; hichainConnector->ParseRemoteCredential(groupType, userId, jsonDeviceList, params, osAccountUserId); } diff --git a/test/commonunittest/UTTest_dm_anonymous.cpp b/test/commonunittest/UTTest_dm_anonymous.cpp index 167c25a6f778c04afcb45268d8ab6aeac90f6d76..8be86ff7e8a3499ccd201bd7653c06722422c93a 100644 --- a/test/commonunittest/UTTest_dm_anonymous.cpp +++ b/test/commonunittest/UTTest_dm_anonymous.cpp @@ -296,6 +296,42 @@ HWTEST_F(DmAnonymousTest, IsInt64_002, testing::ext::TestSize.Level1) EXPECT_EQ(ret, false); } +/** + * @tc.name: IsUint64_001 + * @tc.desc: Return true + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAnonymousTest, IsUint64_001, testing::ext::TestSize.Level1) +{ + std::string str = R"( + { + "REQUESTID" : 789 + } + )"; + JsonObject jsonObj(str); + bool ret = IsUint64(jsonObj, TAG_REQUEST_ID); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: IsUint64_002 + * @tc.desc: Return false + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAnonymousTest, IsUint64_002, testing::ext::TestSize.Level1) +{ + std::string str = R"( + { + "REQUESTID" : "requestidTest" + } + )"; + JsonObject jsonObj(str); + bool ret = IsUint64(jsonObj, TAG_REQUEST_ID); + EXPECT_EQ(ret, false); +} + /** * @tc.name: IsArray_001 * @tc.desc: Return true diff --git a/test/servicesfuzztest/dmtransportmsg_fuzzer/dm_transport_msg_fuzzer.cpp b/test/servicesfuzztest/dmtransportmsg_fuzzer/dm_transport_msg_fuzzer.cpp index fa52cb012ad9827c04d5ea017ca09f879e6c76c0..1c7446574b11966967adfe83627d9cdb1fa1a26c 100644 --- a/test/servicesfuzztest/dmtransportmsg_fuzzer/dm_transport_msg_fuzzer.cpp +++ b/test/servicesfuzztest/dmtransportmsg_fuzzer/dm_transport_msg_fuzzer.cpp @@ -84,6 +84,7 @@ void DmTransPortMsgFuzzTest(const uint8_t* data, size_t size) ToJson(jsonObject, notifyUserIds); FromJson(jsonObject, notifyUserIds); notifyUserIds.ToString(); + cJSON_Delete(jsonObject); } } } diff --git a/test/unittest/UTTest_device_manager_service_impl.cpp b/test/unittest/UTTest_device_manager_service_impl.cpp index 1cf057d1b1a858bb33841c5e3b60d478252eb53f..f08ba99a9c1c9dea9e509424aefd84b09cd4fb92 100644 --- a/test/unittest/UTTest_device_manager_service_impl.cpp +++ b/test/unittest/UTTest_device_manager_service_impl.cpp @@ -908,24 +908,6 @@ HWTEST_F(DeviceManagerServiceImplTest, SetUserOperation_004, testing::ext::TestS EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); } -/** - * @tc.name: SetUserOperation_005 - * @tc.desc: return ERR_DM_INPUT_PARA_INVALID - * @tc.type: FUNC - */ -HWTEST_F(DeviceManagerServiceImplTest, SetUserOperation_005, testing::ext::TestSize.Level1) -{ - std::string pkgName = "com.ohos.test"; - int32_t action = 1; - const std::string params; - if (deviceManagerServiceImpl_ == nullptr) { - deviceManagerServiceImpl_ = std::make_shared(); - } - deviceManagerServiceImpl_->authMgr_ = nullptr; - int32_t ret = deviceManagerServiceImpl_->SetUserOperation(pkgName, action, params); - EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); -} - /** * @tc.name: HandleOffline_001 * @tc.type: FUNC @@ -1621,7 +1603,7 @@ HWTEST_F(DeviceManagerServiceImplTest, ProcessAppUnintall_102, testing::ext::Tes int32_t accessTokenId = 102; std::vector profiles; AddAccessControlProfileFirst(profiles); - EXPECT_CALL(*deviceProfileConnectorMock_, GetAllAccessControlProfile()).WillOnce(Return(profiles)); + EXPECT_CALL(*deviceProfileConnectorMock_, GetAllAclIncludeLnnAcl()).WillOnce(Return(profiles)); int ret = deviceManagerServiceImpl_->ProcessAppUnintall(appId, accessTokenId); EXPECT_EQ(ret, DM_OK); } @@ -1632,7 +1614,7 @@ HWTEST_F(DeviceManagerServiceImplTest, ProcessAppUnintall_103, testing::ext::Tes int32_t accessTokenId = 1001; std::vector profiles; AddAccessControlProfileFirst(profiles); - EXPECT_CALL(*deviceProfileConnectorMock_, GetAllAccessControlProfile()).WillOnce(Return(profiles)); + EXPECT_CALL(*deviceProfileConnectorMock_, GetAllAclIncludeLnnAcl()).WillOnce(Return(profiles)); if (deviceManagerServiceImpl_->hiChainConnector_ == nullptr) { deviceManagerServiceImpl_->Initialize(listener_); } diff --git a/test/unittest/mock/deviceprofile_connector_mock.cpp b/test/unittest/mock/deviceprofile_connector_mock.cpp index f6bccb76d15eaa978d79020ded7f1c842779ccb9..f63e4791d3fbf830fb6f0f2b0492c0984e9b1001 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.cpp +++ b/test/unittest/mock/deviceprofile_connector_mock.cpp @@ -160,5 +160,10 @@ std::map DeviceProfileConnector::GetDeviceIdAndBindLevel(s { return DmDeviceProfileConnector::dmDeviceProfileConnector->GetDeviceIdAndBindLevel(userIds, localUdid); } + +std::vector DeviceProfileConnector::GetAllAclIncludeLnnAcl() +{ + return DmDeviceProfileConnector::dmDeviceProfileConnector->GetAllAclIncludeLnnAcl(); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/deviceprofile_connector_mock.h b/test/unittest/mock/deviceprofile_connector_mock.h index 9241698c7832ff44ecb816e439a735115e429db4..6a464f4bb2df266a06313f54472811acdda1d257 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.h +++ b/test/unittest/mock/deviceprofile_connector_mock.h @@ -65,6 +65,7 @@ public: const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) = 0; virtual std::map GetDeviceIdAndBindLevel(std::vector userIds, const std::string &localUdid) = 0; + virtual std::vector GetAllAclIncludeLnnAcl() = 0; public: static inline std::shared_ptr dmDeviceProfileConnector = nullptr; }; @@ -104,6 +105,7 @@ public: (const std::string &, (const std::vector &), (const std::vector &))); MOCK_METHOD((std::map), GetDeviceIdAndBindLevel, ((std::vector), const std::string &)); + MOCK_METHOD(std::vector, GetAllAclIncludeLnnAcl, ()); }; } }