From 343a4cff287e22580a11296cee946093dae5202e Mon Sep 17 00:00:00 2001 From: wangdi Date: Sat, 28 Jun 2025 18:17:12 +0800 Subject: [PATCH 1/3] add fuzz tests Signed-off-by: wangdi --- ...service_adddonotdisturbprofiles_fuzzer.cpp | 17 ++++++++ .../service_cancelall_fuzzer.cpp | 12 ++++++ .../service_deleteallbyuser_fuzzer.cpp | 12 ++++++ .../service_distributeoperation_fuzzer.cpp | 7 ++++ ...rvice_enabledistributedbybundle_fuzzer.cpp | 14 +++++++ ...ce_getshowbadgeenabledforbundle_fuzzer.cpp | 15 +++++++ ...ice_isdistributedenablebybundle_fuzzer.cpp | 14 +++++++ ...ce_isdistributedenabledbybundle_fuzzer.cpp | 16 +++++++ .../service_issmartreminderenabled_fuzzer.cpp | 14 +++++++ ...forindirectproxywithmaxcapacity_fuzzer.cpp | 12 ++++++ .../service_removegroupbybundle_fuzzer.cpp | 15 +++++++ .../service_removenotifications_fuzzer.cpp | 12 ++++++ .../service_subscribelocalliveview_fuzzer.cpp | 10 +++++ .../service_subscribeself_fuzzer.cpp | 5 +++ .../mock/mock_notification_operation_info.h | 42 +++++++++++++++++++ 15 files changed, 217 insertions(+) create mode 100644 test/fuzztest/fuzz_common_base/mock/mock_notification_operation_info.h diff --git a/test/fuzztest/advancednotificationservice/serviceadddonotdisturbprofiles_fuzzer/service_adddonotdisturbprofiles_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceadddonotdisturbprofiles_fuzzer/service_adddonotdisturbprofiles_fuzzer.cpp index 4e21d92e4..cbc82dd19 100644 --- a/test/fuzztest/advancednotificationservice/serviceadddonotdisturbprofiles_fuzzer/service_adddonotdisturbprofiles_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceadddonotdisturbprofiles_fuzzer/service_adddonotdisturbprofiles_fuzzer.cpp @@ -16,6 +16,7 @@ #include #include "advanced_notification_service.h" +#include "notification_do_not_disturb_profile.h" #include "ans_permission_def.h" #include "mock_notification_request.h" @@ -23,6 +24,16 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + std::vector> profiles; + sptr profile = + new Notification::NotificationDoNotDisturbProfile(); + profiles.emplace_back(profile); + + service->AddDoNotDisturbProfiles(profiles); return true; } } @@ -33,6 +44,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicecancelall_fuzzer/service_cancelall_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicecancelall_fuzzer/service_cancelall_fuzzer.cpp index e3198ba83..2c75c843b 100644 --- a/test/fuzztest/advancednotificationservice/servicecancelall_fuzzer/service_cancelall_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicecancelall_fuzzer/service_cancelall_fuzzer.cpp @@ -23,6 +23,12 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + std::string stringData = fuzzData->ConsumeRandomLengthString(); + service->CancelAll(stringData); return true; } } @@ -33,6 +39,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicedeleteallbyuser_fuzzer/service_deleteallbyuser_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicedeleteallbyuser_fuzzer/service_deleteallbyuser_fuzzer.cpp index 79b8e652a..0c6085de0 100644 --- a/test/fuzztest/advancednotificationservice/servicedeleteallbyuser_fuzzer/service_deleteallbyuser_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicedeleteallbyuser_fuzzer/service_deleteallbyuser_fuzzer.cpp @@ -23,6 +23,12 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + int32_t userId = fuzzData->ConsumeIntegral(); + service->DeleteAllByUser(userId); return true; } } @@ -33,6 +39,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicedistributeoperation_fuzzer/service_distributeoperation_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicedistributeoperation_fuzzer/service_distributeoperation_fuzzer.cpp index 7e110d46b..c1bcc338b 100644 --- a/test/fuzztest/advancednotificationservice/servicedistributeoperation_fuzzer/service_distributeoperation_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicedistributeoperation_fuzzer/service_distributeoperation_fuzzer.cpp @@ -18,11 +18,18 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_operation_info.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + sptr operationInfo = ObjectBuilder::Build(fuzzData); + service->DistributeOperation(operationInfo, nullptr); return true; } } diff --git a/test/fuzztest/advancednotificationservice/serviceenabledistributedbybundle_fuzzer/service_enabledistributedbybundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceenabledistributedbybundle_fuzzer/service_enabledistributedbybundle_fuzzer.cpp index 9e8ee7340..ba0d23875 100644 --- a/test/fuzztest/advancednotificationservice/serviceenabledistributedbybundle_fuzzer/service_enabledistributedbybundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceenabledistributedbybundle_fuzzer/service_enabledistributedbybundle_fuzzer.cpp @@ -18,11 +18,19 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_bundle_option.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + sptr bundleOption = ObjectBuilder::Build(fuzzData); + bool enabled = fuzzData->ConsumeBool(); + service->EnableDistributedByBundle(bundleOption, enabled); return true; } } @@ -33,6 +41,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicegetshowbadgeenabledforbundle_fuzzer/service_getshowbadgeenabledforbundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicegetshowbadgeenabledforbundle_fuzzer/service_getshowbadgeenabledforbundle_fuzzer.cpp index 27f21b34b..7ee43f90b 100644 --- a/test/fuzztest/advancednotificationservice/servicegetshowbadgeenabledforbundle_fuzzer/service_getshowbadgeenabledforbundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicegetshowbadgeenabledforbundle_fuzzer/service_getshowbadgeenabledforbundle_fuzzer.cpp @@ -18,11 +18,20 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_bundle_option.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + sptr bundleOption = ObjectBuilder::Build(fuzzData); + bool enabled = fuzzData->ConsumeBool(); + + service->GetShowBadgeEnabledForBundle(bundleOption, enabled); return true; } } @@ -33,6 +42,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/serviceisdistributedenablebybundle_fuzzer/service_isdistributedenablebybundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceisdistributedenablebybundle_fuzzer/service_isdistributedenablebybundle_fuzzer.cpp index bf25add01..f92ee9d14 100644 --- a/test/fuzztest/advancednotificationservice/serviceisdistributedenablebybundle_fuzzer/service_isdistributedenablebybundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceisdistributedenablebybundle_fuzzer/service_isdistributedenablebybundle_fuzzer.cpp @@ -18,11 +18,19 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_bundle_option.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + sptr bundleOption = ObjectBuilder::Build(fuzzData); + bool enabled = fuzzData->ConsumeBool(); + service->IsDistributedEnableByBundle(bundleOption, enabled); return true; } } @@ -33,6 +41,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/serviceisdistributedenabledbybundle_fuzzer/service_isdistributedenabledbybundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceisdistributedenabledbybundle_fuzzer/service_isdistributedenabledbybundle_fuzzer.cpp index 88b9f0068..17940436d 100644 --- a/test/fuzztest/advancednotificationservice/serviceisdistributedenabledbybundle_fuzzer/service_isdistributedenabledbybundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceisdistributedenabledbybundle_fuzzer/service_isdistributedenabledbybundle_fuzzer.cpp @@ -18,11 +18,21 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_bundle_option.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + sptr bundleOption = ObjectBuilder::Build(fuzzData); + std::string deviceType = fuzzData->ConsumeRandomLengthString(); + bool enabled = fuzzData->ConsumeBool(); + + service->IsDistributedEnabledByBundle(bundleOption, deviceType, enabled); return true; } } @@ -33,6 +43,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/serviceissmartreminderenabled_fuzzer/service_issmartreminderenabled_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceissmartreminderenabled_fuzzer/service_issmartreminderenabled_fuzzer.cpp index 8125f9c26..0d9f9c9d3 100644 --- a/test/fuzztest/advancednotificationservice/serviceissmartreminderenabled_fuzzer/service_issmartreminderenabled_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceissmartreminderenabled_fuzzer/service_issmartreminderenabled_fuzzer.cpp @@ -23,6 +23,14 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + std::string deviceType = fuzzData->ConsumeRandomLengthString(); + bool enabled = fuzzData->ConsumeBool(); + + service->IsSmartReminderEnabled(deviceType, enabled); return true; } } @@ -33,6 +41,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.cpp index ab9560a53..eb1273efc 100644 --- a/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.cpp @@ -23,6 +23,12 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + sptr request = ObjectBuilder::Build(fuzzData); + service->PublishNotificationForIndirectProxyWithMaxCapacity(request); return true; } } @@ -33,6 +39,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/serviceremovegroupbybundle_fuzzer/service_removegroupbybundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceremovegroupbybundle_fuzzer/service_removegroupbybundle_fuzzer.cpp index 72aa484a5..f2fc66184 100644 --- a/test/fuzztest/advancednotificationservice/serviceremovegroupbybundle_fuzzer/service_removegroupbybundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceremovegroupbybundle_fuzzer/service_removegroupbybundle_fuzzer.cpp @@ -18,11 +18,20 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_bundle_option.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + sptr bundleOption = ObjectBuilder::Build(fuzzData); + std::string stringData = fuzzData->ConsumeRandomLengthString(); + + service->RemoveGroupByBundle(bundleOption, stringData); return true; } } @@ -33,6 +42,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/serviceremovenotifications_fuzzer/service_removenotifications_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceremovenotifications_fuzzer/service_removenotifications_fuzzer.cpp index 855b2ecac..1a18cd27a 100644 --- a/test/fuzztest/advancednotificationservice/serviceremovenotifications_fuzzer/service_removenotifications_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceremovenotifications_fuzzer/service_removenotifications_fuzzer.cpp @@ -23,6 +23,12 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + int32_t userId = fdp->ConsumeIntegral(); + return Notification::NotificationHelper::RemoveNotifications(userId); return true; } } @@ -33,6 +39,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicesubscribelocalliveview_fuzzer/service_subscribelocalliveview_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesubscribelocalliveview_fuzzer/service_subscribelocalliveview_fuzzer.cpp index e6da395d5..30c192ce6 100644 --- a/test/fuzztest/advancednotificationservice/servicesubscribelocalliveview_fuzzer/service_subscribelocalliveview_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesubscribelocalliveview_fuzzer/service_subscribelocalliveview_fuzzer.cpp @@ -16,6 +16,7 @@ #include #include "advanced_notification_service.h" +#include "notification_subscribe_info.h" #include "ans_permission_def.h" #include "mock_notification_request.h" @@ -23,6 +24,15 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + sptr info = new Notification::NotificationSubscribeInfo(); + bool isNative = fuzzData->ConsumeBool(); + + service->SubscribeLocalLiveView(nullptr, info, isNative); + service->SubscribeLocalLiveView(nullptr, isNative); return true; } } diff --git a/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.cpp index 3b6f9baee..5b8f6bad3 100644 --- a/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.cpp @@ -23,6 +23,11 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + service->SubscribeSelf(nullptr); return true; } } diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_operation_info.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_operation_info.h new file mode 100644 index 000000000..4bbc019da --- /dev/null +++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_operation_info.h @@ -0,0 +1,42 @@ +/* + * 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. + */ + +#ifndef MOCK_NOTIFICATION_OPERATION_INFO_BUILDER_H +#define MOCK_NOTIFICATION_OPERATION_INFO_BUILDER_H + +#include "mock_fuzz_object.h" +#include "notification_operation_info.h" + +namespace OHOS { +namespace Notification { + +template <> +NotificationOperationInfo* ObjectBuilder::Build(FuzzedDataProvider *fdp) +{ + auto operationInfo = new NotificationOperationInfo(); + operationInfo->SetActionName(fdp->ConsumeRandomLengthString()); + operationInfo->SetUserInput(fdp->ConsumeRandomLengthString()); + operationInfo->SetHashCode(fdp->ConsumeRandomLengthString()); + operationInfo->SetEventId(fdp->ConsumeRandomLengthString()); + operationInfo->SetOperationType(static_cast( + fdp->ConsumeIntegralInRange(0, 1))); + operationInfo->SetBtnIndex(fdp->ConsumeIntegral()); + + return operationInfo; +} +} // namespace Notification +} // namespace OHOS + +#endif // MOCK_NOTIFICATION_OPERATION_INFO_BUILDER_H -- Gitee From c903de2a909acb68ced743c911cd9c4efebcbd23 Mon Sep 17 00:00:00 2001 From: wangdi Date: Sat, 28 Jun 2025 18:17:12 +0800 Subject: [PATCH 2/3] add fuzz tests Signed-off-by: wangdi --- ...service_adddonotdisturbprofiles_fuzzer.cpp | 17 +++++++ .../service_cancelall_fuzzer.cpp | 12 +++++ .../service_deleteallbyuser_fuzzer.cpp | 12 +++++ .../service_distributeoperation_fuzzer.cpp | 7 +++ ...rvice_enabledistributedbybundle_fuzzer.cpp | 14 +++++ ...ce_getshowbadgeenabledforbundle_fuzzer.cpp | 15 ++++++ ...ice_isdistributedenablebybundle_fuzzer.cpp | 14 +++++ ...ce_isdistributedenabledbybundle_fuzzer.cpp | 16 ++++++ .../service_issmartreminderenabled_fuzzer.cpp | 14 +++++ ...forindirectproxywithmaxcapacity_fuzzer.cpp | 12 +++++ .../service_removegroupbybundle_fuzzer.cpp | 15 ++++++ .../service_removenotifications_fuzzer.cpp | 12 +++++ .../service_subscribelocalliveview_fuzzer.cpp | 10 ++++ .../service_subscribeself_fuzzer.cpp | 5 ++ .../mock/mock_notification_operation_info.h | 42 +++++++++++++++ .../mock/mock_notification_subscribe_info.h | 51 +++++++++++++++++++ 16 files changed, 268 insertions(+) create mode 100644 test/fuzztest/fuzz_common_base/mock/mock_notification_operation_info.h create mode 100644 test/fuzztest/fuzz_common_base/mock/mock_notification_subscribe_info.h diff --git a/test/fuzztest/advancednotificationservice/serviceadddonotdisturbprofiles_fuzzer/service_adddonotdisturbprofiles_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceadddonotdisturbprofiles_fuzzer/service_adddonotdisturbprofiles_fuzzer.cpp index 4e21d92e4..cbc82dd19 100644 --- a/test/fuzztest/advancednotificationservice/serviceadddonotdisturbprofiles_fuzzer/service_adddonotdisturbprofiles_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceadddonotdisturbprofiles_fuzzer/service_adddonotdisturbprofiles_fuzzer.cpp @@ -16,6 +16,7 @@ #include #include "advanced_notification_service.h" +#include "notification_do_not_disturb_profile.h" #include "ans_permission_def.h" #include "mock_notification_request.h" @@ -23,6 +24,16 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + std::vector> profiles; + sptr profile = + new Notification::NotificationDoNotDisturbProfile(); + profiles.emplace_back(profile); + + service->AddDoNotDisturbProfiles(profiles); return true; } } @@ -33,6 +44,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicecancelall_fuzzer/service_cancelall_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicecancelall_fuzzer/service_cancelall_fuzzer.cpp index e3198ba83..2c75c843b 100644 --- a/test/fuzztest/advancednotificationservice/servicecancelall_fuzzer/service_cancelall_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicecancelall_fuzzer/service_cancelall_fuzzer.cpp @@ -23,6 +23,12 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + std::string stringData = fuzzData->ConsumeRandomLengthString(); + service->CancelAll(stringData); return true; } } @@ -33,6 +39,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicedeleteallbyuser_fuzzer/service_deleteallbyuser_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicedeleteallbyuser_fuzzer/service_deleteallbyuser_fuzzer.cpp index 79b8e652a..0c6085de0 100644 --- a/test/fuzztest/advancednotificationservice/servicedeleteallbyuser_fuzzer/service_deleteallbyuser_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicedeleteallbyuser_fuzzer/service_deleteallbyuser_fuzzer.cpp @@ -23,6 +23,12 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + int32_t userId = fuzzData->ConsumeIntegral(); + service->DeleteAllByUser(userId); return true; } } @@ -33,6 +39,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicedistributeoperation_fuzzer/service_distributeoperation_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicedistributeoperation_fuzzer/service_distributeoperation_fuzzer.cpp index 7e110d46b..c1bcc338b 100644 --- a/test/fuzztest/advancednotificationservice/servicedistributeoperation_fuzzer/service_distributeoperation_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicedistributeoperation_fuzzer/service_distributeoperation_fuzzer.cpp @@ -18,11 +18,18 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_operation_info.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + sptr operationInfo = ObjectBuilder::Build(fuzzData); + service->DistributeOperation(operationInfo, nullptr); return true; } } diff --git a/test/fuzztest/advancednotificationservice/serviceenabledistributedbybundle_fuzzer/service_enabledistributedbybundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceenabledistributedbybundle_fuzzer/service_enabledistributedbybundle_fuzzer.cpp index 9e8ee7340..ba0d23875 100644 --- a/test/fuzztest/advancednotificationservice/serviceenabledistributedbybundle_fuzzer/service_enabledistributedbybundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceenabledistributedbybundle_fuzzer/service_enabledistributedbybundle_fuzzer.cpp @@ -18,11 +18,19 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_bundle_option.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + sptr bundleOption = ObjectBuilder::Build(fuzzData); + bool enabled = fuzzData->ConsumeBool(); + service->EnableDistributedByBundle(bundleOption, enabled); return true; } } @@ -33,6 +41,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicegetshowbadgeenabledforbundle_fuzzer/service_getshowbadgeenabledforbundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicegetshowbadgeenabledforbundle_fuzzer/service_getshowbadgeenabledforbundle_fuzzer.cpp index 27f21b34b..7ee43f90b 100644 --- a/test/fuzztest/advancednotificationservice/servicegetshowbadgeenabledforbundle_fuzzer/service_getshowbadgeenabledforbundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicegetshowbadgeenabledforbundle_fuzzer/service_getshowbadgeenabledforbundle_fuzzer.cpp @@ -18,11 +18,20 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_bundle_option.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + sptr bundleOption = ObjectBuilder::Build(fuzzData); + bool enabled = fuzzData->ConsumeBool(); + + service->GetShowBadgeEnabledForBundle(bundleOption, enabled); return true; } } @@ -33,6 +42,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/serviceisdistributedenablebybundle_fuzzer/service_isdistributedenablebybundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceisdistributedenablebybundle_fuzzer/service_isdistributedenablebybundle_fuzzer.cpp index bf25add01..f92ee9d14 100644 --- a/test/fuzztest/advancednotificationservice/serviceisdistributedenablebybundle_fuzzer/service_isdistributedenablebybundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceisdistributedenablebybundle_fuzzer/service_isdistributedenablebybundle_fuzzer.cpp @@ -18,11 +18,19 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_bundle_option.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + sptr bundleOption = ObjectBuilder::Build(fuzzData); + bool enabled = fuzzData->ConsumeBool(); + service->IsDistributedEnableByBundle(bundleOption, enabled); return true; } } @@ -33,6 +41,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/serviceisdistributedenabledbybundle_fuzzer/service_isdistributedenabledbybundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceisdistributedenabledbybundle_fuzzer/service_isdistributedenabledbybundle_fuzzer.cpp index 88b9f0068..17940436d 100644 --- a/test/fuzztest/advancednotificationservice/serviceisdistributedenabledbybundle_fuzzer/service_isdistributedenabledbybundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceisdistributedenabledbybundle_fuzzer/service_isdistributedenabledbybundle_fuzzer.cpp @@ -18,11 +18,21 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_bundle_option.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + sptr bundleOption = ObjectBuilder::Build(fuzzData); + std::string deviceType = fuzzData->ConsumeRandomLengthString(); + bool enabled = fuzzData->ConsumeBool(); + + service->IsDistributedEnabledByBundle(bundleOption, deviceType, enabled); return true; } } @@ -33,6 +43,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/serviceissmartreminderenabled_fuzzer/service_issmartreminderenabled_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceissmartreminderenabled_fuzzer/service_issmartreminderenabled_fuzzer.cpp index 8125f9c26..0d9f9c9d3 100644 --- a/test/fuzztest/advancednotificationservice/serviceissmartreminderenabled_fuzzer/service_issmartreminderenabled_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceissmartreminderenabled_fuzzer/service_issmartreminderenabled_fuzzer.cpp @@ -23,6 +23,14 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + std::string deviceType = fuzzData->ConsumeRandomLengthString(); + bool enabled = fuzzData->ConsumeBool(); + + service->IsSmartReminderEnabled(deviceType, enabled); return true; } } @@ -33,6 +41,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.cpp index ab9560a53..eb1273efc 100644 --- a/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.cpp @@ -23,6 +23,12 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + sptr request = ObjectBuilder::Build(fuzzData); + service->PublishNotificationForIndirectProxyWithMaxCapacity(request); return true; } } @@ -33,6 +39,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/serviceremovegroupbybundle_fuzzer/service_removegroupbybundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceremovegroupbybundle_fuzzer/service_removegroupbybundle_fuzzer.cpp index 72aa484a5..f2fc66184 100644 --- a/test/fuzztest/advancednotificationservice/serviceremovegroupbybundle_fuzzer/service_removegroupbybundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceremovegroupbybundle_fuzzer/service_removegroupbybundle_fuzzer.cpp @@ -18,11 +18,20 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_bundle_option.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + sptr bundleOption = ObjectBuilder::Build(fuzzData); + std::string stringData = fuzzData->ConsumeRandomLengthString(); + + service->RemoveGroupByBundle(bundleOption, stringData); return true; } } @@ -33,6 +42,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/serviceremovenotifications_fuzzer/service_removenotifications_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceremovenotifications_fuzzer/service_removenotifications_fuzzer.cpp index 855b2ecac..1a18cd27a 100644 --- a/test/fuzztest/advancednotificationservice/serviceremovenotifications_fuzzer/service_removenotifications_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceremovenotifications_fuzzer/service_removenotifications_fuzzer.cpp @@ -23,6 +23,12 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + int32_t userId = fdp->ConsumeIntegral(); + return Notification::NotificationHelper::RemoveNotifications(userId); return true; } } @@ -33,6 +39,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicesubscribelocalliveview_fuzzer/service_subscribelocalliveview_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesubscribelocalliveview_fuzzer/service_subscribelocalliveview_fuzzer.cpp index e6da395d5..1d7b92343 100644 --- a/test/fuzztest/advancednotificationservice/servicesubscribelocalliveview_fuzzer/service_subscribelocalliveview_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesubscribelocalliveview_fuzzer/service_subscribelocalliveview_fuzzer.cpp @@ -16,6 +16,7 @@ #include #include "advanced_notification_service.h" +#include "notification_subscribe_info.h" #include "ans_permission_def.h" #include "mock_notification_request.h" @@ -23,6 +24,15 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + sptr info = ObjectBuilder::Build(fuzzData); + bool isNative = fuzzData->ConsumeBool(); + + service->SubscribeLocalLiveView(nullptr, info, isNative); + service->SubscribeLocalLiveView(nullptr, isNative); return true; } } diff --git a/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.cpp index 3b6f9baee..5b8f6bad3 100644 --- a/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.cpp @@ -23,6 +23,11 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + service->SubscribeSelf(nullptr); return true; } } diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_operation_info.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_operation_info.h new file mode 100644 index 000000000..4bbc019da --- /dev/null +++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_operation_info.h @@ -0,0 +1,42 @@ +/* + * 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. + */ + +#ifndef MOCK_NOTIFICATION_OPERATION_INFO_BUILDER_H +#define MOCK_NOTIFICATION_OPERATION_INFO_BUILDER_H + +#include "mock_fuzz_object.h" +#include "notification_operation_info.h" + +namespace OHOS { +namespace Notification { + +template <> +NotificationOperationInfo* ObjectBuilder::Build(FuzzedDataProvider *fdp) +{ + auto operationInfo = new NotificationOperationInfo(); + operationInfo->SetActionName(fdp->ConsumeRandomLengthString()); + operationInfo->SetUserInput(fdp->ConsumeRandomLengthString()); + operationInfo->SetHashCode(fdp->ConsumeRandomLengthString()); + operationInfo->SetEventId(fdp->ConsumeRandomLengthString()); + operationInfo->SetOperationType(static_cast( + fdp->ConsumeIntegralInRange(0, 1))); + operationInfo->SetBtnIndex(fdp->ConsumeIntegral()); + + return operationInfo; +} +} // namespace Notification +} // namespace OHOS + +#endif // MOCK_NOTIFICATION_OPERATION_INFO_BUILDER_H diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_subscribe_info.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_subscribe_info.h new file mode 100644 index 000000000..fc4ed2e3d --- /dev/null +++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_subscribe_info.h @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#ifndef MOCK_NOTIFICATION_SUBSCRIBE_INFO_BUILDER_H +#define MOCK_NOTIFICATION_SUBSCRIBE_INFO_BUILDER_H + +#include "mock_fuzz_object.h" +#include "notification_subscribe_info.h" +#include "notification_constant.h" + +namespace OHOS { +namespace Notification { + +template <> +NotificationSubscribeInfo* ObjectBuilder::Build(FuzzedDataProvider *fdp) +{ + auto subscribeInfo = new NotificationSubscribeInfo(); + + subscribeInfo->AddAppName(fdp->->ConsumeRandomLengthString()); + subscribeInfo->AddAppUserId(fdp->ConsumeIntegral()); + subscribeInfo->AddDeviceType(fdp->->ConsumeRandomLengthString()); + subscribeInfo->SetSubscriberUid(fdp->ConsumeIntegral()); + subscribeInfo->SetFilterType(fdp->ConsumeIntegral()); + subscribeInfo->SetNeedNotifyResponse(fdp->ConsumeBool()); + + std::vector slotTypes; + auto slotTypeCnt = fdp->ConsumeIntegralInRange(0, 6); + for (auto i = 0; i < slotTypeCnt; ++i) { + auto slotType = static_cast( + fdp->ConsumeIntegralInRange(0, 7)); + slotTypes.push_back(slotType); + } + subscribeInfo->SetSlotTypes(slotTypes); + return subscribeInfo; +} +} // namespace Notification +} // namespace OHOS + +#endif // MOCK_NOTIFICATION_SUBSCRIBE_INFO_BUILDER_H -- Gitee From 1b81b1ef4b0ce59aa1802e186b8be1ce745638ee Mon Sep 17 00:00:00 2001 From: wangdi Date: Mon, 30 Jun 2025 20:11:50 +0800 Subject: [PATCH 3/3] add fuzz tests Signed-off-by: wangdi --- .../advancednotificationservice/BUILD.gn | 2 - ...service_adddonotdisturbprofiles_fuzzer.cpp | 1 + .../servicedeleteallbyuser_fuzzer/corpus/init | 2 +- .../BUILD.gn | 32 ------------ .../corpus/init | 13 ----- .../project.xml | 25 ---------- ...forindirectproxywithmaxcapacity_fuzzer.cpp | 50 ------------------- ...shforindirectproxywithmaxcapacity_fuzzer.h | 24 --------- .../service_removenotifications_fuzzer.cpp | 9 +++- .../service_subscribelocalliveview_fuzzer.cpp | 3 +- .../servicesubscribeself_fuzzer/BUILD.gn | 32 ------------ .../servicesubscribeself_fuzzer/corpus/init | 13 ----- .../servicesubscribeself_fuzzer/project.xml | 25 ---------- .../service_subscribeself_fuzzer.cpp | 43 ---------------- .../service_subscribeself_fuzzer.h | 24 --------- .../mock_notification_donotdisturb_profile.h | 1 - .../mock/mock_notification_operation_info.h | 3 +- .../mock/mock_notification_subscribe_info.h | 8 +-- 18 files changed, 16 insertions(+), 294 deletions(-) delete mode 100644 test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/corpus/init delete mode 100644 test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/project.xml delete mode 100644 test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.cpp delete mode 100644 test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.h delete mode 100644 test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/corpus/init delete mode 100644 test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/project.xml delete mode 100644 test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.cpp delete mode 100644 test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.h diff --git a/test/fuzztest/advancednotificationservice/BUILD.gn b/test/fuzztest/advancednotificationservice/BUILD.gn index 544826e87..c91e375d7 100644 --- a/test/fuzztest/advancednotificationservice/BUILD.gn +++ b/test/fuzztest/advancednotificationservice/BUILD.gn @@ -36,13 +36,11 @@ group("fuzztest") { "servicedeleteallbyuser_fuzzer:ServiceDeleteAllByUserFuzzTest", "serviceenabledistributedbybundle_fuzzer:ServiceEnableDistributedByBundleFuzzTest", "servicesubscribelocalliveview_fuzzer:ServiceSubscribeLocalLiveViewFuzzTest", - "servicesubscribeself_fuzzer:ServiceSubscribeSelfFuzzTest", "serviceremovegroupbybundle_fuzzer:ServiceRemoveGroupByBundleFuzzTest", "serviceadddonotdisturbprofiles_fuzzer:ServiceAddDoNotDisturbProfilesFuzzTest", "serviceisdistributedenablebybundle_fuzzer:ServiceIsDistributedEnableByBundleFuzzTest", "serviceissmartreminderenabled_fuzzer:ServiceIsSmartReminderEnabledFuzzTest", "serviceremovenotifications_fuzzer:ServiceRemoveNotificationsFuzzTest", - "servicepublishforindirectproxywithmaxcapacity_fuzzer:ServicePublishForIndirectProxyWithMaxCapacityFuzzTest", "serviceissupporttemplate_fuzzer:ServiceIsSupportTemplateFuzzTest", "servicecanpublishasbundle_fuzzer:ServiceCanPublishAsBundleFuzzTest", "serviceunsubscribe_fuzzer:ServiceUnsubscribeFuzzTest", diff --git a/test/fuzztest/advancednotificationservice/serviceadddonotdisturbprofiles_fuzzer/service_adddonotdisturbprofiles_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceadddonotdisturbprofiles_fuzzer/service_adddonotdisturbprofiles_fuzzer.cpp index 307d4453b..95b3088b0 100644 --- a/test/fuzztest/advancednotificationservice/serviceadddonotdisturbprofiles_fuzzer/service_adddonotdisturbprofiles_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceadddonotdisturbprofiles_fuzzer/service_adddonotdisturbprofiles_fuzzer.cpp @@ -19,6 +19,7 @@ #include "notification_do_not_disturb_profile.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_donotdisturb_profile.h" namespace OHOS { namespace Notification { diff --git a/test/fuzztest/advancednotificationservice/servicedeleteallbyuser_fuzzer/corpus/init b/test/fuzztest/advancednotificationservice/servicedeleteallbyuser_fuzzer/corpus/init index d9719cafa..d6a927d54 100644 --- a/test/fuzztest/advancednotificationservice/servicedeleteallbyuser_fuzzer/corpus/init +++ b/test/fuzztest/advancednotificationservice/servicedeleteallbyuser_fuzzer/corpus/init @@ -10,4 +10,4 @@ # 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. -FUZZ \ No newline at end of file +100 \ No newline at end of file diff --git a/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/BUILD.gn b/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/BUILD.gn deleted file mode 100644 index 333149ed2..000000000 --- a/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/BUILD.gn +++ /dev/null @@ -1,32 +0,0 @@ -# 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. - - -#####################hydra-fuzz################### -import("../advancednotificationservice_fuzztest_common.gni") # 导入公共配置 - -##############################fuzztest########################################## -advancednotificationservice_fuzztest_target("ServicePublishForIndirectProxyWithMaxCapacityFuzzTest") { - sources_value = [ "service_publishforindirectproxywithmaxcapacity_fuzzer.cpp" ] - fuzz_config_file_value = - "${component_path}/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer" - deps_value = [] # 如果不需要额外依赖,可以留空 - common_deps_value = common_deps # 使用公共依赖 -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":ServicePublishForIndirectProxyWithMaxCapacityFuzzTest" ] -} -############################################################################### diff --git a/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/corpus/init b/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/corpus/init deleted file mode 100644 index d9719cafa..000000000 --- a/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/corpus/init +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (c) 2023 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. -FUZZ \ No newline at end of file diff --git a/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/project.xml b/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/project.xml deleted file mode 100644 index 226522bd2..000000000 --- a/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 10000 - - 300 - - 4096 - - diff --git a/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.cpp deleted file mode 100644 index eb1273efc..000000000 --- a/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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 "service_publishforindirectproxywithmaxcapacity_fuzzer.h" - -#include -#include "advanced_notification_service.h" -#include "ans_permission_def.h" -#include "mock_notification_request.h" - -namespace OHOS { -namespace Notification { - bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) - { - auto service = AdvancedNotificationService::GetInstance(); - service->InitPublishProcess(); - service->CreateDialogManager(); - - sptr request = ObjectBuilder::Build(fuzzData); - service->PublishNotificationForIndirectProxyWithMaxCapacity(request); - return true; - } -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - FuzzedDataProvider fdp(data, size); - std::vector requestPermission = { - OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, - OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, - OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION - }; - MockRandomToken(&fdp, requestPermission); - OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); - return 0; -} diff --git a/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.h b/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.h deleted file mode 100644 index c6edfd69d..000000000 --- a/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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. - */ - -#ifndef TEST_FUZZTEST_ADVANCEDNOTIFICATIONSERVICE_FUZZER_SERVICE_PUBLISHFORINDIRECTPROXYWITHMAXCAPACITY_FUZZER_H -#define TEST_FUZZTEST_ADVANCEDNOTIFICATIONSERVICE_FUZZER_SERVICE_PUBLISHFORINDIRECTPROXYWITHMAXCAPACITY_FUZZER_H - -#include "fuzz_common_base.h" -#include - -#define FUZZ_PROJECT_NAME "advancednotificationservicepublishforindirectproxywithmaxcapacity_fuzzer" - -#endif // TEST_FUZZTEST_ADVANCEDNOTIFICATIONSERVICE_FUZZER_SERVICE_PUBLISHFORINDIRECTPROXYWITHMAXCAPACITY_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/advancednotificationservice/serviceremovenotifications_fuzzer/service_removenotifications_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceremovenotifications_fuzzer/service_removenotifications_fuzzer.cpp index 1a18cd27a..8ae2926aa 100644 --- a/test/fuzztest/advancednotificationservice/serviceremovenotifications_fuzzer/service_removenotifications_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceremovenotifications_fuzzer/service_removenotifications_fuzzer.cpp @@ -27,8 +27,13 @@ namespace Notification { service->InitPublishProcess(); service->CreateDialogManager(); - int32_t userId = fdp->ConsumeIntegral(); - return Notification::NotificationHelper::RemoveNotifications(userId); + int32_t removeReason = fuzzData->ConsumeIntegral(); + std::vector keys; + size_t numKeys = fuzzData->ConsumeIntegralInRange(0, 6); + for (size_t i = 0; i < numKeys; ++i) { + keys.emplace_back(fuzzData->ConsumeRandomLengthString()); + } + service->RemoveNotifications(keys, removeReason); return true; } } diff --git a/test/fuzztest/advancednotificationservice/servicesubscribelocalliveview_fuzzer/service_subscribelocalliveview_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesubscribelocalliveview_fuzzer/service_subscribelocalliveview_fuzzer.cpp index 4d58b6afd..cefad9391 100644 --- a/test/fuzztest/advancednotificationservice/servicesubscribelocalliveview_fuzzer/service_subscribelocalliveview_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesubscribelocalliveview_fuzzer/service_subscribelocalliveview_fuzzer.cpp @@ -19,6 +19,7 @@ #include "notification_subscribe_info.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_subscribe_info.h" namespace OHOS { namespace Notification { @@ -28,7 +29,7 @@ namespace Notification { service->InitPublishProcess(); service->CreateDialogManager(); - sptr info = ObjectBuilder::Build(fuzzData); + sptr info = ObjectBuilder::Build(fuzzData); bool isNative = fuzzData->ConsumeBool(); service->SubscribeLocalLiveView(nullptr, info, isNative); service->SubscribeLocalLiveView(nullptr, isNative); diff --git a/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/BUILD.gn b/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/BUILD.gn deleted file mode 100644 index cfea9a13f..000000000 --- a/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/BUILD.gn +++ /dev/null @@ -1,32 +0,0 @@ -# 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. - - -#####################hydra-fuzz################### -import("../advancednotificationservice_fuzztest_common.gni") # 导入公共配置 - -##############################fuzztest########################################## -advancednotificationservice_fuzztest_target("ServiceSubscribeSelfFuzzTest") { - sources_value = [ "service_subscribeself_fuzzer.cpp" ] - fuzz_config_file_value = - "${component_path}/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer" - deps_value = [] # 如果不需要额外依赖,可以留空 - common_deps_value = common_deps # 使用公共依赖 -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":ServiceSubscribeSelfFuzzTest" ] -} -############################################################################### diff --git a/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/corpus/init b/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/corpus/init deleted file mode 100644 index d9719cafa..000000000 --- a/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/corpus/init +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (c) 2023 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. -FUZZ \ No newline at end of file diff --git a/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/project.xml b/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/project.xml deleted file mode 100644 index 226522bd2..000000000 --- a/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 10000 - - 300 - - 4096 - - diff --git a/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.cpp deleted file mode 100644 index 5b8f6bad3..000000000 --- a/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 "service_subscribeself_fuzzer.h" - -#include -#include "advanced_notification_service.h" -#include "ans_permission_def.h" -#include "mock_notification_request.h" - -namespace OHOS { -namespace Notification { - bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) - { - auto service = AdvancedNotificationService::GetInstance(); - service->InitPublishProcess(); - service->CreateDialogManager(); - - service->SubscribeSelf(nullptr); - return true; - } -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - FuzzedDataProvider fdp(data, size); - OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); - return 0; -} diff --git a/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.h b/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.h deleted file mode 100644 index f6b29a302..000000000 --- a/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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. - */ - -#ifndef TEST_FUZZTEST_ADVANCEDNOTIFICATIONSERVICE_FUZZER_SERVICE_SUBSCRIBESELF_FUZZER_H -#define TEST_FUZZTEST_ADVANCEDNOTIFICATIONSERVICE_FUZZER_SERVICE_SUBSCRIBESELF_FUZZER_H - -#include "fuzz_common_base.h" -#include - -#define FUZZ_PROJECT_NAME "advancednotificationservicesubscribeself_fuzzer" - -#endif // TEST_FUZZTEST_ADVANCEDNOTIFICATIONSERVICE_FUZZER_SERVICE_SUBSCRIBESELF_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_donotdisturb_profile.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_donotdisturb_profile.h index 6e4f2a0ee..c79f2b1df 100644 --- a/test/fuzztest/fuzz_common_base/mock/mock_notification_donotdisturb_profile.h +++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_donotdisturb_profile.h @@ -17,7 +17,6 @@ #define MOCK_NOTIFICATION_DONOT_DISTURB_PROFILE_BUILDER_H #include "mock_fuzz_object.h" -#include "mock_" #include "notification_bundle_option.h" #include "notification_do_not_disturb_profile.h" diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_operation_info.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_operation_info.h index 4bbc019da..c0d9d3ccf 100644 --- a/test/fuzztest/fuzz_common_base/mock/mock_notification_operation_info.h +++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_operation_info.h @@ -30,9 +30,8 @@ NotificationOperationInfo* ObjectBuilder::Build(Fuzze operationInfo->SetUserInput(fdp->ConsumeRandomLengthString()); operationInfo->SetHashCode(fdp->ConsumeRandomLengthString()); operationInfo->SetEventId(fdp->ConsumeRandomLengthString()); - operationInfo->SetOperationType(static_cast( + operationInfo->SetOperationType(static_cast( fdp->ConsumeIntegralInRange(0, 1))); - operationInfo->SetBtnIndex(fdp->ConsumeIntegral()); return operationInfo; } diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_subscribe_info.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_subscribe_info.h index 45480c285..f7181b100 100644 --- a/test/fuzztest/fuzz_common_base/mock/mock_notification_subscribe_info.h +++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_subscribe_info.h @@ -28,16 +28,16 @@ NotificationSubscribeInfo* ObjectBuilder::Build(Fuzze { auto subscribeInfo = new NotificationSubscribeInfo(); - subscribeInfo->AddAppName(fdp->->ConsumeRandomLengthString()); + subscribeInfo->AddAppName(fdp->ConsumeRandomLengthString()); subscribeInfo->AddAppUserId(fdp->ConsumeIntegral()); - subscribeInfo->AddDeviceType(fdp->->ConsumeRandomLengthString()); + subscribeInfo->AddDeviceType(fdp->ConsumeRandomLengthString()); subscribeInfo->SetSubscriberUid(fdp->ConsumeIntegral()); subscribeInfo->SetFilterType(fdp->ConsumeIntegral()); subscribeInfo->SetNeedNotifyResponse(fdp->ConsumeBool()); std::vector slotTypes; - auto slotTypeCnt = fdp->ConsumeIntegralInRange(0, 6); - for (auto i = 0; i < slotTypeCnt; ++i) { + size_t slotTypeCnt = fdp->ConsumeIntegralInRange(0, 6); + for (size_t i = 0; i < slotTypeCnt; ++i) { auto slotType = static_cast( fdp->ConsumeIntegralInRange(0, 7)); slotTypes.push_back(slotType); -- Gitee