diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index b5f84bce558a9df1e67fbf1b3cfa01ff984d4224..b0cf626e957279bc9e79869b053501e3c5b5ebf1 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -55,6 +55,7 @@ group("fuzztest") { "notificationmultilinecontent_fuzzer:NotificationMultiLineContentFuzzTest", "notificationmultilinecontentannex_fuzzer:NotificationMultiLineContentAnnexFuzzTest", "notificationnormalcontent_fuzzer:NotificationNormalContentFuzzTest", + "notificationparcel_fuzzer:NotificationParcelFuzzTest", "notificationpicturecontent_fuzzer:NotificationPictureContentFuzzTest", "notificationpicturecontentannex_fuzzer:NotificationPictureContentAnnexFuzzTest", "notificationrequest_fuzzer:NotificationRequestFuzzTest", diff --git a/test/fuzztest/notificationmediacontent_fuzzer/notificationmediacontent_fuzzer.cpp b/test/fuzztest/notificationmediacontent_fuzzer/notificationmediacontent_fuzzer.cpp index 150c4e2dc7c0065a8e0e4a3d470310cab6be854a..e0b12fea9d4fe2521178da35fcdc50308868b172 100644 --- a/test/fuzztest/notificationmediacontent_fuzzer/notificationmediacontent_fuzzer.cpp +++ b/test/fuzztest/notificationmediacontent_fuzzer/notificationmediacontent_fuzzer.cpp @@ -37,6 +37,10 @@ namespace OHOS { notificationMediaContent.GetShownActions(); // test Dump function notificationMediaContent.Dump(); + // test Json function + nlohmann::json jsonObj; + notificationMediaContent.ToJson(jsonObj); + notificationMediaContent.FromJson(jsonObj); // test Unmarshalling function Parcel parcel; notificationMediaContent.Unmarshalling(parcel); diff --git a/test/fuzztest/notificationparcel_fuzzer/BUILD.gn b/test/fuzztest/notificationparcel_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e64bbb1b696bb9d5279018e35a67a16f30c360f2 --- /dev/null +++ b/test/fuzztest/notificationparcel_fuzzer/BUILD.gn @@ -0,0 +1,57 @@ +# 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("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("NotificationParcelFuzzTest") { + module_out_path = service_fuzz_test_path + fuzz_config_file = "${component_path}/test/fuzztest/notificationparcel_fuzzer" + + include_dirs = [ + "${component_path}/test/fuzztest/fuzz_common_base", + "${component_path}/test/fuzztest/fuzz_common_base/mock", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notificationparcel_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "c_utils:utils", + "hilog:libhilog", + "image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationParcelFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notificationparcel_fuzzer/corpus/init b/test/fuzztest/notificationparcel_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..8f37f09254457133cae0f828d0a5faee7dcbd779 --- /dev/null +++ b/test/fuzztest/notificationparcel_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/notificationparcel_fuzzer/notificationparcel_fuzzer.cpp b/test/fuzztest/notificationparcel_fuzzer/notificationparcel_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..930a24919bb5f69085c129a232d29e25a42f0dce --- /dev/null +++ b/test/fuzztest/notificationparcel_fuzzer/notificationparcel_fuzzer.cpp @@ -0,0 +1,257 @@ +/* + * 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 "notification_capsule.h" +#include "notification_disable.h" +#include "notification_do_not_disturb_profile.h" +#include "notification_icon_button.h" +#include "notification_live_view_content.h" +#include "notification_local_live_view_button.h" +#include "notification_local_live_view_content.h" +#include "notification_operation_info.h" +#include "notification_unified_group_Info.h" +#include "resource_manager.h" +#include "notificationparcel_fuzzer.h" +#include + +namespace OHOS { +namespace Notification { + void TestNotificationCapsuleParcel(FuzzedDataProvider *fdp) + { + NotificationCapsule capsule; + Parcel parcel; + nlohmann::json jsonObject; + std::string stringData = fdp->ConsumeRandomLengthString(); + int32_t time = fdp->ConsumeIntegral(); + + capsule.SetTitle(stringData); + capsule.GetTitle(); + capsule.SetBackgroundColor(stringData); + capsule.GetBackgroundColor(); + capsule.SetContent(stringData); + capsule.GetContent(); + capsule.SetTime(time); + capsule.GetTime(); + capsule.ToJson(jsonObject); + capsule.Dump(); + capsule.FromJson(jsonObject); + capsule.Marshalling(parcel); + capsule.Unmarshalling(parcel); + } + + void TestNotificationDoNotDisturbProfileParcel(FuzzedDataProvider *fdp) + { + NotificationDoNotDisturbProfile disturbProfile; + Parcel parcel; + int64_t profileId = fdp->ConsumeIntegral(); + std::string profileName = fdp->ConsumeRandomLengthString(); + std::vector trustList; + NotificationBundleOption bundleOption; + trustList.push_back(bundleOption); + + disturbProfile.SetProfileId(profileId); + disturbProfile.GetProfileId(); + disturbProfile.SetProfileName(profileName); + disturbProfile.GetProfileName(); + disturbProfile.SetProfileTrustList(trustList); + disturbProfile.GetProfileTrustList(); + disturbProfile.Marshalling(parcel); + disturbProfile.ReadFromParcel(parcel); + disturbProfile.Unmarshalling(parcel); + std::string disturbProfileJson = disturbProfile.ToJson(); + disturbProfile.FromJson(disturbProfileJson); + } + + void TestNotificationDisableParcel(FuzzedDataProvider *fdp) + { + NotificationDisable notificationDisable; + std::vector bundleList; + bool disabled = fdp->ConsumeBool(); + Parcel parcel; + + bundleList.emplace_back(fdp->ConsumeRandomLengthString()); + notificationDisable.SetDisabled(disabled); + notificationDisable.GetDisabled(); + notificationDisable.SetBundleList(bundleList); + notificationDisable.GetBundleList(); + + notificationDisable.Marshalling(parcel); + notificationDisable.ReadFromParcel(parcel); + notificationDisable.Unmarshalling(parcel); + + std::string jsonObj = notificationDisable.ToJson(); + notificationDisable.FromJson(jsonObj); + } + + void TestNotificationLiveViewContentParcel(FuzzedDataProvider *fdp) + { + NotificationLiveViewContent liveViewContent; + PictureMap picMap; + nlohmann::json jsonObject; + auto extraInfo = std::make_shared(); + + liveViewContent.SetVersion(fdp->ConsumeIntegral()); + liveViewContent.GetVersion(); + liveViewContent.SetText(fdp->ConsumeRandomLengthString()); + liveViewContent.SetTitle(fdp->ConsumeRandomLengthString()); + liveViewContent.SetAdditionalText(fdp->ConsumeRandomLengthString()); + liveViewContent.SetIsOnlyLocalUpdate(fdp->ConsumeBool()); + liveViewContent.SetPicture(picMap); + liveViewContent.SetExtraInfo(extraInfo); + liveViewContent.Dump(); + liveViewContent.ToJson(jsonObject); + liveViewContent.FromJson(jsonObject); + } + + void TestNotificationLocalLiveViewButtonParcel(FuzzedDataProvider *fdp) + { + NotificationLocalLiveViewButton button; + std::string buttonName = fdp->ConsumeRandomLengthString(); + auto pixelMapOne = std::make_shared(); + auto pixelMapTwo = std::make_shared(); + auto iconResource = std::make_shared(); + iconResource->id = fdp->ConsumeIntegral(); + iconResource->bundleName = fdp->ConsumeRandomLengthString(); + iconResource->moduleName = fdp->ConsumeRandomLengthString(); + Parcel parcel; + nlohmann::json jsonObj; + + button.addSingleButtonName(buttonName); + button.GetAllButtonNames(); + button.addSingleButtonIcon(pixelMapOne); + button.addSingleButtonIcon(pixelMapTwo); + button.GetAllButtonIcons(); + button.addSingleButtonIconResource(iconResource); + button.GetAllButtonIconResource(); + button.Dump(); + + button.ToJson(jsonObj); + button.FromJson(jsonObj); + + button.Marshalling(parcel); + button.Unmarshalling(parcel); + button.ClearButtonIcons(); + button.ClearButtonIconsResource(); + } + + void TestNotificationLocalLiveViewContentParcel(FuzzedDataProvider *fdp) + { + NotificationLocalLiveViewContent content; + NotificationCapsule capsule; + NotificationLocalLiveViewButton button; + NotificationIconButton iconButton; + std::vector iconButtons; + NotificationProgress progress; + NotificationTime time; + Parcel parcel; + nlohmann::json jsonObj; + int32_t flag = fdp->ConsumeIntegral(); + iconButtons.push_back(iconButton); + content.SetType(fdp->ConsumeIntegral()); + content.GetType(); + content.SetCapsule(capsule); + content.GetCapsule(); + content.SetButton(button); + content.GetButton(); + content.SetCardButton(iconButtons); + content.GetCardButton(); + content.SetProgress(progress); + content.GetProgress(); + content.SetTime(time); + content.GetTime(); + content.addFlag(flag); + content.isFlagExist(flag); + content.isFlagExist(fdp->ConsumeIntegral()); + content.Dump(); + + content.ToJson(jsonObj); + content.FromJson(jsonObj); + + content.Marshalling(parcel); + content.Unmarshalling(parcel); + + content.ClearButton(); + content.ClearCapsuleIcon(); + } + + void TestNotificationOperationInfoParcel(FuzzedDataProvider *fdp) + { + NotificationOperationInfo info; + std::string actionName = fdp->ConsumeRandomLengthString(); + std::string userInput = fdp->ConsumeRandomLengthString(); + std::string hashCode = fdp->ConsumeRandomLengthString(); + std::string eventId = fdp->ConsumeRandomLengthString(); + Parcel parcel; + + info.SetActionName(actionName); + info.GetActionName(); + info.SetUserInput(userInput); + info.GetUserInput(); + info.SetHashCode(hashCode); + info.GetHashCode(); + info.SetEventId(eventId); + info.GetEventId(); + info.Dump(); + info.Marshalling(parcel); + info.Unmarshalling(parcel); + } + + void TestNotificationUnifiedGroupInfoParcel(FuzzedDataProvider *fdp) + { + NotificationUnifiedGroupInfo info; + std::string key = fdp->ConsumeRandomLengthString(); + std::string title = fdp->ConsumeRandomLengthString(); + std::string content = fdp->ConsumeRandomLengthString(); + std::string sceneName = fdp->ConsumeRandomLengthString(); + auto extraInfo = std::make_shared(); + Parcel parcel; + + info.SetKey(key); + info.GetKey(); + info.SetTitle(title); + info.GetTitle(); + info.SetContent(content); + info.GetContent(); + info.SetSceneName(sceneName); + info.GetSceneName(); + info.SetExtraInfo(extraInfo); + info.GetExtraInfo(); + info.Dump(); + info.Marshalling(parcel); + info.Unmarshalling(parcel); + } + + bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fdp) + { + TestNotificationCapsuleParcel(fdp); + TestNotificationDoNotDisturbProfileParcel(fdp); + TestNotificationDisableParcel(fdp); + TestNotificationLiveViewContentParcel(fdp); + TestNotificationLocalLiveViewButtonParcel(fdp); + TestNotificationLocalLiveViewContentParcel(fdp); + TestNotificationOperationInfoParcel(fdp); + TestNotificationUnifiedGroupInfoParcel(fdp); + 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/notificationparcel_fuzzer/notificationparcel_fuzzer.h b/test/fuzztest/notificationparcel_fuzzer/notificationparcel_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..ff69b1c9cc9ec7b4fc4ea8ebe536f3c6a531b399 --- /dev/null +++ b/test/fuzztest/notificationparcel_fuzzer/notificationparcel_fuzzer.h @@ -0,0 +1,23 @@ +/* + * 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_NOTIFICATIONPARCEL_FUZZER_NOTIFICATIONPARCEL_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATIONPARCEL_FUZZER_NOTIFICATIONPARCEL_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notificationparcel_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATIONPARCEL_FUZZER_NOTIFICATIONPARCEL_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notificationparcel_fuzzer/project.xml b/test/fuzztest/notificationparcel_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..66e1dcac475475fb101b6f8670ec699e6e9696aa --- /dev/null +++ b/test/fuzztest/notificationparcel_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/notificationsortingmap_fuzzer/notificationsortingmap_fuzzer.cpp b/test/fuzztest/notificationsortingmap_fuzzer/notificationsortingmap_fuzzer.cpp index 7f1c10ddb106a231a1970450f0c8e96b43a4fc85..12186f6cfa98383d9d7d3274dfd91cb25de8b925 100644 --- a/test/fuzztest/notificationsortingmap_fuzzer/notificationsortingmap_fuzzer.cpp +++ b/test/fuzztest/notificationsortingmap_fuzzer/notificationsortingmap_fuzzer.cpp @@ -36,7 +36,9 @@ namespace OHOS { notificationSortingMap.SetNotificationSorting(sortingList); notificationSortingMap.Dump(); Parcel parcel; - return notificationSortingMap.Marshalling(parcel); + notificationSortingMap.Marshalling(parcel); + notificationSortingMap.Unmarshalling(parcel); + return true; } } diff --git a/test/fuzztest/notificationuserinputannex_fuzzer/notificationuserinputannex_fuzzer.cpp b/test/fuzztest/notificationuserinputannex_fuzzer/notificationuserinputannex_fuzzer.cpp index a7e4dc5eec42abbfeec4299acc50c043b04f78d3..fd38a2603497ea83bcb3a0825dfa5fe2586493a8 100644 --- a/test/fuzztest/notificationuserinputannex_fuzzer/notificationuserinputannex_fuzzer.cpp +++ b/test/fuzztest/notificationuserinputannex_fuzzer/notificationuserinputannex_fuzzer.cpp @@ -33,6 +33,9 @@ namespace OHOS { Notification::NotificationUserInput userInput(stringData); std::map> results; notificationUserInput.AddMimeInputToWant(userInput, want, results); + nlohmann::json jsonObj; + notificationUserInput.ToJson(jsonObj); + notificationUserInput.FromJson(jsonObj); std::string inputKey = fdp->ConsumeRandomLengthString(); std::string tag = fdp->ConsumeRandomLengthString(); std::vector options;