diff --git a/test/fuzztest/advancednotificationservice/BUILD.gn b/test/fuzztest/advancednotificationservice/BUILD.gn index 544826e8755af8d92fd5ab95d099d2bfd0870973..c91e375d7c58ce24a41897bf139c39c39a6ecca6 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 4e21d92e4a57cded9c0c03734df87dfda15289e4..95b3088b0db5df21da3e528e4862ec5439f19446 100644 --- a/test/fuzztest/advancednotificationservice/serviceadddonotdisturbprofiles_fuzzer/service_adddonotdisturbprofiles_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceadddonotdisturbprofiles_fuzzer/service_adddonotdisturbprofiles_fuzzer.cpp @@ -16,13 +16,27 @@ #include #include "advanced_notification_service.h" +#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 { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + std::vector> profiles; + size_t numProfiles = fuzzData->ConsumeIntegralInRange(0, 6); + for (size_t i = 0; i < numProfiles; ++i) { + sptr profile = + ObjectBuilder::Build(fuzzData); + profiles.push_back(profile); + } + service->AddDoNotDisturbProfiles(profiles); return true; } } @@ -33,6 +47,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 e3198ba83178431c37753688af73fae127768132..2c75c843bf8704b8f2acd8d3ea96f8e0ece4559d 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/corpus/init b/test/fuzztest/advancednotificationservice/servicedeleteallbyuser_fuzzer/corpus/init index d9719cafab50ed61d354cfa865b56390a0df320f..d6a927d5409f58fd33b8e793135561bca72e8409 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/servicedeleteallbyuser_fuzzer/service_deleteallbyuser_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicedeleteallbyuser_fuzzer/service_deleteallbyuser_fuzzer.cpp index 79b8e652af4fdf862cf4b973d96c6cf642fe6378..0c6085de017b1f06b3209e208db5c11a1611a67e 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 7e110d46bf23756b8c0d5a51d17f07ae6e3b7f3b..c1bcc338bf5dbf400612d76e9f7170f6bfb23719 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 9e8ee7340e5b8a497fe31d2f8b69f42da5681fe8..3b49c92d7778fb3c3d880b6b01fca9f93ed12239 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 27f21b34b1e121ff6c4e551370983b1433db1313..7ee43f90bde0d0a7b60b61e5a950dfbda54dde72 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 bf25add0163d005dc0b882ec99abba4923384c51..f92ee9d142c9659e9afba465d002020a2781efbd 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 88b9f0068baf692a5b828c513221b9f6aa69b88d..17940436dd57f00dcfd4a16d86fe30cc4ba2b95b 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 8125f9c2625abb78abb1bd37a4c9070787a60934..0d9f9c9d3e5d6d13d43137d5ac59410613a136cc 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/BUILD.gn b/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/BUILD.gn deleted file mode 100644 index 333149ed2d097d9dfe4acc6d22af121e8651996b..0000000000000000000000000000000000000000 --- 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 d9719cafab50ed61d354cfa865b56390a0df320f..0000000000000000000000000000000000000000 --- 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 226522bd2ad3eaf2db4f710f1924d82d2912c235..0000000000000000000000000000000000000000 --- a/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 10000 - - 300 - - 4096 - - diff --git a/test/fuzztest/advancednotificationservice/serviceremovegroupbybundle_fuzzer/service_removegroupbybundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceremovegroupbybundle_fuzzer/service_removegroupbybundle_fuzzer.cpp index 72aa484a592767734b92d8c54ad3aaf2c5bab824..f2fc6618491db851e1d69279b4be290c57277fd6 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 855b2ecac359525f2f68dc4c4215b9c972b42e0a..8ae2926aaece7ac938ce4d059ce686efde8b54ad 100644 --- a/test/fuzztest/advancednotificationservice/serviceremovenotifications_fuzzer/service_removenotifications_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceremovenotifications_fuzzer/service_removenotifications_fuzzer.cpp @@ -23,6 +23,17 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + 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; } } @@ -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/servicesubscribelocalliveview_fuzzer/service_subscribelocalliveview_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesubscribelocalliveview_fuzzer/service_subscribelocalliveview_fuzzer.cpp index e6da395d5996db0a2afdb86d826ca424569fb0c8..cefad9391dcd4e2095d9a4bbd7eadb99746ede38 100644 --- a/test/fuzztest/advancednotificationservice/servicesubscribelocalliveview_fuzzer/service_subscribelocalliveview_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesubscribelocalliveview_fuzzer/service_subscribelocalliveview_fuzzer.cpp @@ -16,13 +16,23 @@ #include #include "advanced_notification_service.h" +#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 { 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/BUILD.gn b/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/BUILD.gn deleted file mode 100644 index cfea9a13fa8b6bd5851503ccdbd5312c9716fcfb..0000000000000000000000000000000000000000 --- 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 d9719cafab50ed61d354cfa865b56390a0df320f..0000000000000000000000000000000000000000 --- 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 226522bd2ad3eaf2db4f710f1924d82d2912c235..0000000000000000000000000000000000000000 --- 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.h b/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.h deleted file mode 100644 index f6b29a302d7006b2ab04ecdeebf23179fc1cae33..0000000000000000000000000000000000000000 --- 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/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.cpp b/test/fuzztest/fuzz_common_base/mock/mock_notification_donotdisturb_profile.h similarity index 39% rename from test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.cpp rename to test/fuzztest/fuzz_common_base/mock/mock_notification_donotdisturb_profile.h index ab9560a53ff57fe377bc8a6b02e1b7c2831e00e2..c79f2b1df0fdb78da8c6ffeef17df48da900c676 100644 --- a/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.cpp +++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_donotdisturb_profile.h @@ -12,27 +12,33 @@ * 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" +#ifndef MOCK_NOTIFICATION_DONOT_DISTURB_PROFILE_BUILDER_H +#define MOCK_NOTIFICATION_DONOT_DISTURB_PROFILE_BUILDER_H + +#include "mock_fuzz_object.h" +#include "notification_bundle_option.h" +#include "notification_do_not_disturb_profile.h" namespace OHOS { namespace Notification { - bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) - { - return true; - } -} -} -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +template <> +NotificationDoNotDisturbProfile* ObjectBuilder::Build(FuzzedDataProvider *fdp) { - /* Run your code on data */ - FuzzedDataProvider fdp(data, size); - OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); - return 0; + int64_t id = fdp->ConsumeIntegral(); + std::string profileName = fdp->ConsumeRandomLengthString(); + std::vector trustList; + size_t listSize = fdp->ConsumeIntegralInRange(0, 10); + for (size_t i = 0; i < listSize; ++i) { + std::unique_ptr bundleOption( + ObjectBuilder::Build(fdp)); + trustList.push_back(*bundleOption); + } + return new NotificationDoNotDisturbProfile(id, profileName, trustList); } + +} // namespace Notification +} // namespace OHOS + +#endif // MOCK_NOTIFICATION_DONOT_DISTURB_PROFILE_BUILDER_H diff --git a/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.cpp b/test/fuzztest/fuzz_common_base/mock/mock_notification_operation_info.h similarity index 43% rename from test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.cpp rename to test/fuzztest/fuzz_common_base/mock/mock_notification_operation_info.h index 3b6f9baeeb62eef237972235608ea07814e0018f..c0d9d3ccffca1d0679226f1b81ccf10bd2422cf8 100644 --- a/test/fuzztest/advancednotificationservice/servicesubscribeself_fuzzer/service_subscribeself_fuzzer.cpp +++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_operation_info.h @@ -12,27 +12,30 @@ * 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" +#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 { - bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) - { - return true; - } -} -} -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +template <> +NotificationOperationInfo* ObjectBuilder::Build(FuzzedDataProvider *fdp) { - /* Run your code on data */ - FuzzedDataProvider fdp(data, size); - OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); - return 0; + 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))); + + return operationInfo; } +} // namespace Notification +} // namespace OHOS + +#endif // MOCK_NOTIFICATION_OPERATION_INFO_BUILDER_H diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_request.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_request.h index 206a6a62d1cea14a3a744684fdbc46d9966909bb..923ec46f0f3e1cdf9b8cea1e61844d6f86fedf2c 100644 --- a/test/fuzztest/fuzz_common_base/mock/mock_notification_request.h +++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_request.h @@ -169,8 +169,6 @@ NotificationRequest* ObjectBuilder::Build(FuzzedDataProvide return request; } - - } // namespace Notification } // namespace OHOS diff --git a/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_subscribe_info.h similarity index 31% rename from test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.h rename to test/fuzztest/fuzz_common_base/mock/mock_notification_subscribe_info.h index c6edfd69d5d610b8c03137496c59ffe93d2b9cf4..f7181b100f62515a57d2e516a731131b835c1e96 100644 --- a/test/fuzztest/advancednotificationservice/servicepublishforindirectproxywithmaxcapacity_fuzzer/service_publishforindirectproxywithmaxcapacity_fuzzer.h +++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_subscribe_info.h @@ -13,12 +13,40 @@ * limitations under the License. */ -#ifndef TEST_FUZZTEST_ADVANCEDNOTIFICATIONSERVICE_FUZZER_SERVICE_PUBLISHFORINDIRECTPROXYWITHMAXCAPACITY_FUZZER_H -#define TEST_FUZZTEST_ADVANCEDNOTIFICATIONSERVICE_FUZZER_SERVICE_PUBLISHFORINDIRECTPROXYWITHMAXCAPACITY_FUZZER_H +#ifndef MOCK_NOTIFICATION_SUBSCRIBE_INFO_BUILDER_H +#define MOCK_NOTIFICATION_SUBSCRIBE_INFO_BUILDER_H -#include "fuzz_common_base.h" -#include +#include "mock_fuzz_object.h" +#include "notification_subscribe_info.h" +#include "notification_constant.h" -#define FUZZ_PROJECT_NAME "advancednotificationservicepublishforindirectproxywithmaxcapacity_fuzzer" +namespace OHOS { +namespace Notification { -#endif // TEST_FUZZTEST_ADVANCEDNOTIFICATIONSERVICE_FUZZER_SERVICE_PUBLISHFORINDIRECTPROXYWITHMAXCAPACITY_FUZZER_H \ No newline at end of file +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; + 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); + } + subscribeInfo->SetSlotTypes(slotTypes); + return subscribeInfo; +} + +} // namespace Notification +} // namespace OHOS + +#endif // MOCK_NOTIFICATION_SUBSCRIBE_INFO_BUILDER_H