diff --git a/common/src/dm_anonymous.cpp b/common/src/dm_anonymous.cpp index 57edca138b185da9f1ca5af21277e6e6129b6c6f..aeabd2c57e65e0430f9d5eff4e0666dc7d410836 100644 --- a/common/src/dm_anonymous.cpp +++ b/common/src/dm_anonymous.cpp @@ -31,25 +31,25 @@ const int32_t LIST_SPLIT_LEN = 2; std::string GetAnonyString(const std::string &value) { - const int32_t INT32_SHORT_ID_LENGTH = 20; - const int32_t INT32_PLAINTEXT_LENGTH = 4; - const int32_t INT32_MIN_ID_LENGTH = 3; + const int32_t int32ShortIdLength = 20; + const int32_t int32PlaintextLength = 4; + const int32_t int32MinIdLength = 3; std::string tmpStr("******"); size_t strLen = value.length(); - if (strLen < INT32_MIN_ID_LENGTH) { + if (strLen < int32MinIdLength) { return tmpStr; } std::string res; - if (strLen <= INT32_SHORT_ID_LENGTH) { + if (strLen <= int32ShortIdLength) { res += value[0]; res += tmpStr; res += value[strLen - 1]; } else { - res.append(value, 0, INT32_PLAINTEXT_LENGTH); + res.append(value, 0, int32PlaintextLength); res += tmpStr; - res.append(value, strLen - INT32_PLAINTEXT_LENGTH, INT32_PLAINTEXT_LENGTH); + res.append(value, strLen - int32PlaintextLength, int32PlaintextLength); } return res; @@ -105,11 +105,11 @@ bool IsNumberString(const std::string &inputString) LOGE("inputString is Null or inputString length is too long"); return false; } - const int32_t MIN_ASCII_NUM = 48; - const int32_t MAX_ASCII_NUM = 57; + const int32_t minAsciiNum = 48; + const int32_t maxAsciiNum = 57; for (size_t i = 0; i < inputString.length(); i++) { int num = (int)inputString[i]; - if (num >= MIN_ASCII_NUM && num <= MAX_ASCII_NUM) { + if (num >= minAsciiNum && num <= maxAsciiNum) { continue; } else { return false; 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 42aac4ed71cbc01f7c487d73137aab519696c4f1..1e6a7b8b027d7195b1f2a04c023bf89bf37bad46 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -2972,7 +2972,7 @@ bool DeviceManagerImpl::CheckSinkIsSameAccount(const DmAccessCaller &caller, con } bool DeviceManagerImpl::CheckAclByIpcCode(const DmAccessCaller &caller, const DmAccessCallee &callee, - const DMIpcCmdInterfaceCode &ipcCode) + const DMIpcCmdInterfaceCode &ipcCode) { LOGI("start, ipcCode %{public}d.", static_cast(ipcCode)); std::shared_ptr req = std::make_shared(); diff --git a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp index 278ebade4d53d5d46cd43c5f43211105821592bf..0639394b1642b540f70fc47cc24e8e471c08d760 100644 --- a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp +++ b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp @@ -419,7 +419,7 @@ void DeviceManagerNotify::OnDeviceChanged(const std::string &pkgName, const DmDe auto iter = deviceStateCallback_.find(pkgName); if (iter == deviceStateCallback_.end()) { if (deviceStatusCallback_.find(pkgName) == deviceStatusCallback_.end()) { - LOGE("error, device state callback not register, pkgName:%{public}s",pkgName.c_str()); + LOGE("error, device state callback not register, pkgName:%{public}s", pkgName.c_str()); } return; } diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 2bcd88c8f183ad3f2e4e0c70e53f9f34fe237441..3c32387694a08c1a504007d63e986e72f1ab77a9 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1925,7 +1925,7 @@ bool DeviceManagerService::CheckAccessControl(const DmAccessCaller &caller, cons LOGE("GetAccessUdidByNetworkId failed."); return false; } - return dmServiceImpl_->CheckAccessControl(caller, srcUdid, callee, sinkUdid); + return dmServiceImpl_->CheckAccessControl(caller, srcUdid, callee, sinkUdid); } bool DeviceManagerService::CheckIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee) diff --git a/test/commonunittest/UTTest_dm_anonymous.cpp b/test/commonunittest/UTTest_dm_anonymous.cpp index 8be86ff7e8a3499ccd201bd7653c06722422c93a..09bb25317962c7014f8edd918ada3e0f72644ea5 100644 --- a/test/commonunittest/UTTest_dm_anonymous.cpp +++ b/test/commonunittest/UTTest_dm_anonymous.cpp @@ -431,15 +431,15 @@ HWTEST_F(DmAnonymousTest, IsBool_002, testing::ext::TestSize.Level1) */ HWTEST_F(DmAnonymousTest, ConvertCharArray2String_001, testing::ext::TestSize.Level1) { - constexpr uint32_t MAX_MESSAGE_LEN = 40 * 1024 * 1024; + constexpr uint32_t maxMessageLen = 40 * 1024 * 1024; char *srcData = nullptr; uint32_t srcLen = 0; std::string ret = ConvertCharArray2String(srcData, srcLen); EXPECT_EQ(ret, ""); - ret = ConvertCharArray2String(srcData, MAX_MESSAGE_LEN + 1); + ret = ConvertCharArray2String(srcData, maxMessageLen + 1); EXPECT_EQ(ret, ""); char srcData2[20] = {"1234"}; - ret = ConvertCharArray2String(srcData2, MAX_MESSAGE_LEN + 1); + ret = ConvertCharArray2String(srcData2, maxMessageLen + 1); EXPECT_EQ(ret, ""); uint32_t srcLen2 = 20; ret = ConvertCharArray2String(srcData2, srcLen); diff --git a/test/commonunittest/UTTest_dm_auth_manager_first.cpp b/test/commonunittest/UTTest_dm_auth_manager_first.cpp index 887ebd6e8b4832399c8836e8b01fa47798aa06cb..aff6cb61d2a9874d5b00bdec5957ade828a03fa0 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_first.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_first.cpp @@ -1490,34 +1490,6 @@ HWTEST_F(DmAuthManagerTest, StopAuthenticateDevice_001, testing::ext::TestSize.L ASSERT_EQ(ret, DM_OK); } -HWTEST_F(DmAuthManagerTest, GetBindLevel_001, testing::ext::TestSize.Level1) -{ - int32_t bindLevel = INVALIED_TYPE; - std::string udid; - authManager_->HandleDeviceNotTrust(udid); - udid = "988989"; - authManager_->HandleDeviceNotTrust(udid); - int32_t sessionId = 32166; - authManager_->ProcIncompatible(sessionId); - - authManager_->authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE; - authManager_->authResponseContext_->importAuthCode = "importAuthCode"; - authManager_->importAuthCode_ = "importAuthCode"; - authManager_->ProcessAuthRequest(sessionId); - - authManager_->authResponseContext_->authType == AUTH_TYPE_NFC; - authManager_->authResponseContext_->isOnline = false; - authManager_->authResponseContext_->reply = 0; - authManager_->authResponseContext_->isIdenticalAccount = false; - authManager_->authResponseContext_->isAuthCodeReady = true; - authManager_->ProcessAuthRequest(sessionId); - - authManager_->authResponseContext_->reply = ERR_DM_UNSUPPORTED_AUTH_TYPE; - authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE; - authManager_->authResponseContext_->isAuthCodeReady == false; - authManager_->ProcessAuthRequest(sessionId); -} - HWTEST_F(DmAuthManagerTest, IsAuthFinish_001, testing::ext::TestSize.Level1) { authManager_->authResponseContext_->reply = ERR_DM_UNSUPPORTED_AUTH_TYPE; diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp index de578f338e99e8f3d42adedfd77727140c9b0f6e..163e85156456ab6211b4cc8d0f2ca57082560123 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp @@ -1689,8 +1689,9 @@ HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndUdidListByTokenId_002, std::vector emptyUserIds; std::string localUdid = "localDeviceId"; int32_t tokenId = 1234; - - auto result = DeviceProfileConnector::GetInstance().GetDeviceIdAndUdidListByTokenId(emptyUserIds, localUdid, tokenId); + + auto result = DeviceProfileConnector::GetInstance() + .GetDeviceIdAndUdidListByTokenId(emptyUserIds, localUdid, tokenId); EXPECT_TRUE(result.empty()); } diff --git a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp index 69cebe8cfdf924f777e0d2092c2be64143daae33..5988b4d5b31563f8ca06b357dce37ad9f100d05f 100755 --- a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp +++ b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp @@ -1,265 +1,264 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ - #include - #include - #include - #include - #include - #include - #include - - #include "device_manager_impl.h" - - namespace OHOS { - namespace DistributedHardware { - - namespace { - - } - - void StopAuthenticateDeviceTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().StopAuthenticateDevice(pkgName); - DeviceManagerImpl::GetInstance().OnDmServiceDied(); - } - - void UnBindDeviceTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string deviceId = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().UnBindDevice(pkgName, deviceId); - } - - void ShiftLNNGearTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().ShiftLNNGear(pkgName); - } - - void RegDevTrustChangeCallbackTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::shared_ptr callback = nullptr; - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().RegDevTrustChangeCallback(pkgName, callback); - } - - void GetNetworkIdByUdidTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string udid = fdp.ConsumeRandomLengthString(); - std::string networkId = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().GetNetworkIdByUdid(pkgName, udid, networkId); - } - - void RegisterCredentialAuthStatusCallbackTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().RegisterCredentialAuthStatusCallback(pkgName, callback); - } - - void GetAllTrustedDeviceListTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string extra = fdp.ConsumeRandomLengthString(); - std::vector deviceList; - DeviceManagerImpl::GetInstance().GetAllTrustedDeviceList(pkgName, extra, deviceList); - } - - void RegisterSinkBindCallbackTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().RegisterSinkBindCallback(pkgName, callback); - } - - void GetDeviceProfileInfoListTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DmDeviceProfileInfoFilterOptions filterOptions; - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().GetDeviceProfileInfoList(pkgName, filterOptions, callback); - } - - void GetDeviceIconInfoTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DmDeviceProfileInfoFilterOptions filterOptions; - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().GetDeviceProfileInfoList(pkgName, filterOptions, callback); - } - - void PutDeviceProfileInfoListTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::vector deviceProfileInfoList; - DeviceManagerImpl::GetInstance().PutDeviceProfileInfoList(pkgName, deviceProfileInfoList); - } - - void GetLocalDisplayDeviceNameTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string displayName = fdp.ConsumeRandomLengthString(); - int32_t maxNameLength = fdp.ConsumeIntegral(); - DeviceManagerImpl::GetInstance().GetLocalDisplayDeviceName(pkgName, maxNameLength, displayName); - } - - void GetDeviceNetworkIdListTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string bundleName = fdp.ConsumeRandomLengthString(); - NetworkIdQueryFilter queryFilter; - std::vector networkIds; - DeviceManagerImpl::GetInstance().GetDeviceNetworkIdList(bundleName, queryFilter, networkIds); - } - - void SetLocalDeviceNameTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string deviceName = fdp.ConsumeRandomLengthString(); - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().SetLocalDeviceName(pkgName, deviceName, callback); - } - - void SetRemoteDeviceNameTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string deviceId = fdp.ConsumeRandomLengthString(); - std::string deviceName = fdp.ConsumeRandomLengthString(); - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().SetRemoteDeviceName(pkgName, deviceId, deviceName, callback); - } - - void RestoreLocalDeviceNameTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().RestoreLocalDeviceName(pkgName); - } - - void GetLocalServiceInfoByBundleNameAndPinExchangeTypeTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string bundleName = fdp.ConsumeRandomLengthString(); - int32_t maxNameLength = fdp.ConsumeIntegral(); - DMLocalServiceInfo info; - DeviceManagerImpl::GetInstance(). - GetLocalServiceInfoByBundleNameAndPinExchangeType(bundleName, maxNameLength, info); - } - - void UnRegisterPinHolderCallbackTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().UnRegisterPinHolderCallback(pkgName); - } - } - } - - /* Fuzzer entry point */ - extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) - { - /* Run your code on data */ - OHOS::DistributedHardware::StopAuthenticateDeviceTest(data, size); - OHOS::DistributedHardware::UnBindDeviceTest(data, size); - OHOS::DistributedHardware::ShiftLNNGearTest(data, size); - OHOS::DistributedHardware::RegDevTrustChangeCallbackTest(data, size); - OHOS::DistributedHardware::GetNetworkIdByUdidTest(data, size); - OHOS::DistributedHardware::RegisterCredentialAuthStatusCallbackTest(data, size); - OHOS::DistributedHardware::GetAllTrustedDeviceListTest(data, size); - OHOS::DistributedHardware::RegisterSinkBindCallbackTest(data, size); - OHOS::DistributedHardware::GetDeviceProfileInfoListTest(data, size); - OHOS::DistributedHardware::GetDeviceIconInfoTest(data, size); - OHOS::DistributedHardware::PutDeviceProfileInfoListTest(data, size); - OHOS::DistributedHardware::GetLocalDisplayDeviceNameTest(data, size); - OHOS::DistributedHardware::GetDeviceNetworkIdListTest(data, size); - OHOS::DistributedHardware::SetLocalDeviceNameTest(data, size); - OHOS::DistributedHardware::SetRemoteDeviceNameTest(data, size); - OHOS::DistributedHardware::RestoreLocalDeviceNameTest(data, size); - OHOS::DistributedHardware::GetLocalServiceInfoByBundleNameAndPinExchangeTypeTest(data, size); - OHOS::DistributedHardware::UnRegisterPinHolderCallbackTest(data, size); - return 0; - } - \ No newline at end of file +#include +#include +#include +#include +#include +#include +#include + +#include "device_manager_impl.h" + +namespace OHOS { +namespace DistributedHardware { + +namespace { + +} + +void StopAuthenticateDeviceTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().StopAuthenticateDevice(pkgName); + DeviceManagerImpl::GetInstance().OnDmServiceDied(); +} + +void UnBindDeviceTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string deviceId = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().UnBindDevice(pkgName, deviceId); +} + +void ShiftLNNGearTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().ShiftLNNGear(pkgName); +} + +void RegDevTrustChangeCallbackTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::shared_ptr callback = nullptr; + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().RegDevTrustChangeCallback(pkgName, callback); +} + +void GetNetworkIdByUdidTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string udid = fdp.ConsumeRandomLengthString(); + std::string networkId = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().GetNetworkIdByUdid(pkgName, udid, networkId); +} + +void RegisterCredentialAuthStatusCallbackTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().RegisterCredentialAuthStatusCallback(pkgName, callback); +} + +void GetAllTrustedDeviceListTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string extra = fdp.ConsumeRandomLengthString(); + std::vector deviceList; + DeviceManagerImpl::GetInstance().GetAllTrustedDeviceList(pkgName, extra, deviceList); +} + +void RegisterSinkBindCallbackTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().RegisterSinkBindCallback(pkgName, callback); +} + +void GetDeviceProfileInfoListTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DmDeviceProfileInfoFilterOptions filterOptions; + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().GetDeviceProfileInfoList(pkgName, filterOptions, callback); +} + +void GetDeviceIconInfoTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DmDeviceProfileInfoFilterOptions filterOptions; + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().GetDeviceProfileInfoList(pkgName, filterOptions, callback); +} + +void PutDeviceProfileInfoListTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::vector deviceProfileInfoList; + DeviceManagerImpl::GetInstance().PutDeviceProfileInfoList(pkgName, deviceProfileInfoList); +} + +void GetLocalDisplayDeviceNameTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string displayName = fdp.ConsumeRandomLengthString(); + int32_t maxNameLength = fdp.ConsumeIntegral(); + DeviceManagerImpl::GetInstance().GetLocalDisplayDeviceName(pkgName, maxNameLength, displayName); +} + +void GetDeviceNetworkIdListTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string bundleName = fdp.ConsumeRandomLengthString(); + NetworkIdQueryFilter queryFilter; + std::vector networkIds; + DeviceManagerImpl::GetInstance().GetDeviceNetworkIdList(bundleName, queryFilter, networkIds); +} + +void SetLocalDeviceNameTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string deviceName = fdp.ConsumeRandomLengthString(); + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().SetLocalDeviceName(pkgName, deviceName, callback); +} + +void SetRemoteDeviceNameTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string deviceId = fdp.ConsumeRandomLengthString(); + std::string deviceName = fdp.ConsumeRandomLengthString(); + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().SetRemoteDeviceName(pkgName, deviceId, deviceName, callback); +} + +void RestoreLocalDeviceNameTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().RestoreLocalDeviceName(pkgName); +} + +void GetLocalServiceInfoByBundleNameAndPinExchangeTypeTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string bundleName = fdp.ConsumeRandomLengthString(); + int32_t maxNameLength = fdp.ConsumeIntegral(); + DMLocalServiceInfo info; + DeviceManagerImpl::GetInstance(). + GetLocalServiceInfoByBundleNameAndPinExchangeType(bundleName, maxNameLength, info); +} + +void UnRegisterPinHolderCallbackTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().UnRegisterPinHolderCallback(pkgName); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::StopAuthenticateDeviceTest(data, size); + OHOS::DistributedHardware::UnBindDeviceTest(data, size); + OHOS::DistributedHardware::ShiftLNNGearTest(data, size); + OHOS::DistributedHardware::RegDevTrustChangeCallbackTest(data, size); + OHOS::DistributedHardware::GetNetworkIdByUdidTest(data, size); + OHOS::DistributedHardware::RegisterCredentialAuthStatusCallbackTest(data, size); + OHOS::DistributedHardware::GetAllTrustedDeviceListTest(data, size); + OHOS::DistributedHardware::RegisterSinkBindCallbackTest(data, size); + OHOS::DistributedHardware::GetDeviceProfileInfoListTest(data, size); + OHOS::DistributedHardware::GetDeviceIconInfoTest(data, size); + OHOS::DistributedHardware::PutDeviceProfileInfoListTest(data, size); + OHOS::DistributedHardware::GetLocalDisplayDeviceNameTest(data, size); + OHOS::DistributedHardware::GetDeviceNetworkIdListTest(data, size); + OHOS::DistributedHardware::SetLocalDeviceNameTest(data, size); + OHOS::DistributedHardware::SetRemoteDeviceNameTest(data, size); + OHOS::DistributedHardware::RestoreLocalDeviceNameTest(data, size); + OHOS::DistributedHardware::GetLocalServiceInfoByBundleNameAndPinExchangeTypeTest(data, size); + OHOS::DistributedHardware::UnRegisterPinHolderCallbackTest(data, size); + return 0; +} diff --git a/test/servicesfuzztest/dmcommtooltwo_fuzzer/dm_comm_tool_two_fuzzer.cpp b/test/servicesfuzztest/dmcommtooltwo_fuzzer/dm_comm_tool_two_fuzzer.cpp index 18652864e2bd7fe9a6845e685e14076c159c094c..a797643db18aad9dbe2d0b24f46313dd5f604518 100644 --- a/test/servicesfuzztest/dmcommtooltwo_fuzzer/dm_comm_tool_two_fuzzer.cpp +++ b/test/servicesfuzztest/dmcommtooltwo_fuzzer/dm_comm_tool_two_fuzzer.cpp @@ -36,7 +36,7 @@ void GenerateUserIds(FuzzedDataProvider& fdp, std::vector& outIds) auto count = fdp.ConsumeIntegralInRange(0, 10); - while(count-- > 0 && fdp.remaining_bytes() >= sizeof(uint32_t)) { + while (count-- > 0 && fdp.remaining_bytes() >= sizeof(uint32_t)) { outIds.push_back(fdp.ConsumeIntegral()); } } diff --git a/test/servicesfuzztest/dmsoftbuslistener_fuzzer/dm_softbus_listener_fuzzer.cpp b/test/servicesfuzztest/dmsoftbuslistener_fuzzer/dm_softbus_listener_fuzzer.cpp index c2471bb76c80e64816efd178a8ce09417acfca5e..d189ad1ae564f1616ab3bcc7942f9807718585fd 100644 --- a/test/servicesfuzztest/dmsoftbuslistener_fuzzer/dm_softbus_listener_fuzzer.cpp +++ b/test/servicesfuzztest/dmsoftbuslistener_fuzzer/dm_softbus_listener_fuzzer.cpp @@ -33,7 +33,7 @@ void DmSoftbusListenerFuzzTestNext(FuzzedDataProvider &fdp) { SoftbusListener listener; std::string networkIdStr = fdp.ConsumeRandomLengthString(); - if (!networkIdStr.empty()) { + if (!networkIdStr.empty()) { int32_t networkType = fdp.ConsumeIntegral(); listener.GetNetworkTypeByNetworkId(networkIdStr.c_str(), networkType); } diff --git a/test/unittest/UTTest_device_manager_service_impl.cpp b/test/unittest/UTTest_device_manager_service_impl.cpp index c2c5a453e4d6edd33613bd957b1ebb2a86efd3b2..25babd3e14ccc498dcaf9a264927b112dbac53e2 100644 --- a/test/unittest/UTTest_device_manager_service_impl.cpp +++ b/test/unittest/UTTest_device_manager_service_impl.cpp @@ -35,7 +35,7 @@ void DeviceManagerServiceImplTest::SetUp() uint64_t tokenId = IPCSkeleton::GetCallingTokenID(); deviceManagerServiceImpl_->InitAndRegisterAuthMgr(true, tokenId, session, 0, "com.test"); } -const std::string testID("111111"); +const std::string TEST_ID("111111"); void DeviceManagerServiceImplTest::TearDown() { diff --git a/test/unittest/UTTest_device_manager_service_impl_first.cpp b/test/unittest/UTTest_device_manager_service_impl_first.cpp index 3badcf2992de30ab7a6b0953da5f31fdb3e8f0a8..ca79359a2d608fbbe15d3af9ec00ef0fe6005033 100644 --- a/test/unittest/UTTest_device_manager_service_impl_first.cpp +++ b/test/unittest/UTTest_device_manager_service_impl_first.cpp @@ -720,7 +720,8 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, ProcessUnBindApp_003, testing::ext:: std::string extra = R"({"peerTokenId": 5678})"; std::string udid = "remoteUdid"; - EXPECT_CALL(*deviceManagerServiceImplMock_, HandleAppUnBindEvent(userId, udid, accessTokenId, peerTokenId)).Times(1); + EXPECT_CALL(*deviceManagerServiceImplMock_, + HandleAppUnBindEvent(userId, udid, accessTokenId, peerTokenId)).Times(1); deviceManagerServiceImpl_->ProcessUnBindApp(userId, accessTokenId, extra, udid); } diff --git a/test/unittest/UTTest_device_manager_service_three.cpp b/test/unittest/UTTest_device_manager_service_three.cpp index f944566c4a842cddd234ea3549eb38d6d7938e85..fc815051a5616d7035effffaa13848fb525c0177 100644 --- a/test/unittest/UTTest_device_manager_service_three.cpp +++ b/test/unittest/UTTest_device_manager_service_three.cpp @@ -725,7 +725,6 @@ HWTEST_F(DeviceManagerServiceThreeTest, SubscribePackageCommonEvent_301, testing DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); DeviceManagerService::GetInstance().softbusListener_ = nullptr; - } HWTEST_F(DeviceManagerServiceThreeTest, SubscribePackageCommonEvent_302, testing::ext::TestSize.Level1) @@ -816,18 +815,18 @@ HWTEST_F(DeviceManagerServiceThreeTest, NotifyRemoteUnBindAppByWifi_001, testing HWTEST_F(DeviceManagerServiceThreeTest, ProcessReceiveRspAppUninstall_301, testing::ext::TestSize.Level1) { - std::string remoteUdid = "ohos"; - DeviceManagerService::GetInstance().timer_ = std::make_shared(); - DeviceManagerService::GetInstance().ProcessReceiveRspAppUninstall(remoteUdid); - EXPECT_NE(DeviceManagerService::GetInstance().timer_, nullptr); + std::string remoteUdid = "ohos"; + DeviceManagerService::GetInstance().timer_ = std::make_shared(); + DeviceManagerService::GetInstance().ProcessReceiveRspAppUninstall(remoteUdid); + EXPECT_NE(DeviceManagerService::GetInstance().timer_, nullptr); } HWTEST_F(DeviceManagerServiceThreeTest, ProcessReceiveRspAppUninstall_302, testing::ext::TestSize.Level1) { - std::string remoteUdid = "ohos"; - DeviceManagerService::GetInstance().timer_ = nullptr; - DeviceManagerService::GetInstance().ProcessReceiveRspAppUninstall(remoteUdid); - EXPECT_EQ(DeviceManagerService::GetInstance().timer_, nullptr); + std::string remoteUdid = "ohos"; + DeviceManagerService::GetInstance().timer_ = nullptr; + DeviceManagerService::GetInstance().ProcessReceiveRspAppUninstall(remoteUdid); + EXPECT_EQ(DeviceManagerService::GetInstance().timer_, nullptr); } HWTEST_F(DeviceManagerServiceThreeTest, ProcessReceiveRspAppUnbind_301, testing::ext::TestSize.Level1) diff --git a/test/unittest/UTTest_device_manager_service_two.cpp b/test/unittest/UTTest_device_manager_service_two.cpp index 178290401a8a6030224bd61365c34aadf68c6a80..d6298c7b8903bf2be23d5a38da401f2a1f1711a9 100644 --- a/test/unittest/UTTest_device_manager_service_two.cpp +++ b/test/unittest/UTTest_device_manager_service_two.cpp @@ -1818,11 +1818,6 @@ HWTEST_F(DeviceManagerServiceTest, SendShareTypeUnBindBroadCast_001, testing::ex EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); } -HWTEST_F(DeviceManagerServiceTest, HandleCredentialDeleted_001, testing::ext::TestSize.Level1) -{ - DeviceManagerService::GetInstance().HandleCredentialDeleted("credId", "credInfo"); -} - HWTEST_F(DeviceManagerServiceTest, HandleCredentialDeleted_002, testing::ext::TestSize.Level1) { EXPECT_CALL(*deviceManagerServiceImplMock_, HandleCredentialDeleted(_, _, _, _)).Times(0); @@ -1830,11 +1825,6 @@ HWTEST_F(DeviceManagerServiceTest, HandleCredentialDeleted_002, testing::ext::Te DeviceManagerService::GetInstance().HandleCredentialDeleted(nullptr, "credInfo"); } -HWTEST_F(DeviceManagerServiceTest, HandleCredentialDeleted_003, testing::ext::TestSize.Level1) -{ - DeviceManagerService::GetInstance().HandleCredentialDeleted("credId", nullptr); -} - HWTEST_F(DeviceManagerServiceTest, HandleCredentialDeleted_004, testing::ext::TestSize.Level1) { EXPECT_CALL(*multipleUserConnectorMock_, GetCurrentAccountUserID()).Times(0); @@ -1947,6 +1937,7 @@ HWTEST_F(DeviceManagerServiceTest, GetNotifyRemoteUnBindAppWay_001, testing::ext EXPECT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr); DeviceManagerService::GetInstance().softbusListener_ = nullptr; } + HWTEST_F(DeviceManagerServiceTest, GetNotifyRemoteUnBindAppWay_002, testing::ext::TestSize.Level1) { int32_t userId = 1001; @@ -1956,7 +1947,6 @@ HWTEST_F(DeviceManagerServiceTest, GetNotifyRemoteUnBindAppWay_002, testing::ext DeviceManagerService::GetInstance().softbusListener_ = nullptr; DeviceManagerService::GetInstance().GetNotifyRemoteUnBindAppWay(userId, tokenId, wifiDevices, isBleWay); EXPECT_EQ(DeviceManagerService::GetInstance().softbusListener_, nullptr); - } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/UTTest_dm_pin_holder.h b/test/unittest/UTTest_dm_pin_holder.h index 3b3746babd5dc367fa12bf250f6855f76424ce32..547e5717e5b0dd76f62ff7c715c89287e8f54a73 100644 --- a/test/unittest/UTTest_dm_pin_holder.h +++ b/test/unittest/UTTest_dm_pin_holder.h @@ -216,14 +216,14 @@ public: (void)processInfo; } - virtual void OnDevStateCallbackAdd(const ProcessInfo &processInfo, + void OnDevStateCallbackAdd(const ProcessInfo &processInfo, const std::vector &deviceList) override { (void)processInfo; (void)deviceList; } - virtual void OnGetDeviceProfileInfoListResult(const ProcessInfo &processInfo, + void OnGetDeviceProfileInfoListResult(const ProcessInfo &processInfo, const std::vector &deviceProfileInfos, int32_t code) override { (void)processInfo; @@ -231,7 +231,7 @@ public: (void)code; } - virtual void OnGetDeviceIconInfoResult(const ProcessInfo &processInfo, + void OnGetDeviceIconInfoResult(const ProcessInfo &processInfo, const DmDeviceIconInfo &dmDeviceIconInfo, int32_t code) override { (void)processInfo; @@ -239,7 +239,7 @@ public: (void)code; } - virtual void OnSetLocalDeviceNameResult(const ProcessInfo &processInfo, + void OnSetLocalDeviceNameResult(const ProcessInfo &processInfo, const std::string &deviceName, int32_t code) override { (void)processInfo; @@ -247,7 +247,7 @@ public: (void)code; } - virtual void OnSetRemoteDeviceNameResult(const ProcessInfo &processInfo, const std::string &deviceId, + void OnSetRemoteDeviceNameResult(const ProcessInfo &processInfo, const std::string &deviceId, const std::string &deviceName, int32_t code) override { (void)processInfo; diff --git a/test/unittest/UTTest_relationship_sync_mgr.cpp b/test/unittest/UTTest_relationship_sync_mgr.cpp index 398e4ef0774dfc1f3a2990e411d0498c7635ddcb..9f6627fc7af642451af4a71905a6def19b276dec 100644 --- a/test/unittest/UTTest_relationship_sync_mgr.cpp +++ b/test/unittest/UTTest_relationship_sync_mgr.cpp @@ -811,7 +811,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToString_ValidData, testing::ext::TestSize.Le "{ isNewEvent: false, userId: 12345, accountId: a******3, tokenId: 67890, " + "peerUdids: [ u******1, u******2 ], peerUdid: p******d, " + "accountName: t******t, syncUserIdFlag: 1, " + - "userIds: [ { 1, userId: 111 }, { 0, userId: 222 } ], broadCastId: 0 }"; + "userIds: [ { 1, userId: 111 }, { 0, userId: 222 } ], broadCastId: 0 }"; EXPECT_EQ(msg.ToString(), expected); }