diff --git a/test/fuzztest/advancednotificationservice/servicegetnotificationrequestbyhashcode_fuzzer/service_getnotificationrequestbyhashcode_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicegetnotificationrequestbyhashcode_fuzzer/service_getnotificationrequestbyhashcode_fuzzer.cpp index eb3146dfcabf83bbc0113d45e60d76c9319749b2..592cd50865c256d12877026c591a143720e3ca9a 100644 --- a/test/fuzztest/advancednotificationservice/servicegetnotificationrequestbyhashcode_fuzzer/service_getnotificationrequestbyhashcode_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicegetnotificationrequestbyhashcode_fuzzer/service_getnotificationrequestbyhashcode_fuzzer.cpp @@ -23,6 +23,10 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + std::string hashCode = fuzzData->ConsumeRandomLengthString(); + sptr notificationRequest; + service->GetNotificationRequestByHashCode(hashCode, notificationRequest); return true; } } @@ -33,6 +37,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/servicegetslotbybundle_fuzzer/service_getslotbybundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicegetslotbybundle_fuzzer/service_getslotbybundle_fuzzer.cpp index 91f472ca6e2faf5aeeefbd112a29435074dbba93..a3c1b6d230828d8d6dfb9948c6392c3d5630a330 100644 --- a/test/fuzztest/advancednotificationservice/servicegetslotbybundle_fuzzer/service_getslotbybundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicegetslotbybundle_fuzzer/service_getslotbybundle_fuzzer.cpp @@ -17,12 +17,16 @@ #include #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(); + sptr bundleOption = ObjectBuilder::Build(fuzzData); + std::vector> slots; + service->GetSlotsByBundle(bundleOption, slots); return true; } } @@ -33,6 +37,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/servicegetsyncnotificationenabledwithoutapp_fuzzer/service_getsyncnotificationenabledwithoutapp_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicegetsyncnotificationenabledwithoutapp_fuzzer/service_getsyncnotificationenabledwithoutapp_fuzzer.cpp index 216c80c33b3031cc49ac88e75555b30c8b6c28e5..02aeac804873ef11529b73cc536590e3b66d145f 100644 --- a/test/fuzztest/advancednotificationservice/servicegetsyncnotificationenabledwithoutapp_fuzzer/service_getsyncnotificationenabledwithoutapp_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicegetsyncnotificationenabledwithoutapp_fuzzer/service_getsyncnotificationenabledwithoutapp_fuzzer.cpp @@ -23,6 +23,10 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + int32_t userId = fuzzData->ConsumeIntegral(); + bool enabled = fuzzData->ConsumeBool(); + service->GetSyncNotificationEnabledWithoutApp(userId, enabled); return true; } } @@ -33,6 +37,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/servicepublishasbundle_fuzzer/service_publishasbundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicepublishasbundle_fuzzer/service_publishasbundle_fuzzer.cpp index 5554a30432a52726e3a2394b1980f71e5bc08e4e..80b24d4e36f921f66506419cd2989d6ab1fad8fc 100644 --- a/test/fuzztest/advancednotificationservice/servicepublishasbundle_fuzzer/service_publishasbundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicepublishasbundle_fuzzer/service_publishasbundle_fuzzer.cpp @@ -23,6 +23,10 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + sptr request = ObjectBuilder::Build(fuzzData); + std::string representativeBundle = fuzzData->ConsumeRandomLengthString(); + service->PublishAsBundle(request, representativeBundle); return true; } } @@ -33,6 +37,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/serviceregisterpushcallback_fuzzer/service_registerpushcallback_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceregisterpushcallback_fuzzer/service_registerpushcallback_fuzzer.cpp index 56f10cddab413098edd7177d66002bfe397cd0f7..c9776ac46343726cf8d7fea609d760215c68e25d 100644 --- a/test/fuzztest/advancednotificationservice/serviceregisterpushcallback_fuzzer/service_registerpushcallback_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceregisterpushcallback_fuzzer/service_registerpushcallback_fuzzer.cpp @@ -17,12 +17,29 @@ #include #include "advanced_notification_service.h" #include "ans_permission_def.h" -#include "mock_notification_request.h" +#include "mock_notification_check_request.h" +#include "push_callback_stub.h" namespace OHOS { namespace Notification { + +class FuzzTestPushCallBackStub : public PushCallBackStub { +public: + int32_t OnCheckNotification( + const std::string ¬ificationData, + const std::shared_ptr &pushCallBackParam) override + { + return 0; + } +}; + bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + sptr pushCallback = new (std::nothrow) FuzzTestPushCallBackStub(); + sptr notificationCheckRequest = + ObjectBuilder::Build(fuzzData); + service->RegisterPushCallback(pushCallback, notificationCheckRequest); return true; } } @@ -33,6 +50,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/serviceremovenotification_fuzzer/service_removenotification_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceremovenotification_fuzzer/service_removenotification_fuzzer.cpp index c66de57b166d73d11e971011895c3655ee7a4b2e..fb3e6c2da58d6147b177f87e20a4b3ba4018a0f7 100644 --- a/test/fuzztest/advancednotificationservice/serviceremovenotification_fuzzer/service_removenotification_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceremovenotification_fuzzer/service_removenotification_fuzzer.cpp @@ -17,12 +17,18 @@ #include #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(); + sptr bundleOption = ObjectBuilder::Build(fuzzData); + std::string label = fuzzData->ConsumeRandomLengthString(); + int32_t notificationId = fuzzData->ConsumeIntegral(); + int32_t removeReason = fuzzData->ConsumeIntegral(); + service->RemoveNotification(bundleOption, notificationId, label, removeReason); 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/servicesetbadgenumberfordhbybundle_fuzzer/service_setbadgenumberfordhbybundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesetbadgenumberfordhbybundle_fuzzer/service_setbadgenumberfordhbybundle_fuzzer.cpp index df8ad3cc774be663696e5639dbf8a293a8a91122..c353508f7e3db9993a0686f5cfaeec527d9fdd91 100644 --- a/test/fuzztest/advancednotificationservice/servicesetbadgenumberfordhbybundle_fuzzer/service_setbadgenumberfordhbybundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesetbadgenumberfordhbybundle_fuzzer/service_setbadgenumberfordhbybundle_fuzzer.cpp @@ -17,12 +17,16 @@ #include #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(); + sptr bundleOption = ObjectBuilder::Build(fuzzData); + int32_t badgeNumber = fuzzData->ConsumeIntegral(); + service->SetBadgeNumberForDhByBundle(bundleOption, badgeNumber); return true; } } @@ -33,6 +37,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/servicesetdistributedenabledbybundle_fuzzer/service_setdistributedenabledbybundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesetdistributedenabledbybundle_fuzzer/service_setdistributedenabledbybundle_fuzzer.cpp index 466d90492a081639f181aa3ddf66be1b949099ed..3b268dc2dfcb04ce59f9e44f9d8646adad101438 100644 --- a/test/fuzztest/advancednotificationservice/servicesetdistributedenabledbybundle_fuzzer/service_setdistributedenabledbybundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesetdistributedenabledbybundle_fuzzer/service_setdistributedenabledbybundle_fuzzer.cpp @@ -17,12 +17,17 @@ #include #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(); + sptr bundleOption = ObjectBuilder::Build(fuzzData); + std::string deviceType = fuzzData->ConsumeRandomLengthString(); + bool enabled = fuzzData->ConsumeBool(); + service->SetDistributedEnabledByBundle(bundleOption, deviceType, enabled); return true; } } @@ -33,6 +38,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/servicesetslotflagsasbundle_fuzzer/service_setslotflagsasbundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesetslotflagsasbundle_fuzzer/service_setslotflagsasbundle_fuzzer.cpp index dbf0f5a5632ce8340340e9a57b368f8c026eb27d..cb84b9cc5923dbe3629936699f36e7e644f8610d 100644 --- a/test/fuzztest/advancednotificationservice/servicesetslotflagsasbundle_fuzzer/service_setslotflagsasbundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesetslotflagsasbundle_fuzzer/service_setslotflagsasbundle_fuzzer.cpp @@ -17,12 +17,16 @@ #include #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(); + sptr bundleOption = ObjectBuilder::Build(fuzzData); + uint32_t slotFlags = fuzzData->ConsumeIntegral(); + service->SetSlotFlagsAsBundle(bundleOption, slotFlags); return true; } } @@ -33,6 +37,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/servicesubscribe_fuzzer/service_subscribe_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesubscribe_fuzzer/service_subscribe_fuzzer.cpp index 991515ae66b16dccd3827a3a582a01d06012ca89..846207df853b49883a0d07410851ef84a0a00bde 100644 --- a/test/fuzztest/advancednotificationservice/servicesubscribe_fuzzer/service_subscribe_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesubscribe_fuzzer/service_subscribe_fuzzer.cpp @@ -17,12 +17,50 @@ #include #include "advanced_notification_service.h" #include "ans_permission_def.h" -#include "mock_notification_request.h" +#include "mock_notification_subscribe_info.h" +#include "notification_subscriber.h" +#include "ans_subscriber_listener.h" namespace OHOS { namespace Notification { + +class FuzzTestSubscriber : public NotificationSubscriber { +public: + void OnDisconnected() override + {} + void OnDied() override + {} + void OnUpdate(const std::shared_ptr &sortingMap) override + {} + void OnDoNotDisturbDateChange(const std::shared_ptr &date) override + {} + void OnConnected() override + {} + void OnEnabledNotificationChanged(const std::shared_ptr &callbackData) override + {} + void OnCanceled(const std::shared_ptr &request, + const std::shared_ptr &sortingMap, int deleteReason) override + {} + void OnBadgeChanged(const std::shared_ptr &badgeData) override + {} + void OnBadgeEnabledChanged(const sptr &callbackData) override + {} + void OnConsumed(const std::shared_ptr &request, + const std::shared_ptr &sortingMap) override + {} + + void OnBatchCanceled(const std::vector> &requestList, + const std::shared_ptr &sortingMap, int32_t deleteReason) override + {} +}; + bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + std::shared_ptr testSubscriber = std::make_shared(); + sptr subscriber = new (std::nothrow) SubscriberListener(testSubscriber); + sptr info = ObjectBuilder::Build(fuzzData); + service->Subscribe(subscriber, info); return true; } } @@ -33,6 +71,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/fuzz_common_base/mock/mock_notification_check_request.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_check_request.h new file mode 100644 index 0000000000000000000000000000000000000000..b24314e2cf0deddb22d21876485e8c78c655dd81 --- /dev/null +++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_check_request.h @@ -0,0 +1,53 @@ +/* + * 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_CHECK_REQUEST_BUILDER_H +#define MOCK_NOTIFICATION_CHECK_REQUEST_BUILDER_H + +#include "mock_fuzz_object.h" +#include "notification_check_request.h" + +namespace OHOS { +namespace Notification { + +const int MAX_SLOT_TYPE = 8; +const int MAX_CONTENT_TYPE = 10; +const int MAX_ARRAY_SIZE = 10; +const int MAX_STRING_SIZE = 20; + +template <> +NotificationCheckRequest* ObjectBuilder::Build(FuzzedDataProvider *fdp) +{ + auto checkRequest = new NotificationCheckRequest(); + + checkRequest->SetContentType(static_cast( + fdp->ConsumeIntegralInRange(0, MAX_CONTENT_TYPE))); + + checkRequest->SetSlotType(static_cast( + fdp->ConsumeIntegralInRange(0, MAX_SLOT_TYPE))); + std::vector extraKeys; + for (int i = 0; i < fdp->ConsumeIntegralInRange(0, MAX_ARRAY_SIZE); i++) { + extraKeys.push_back(fdp->ConsumeRandomLengthString(MAX_STRING_SIZE)); + } + checkRequest->SetExtraKeys(extraKeys); + checkRequest->SetUid(fdp->ConsumeIntegral()); + + ANS_LOGE("Build mock veriables"); + return checkRequest; +} +} // namespace Notification +} // namespace OHOS + +#endif // MOCK_NOTIFICATION_CHECK_REQUEST_BUILDER_H \ No newline at end of file