diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 39303ad3a609a5bb3f1cce6f575fa2be8c9a6bbc..0c561b3eed55dd8c4235416a69838656481b4951 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -19,14 +19,18 @@ group("fuzztest") { "addnotificationslots_fuzzer:AddNotificationSlotsFuzzTest", "addslotbytype_fuzzer:AddSlotByTypeFuzzTest", "cancelasbundle_fuzzer:CancelAsBundleFuzzTest", + "cancelgroup_fuzzer:CancelGroupFuzzTest", "cancelnotification_fuzzer:CancelNotificationFuzzTest", + "getallactivenotifications_fuzzer:GetAllActiveNotificationsFuzzTest", "getbundleimportance_fuzzer:GetBundleImportanceFuzzTest", "getnotificationslot_fuzzer:GetNotificationSlotFuzzTest", "getnotificationslotnumasbundle_fuzzer:GetNotificationSlotNumAsBundleFuzzTest", + "getnotificationslotsforbundle_fuzzer:GetNotificationSlotsForBundleFuzzTest", "publishnotification_fuzzer:PublishNotificationFuzzTest", "removenotification_fuzzer:RemoveNotificationFuzzTest", "removenotificationsbybundle_fuzzer:RemoveNotificationsByBundleFuzzTest", "removenotificationslot_fuzzer:RemoveNotificationSlotFuzzTest", "setnotificationbadgenum_fuzzer:SetNotificationBadgeNumFuzzTest", + "setnotificationsenabledforallbundles_fuzzer:SetNotificationsEnabledForAllBundlesFuzzTest", ] } diff --git a/test/fuzztest/cancelgroup_fuzzer/BUILD.gn b/test/fuzztest/cancelgroup_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..11eaa77f9233d0575c8326e2ecabfef83e6f538b --- /dev/null +++ b/test/fuzztest/cancelgroup_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 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") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("CancelGroupFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/cancelgroup_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "cancelgroup_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", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":CancelGroupFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/cancelgroup_fuzzer/cancelgroup_fuzzer.cpp b/test/fuzztest/cancelgroup_fuzzer/cancelgroup_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d24e2df048a4ef304300d4bafe79ea78b62a91bc --- /dev/null +++ b/test/fuzztest/cancelgroup_fuzzer/cancelgroup_fuzzer.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2022 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 "cancelgroup_fuzzer.h" + +#include "notification_helper.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + // test GetShowBadgeEnabled function + bool enabled = *data % ENABLE; + Notification::NotificationHelper::GetShowBadgeEnabled(enabled); + // test CancelGroup function + std::string stringData(data); + Notification::NotificationHelper::CancelGroup(stringData); + // test SetDoNotDisturbDate function + uint32_t type = GetU32Data(data); + Notification::NotificationDoNotDisturbDate disturb; + Notification::NotificationConstant::DoNotDisturbType disturbType = + Notification::NotificationConstant::DoNotDisturbType(type); + disturb.SetDoNotDisturbType(disturbType); + Notification::NotificationHelper::SetDoNotDisturbDate(disturb); + // test GetDoNotDisturbDate function + Notification::NotificationHelper::GetDoNotDisturbDate(disturb); + // test DoesSupportDoNotDisturbMode function + Notification::NotificationHelper::DoesSupportDoNotDisturbMode(enabled); + // test IsDistributedEnabled function + return Notification::NotificationHelper::IsDistributedEnabled(enabled); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/cancelgroup_fuzzer/cancelgroup_fuzzer.h b/test/fuzztest/cancelgroup_fuzzer/cancelgroup_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..5f8e00c0b32b789669c601aecb76bfd3cf179e15 --- /dev/null +++ b/test/fuzztest/cancelgroup_fuzzer/cancelgroup_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 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_CANCELGROUP_FUZZER_CANCELGROUP_FUZZER_H +#define TEST_FUZZTEST_CANCELGROUP_FUZZER_CANCELGROUP_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "cancelgroup_fuzzer" + +#endif // TEST_FUZZTEST_CANCELGROUP_FUZZER_CANCELGROUP_FUZZER_H diff --git a/test/fuzztest/cancelgroup_fuzzer/corpus/init b/test/fuzztest/cancelgroup_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/cancelgroup_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 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/cancelgroup_fuzzer/project.xml b/test/fuzztest/cancelgroup_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/cancelgroup_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/getallactivenotifications_fuzzer/BUILD.gn b/test/fuzztest/getallactivenotifications_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..02e1ac41e2332d8e960ec2f9010e4b1d4894cafd --- /dev/null +++ b/test/fuzztest/getallactivenotifications_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# Copyright (c) 2022 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") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("GetAllActiveNotificationsFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/getallactivenotifications_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "getallactivenotifications_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", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":GetAllActiveNotificationsFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/getallactivenotifications_fuzzer/corpus/init b/test/fuzztest/getallactivenotifications_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/getallactivenotifications_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 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/getallactivenotifications_fuzzer/getallactivenotifications_fuzzer.cpp b/test/fuzztest/getallactivenotifications_fuzzer/getallactivenotifications_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..255bf5db7834aa9cb3288de62d7db950b3bfe7b0 --- /dev/null +++ b/test/fuzztest/getallactivenotifications_fuzzer/getallactivenotifications_fuzzer.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 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 "getallactivenotifications_fuzzer.h" + +#include "notification_helper.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + // test IsAllowedNotify function + std::string stringData(data); + int32_t usingData = static_cast(GetU32Data(data)); + Notification::NotificationBundleOption bundleOption; + bundleOption.SetBundleName(stringData); + bundleOption.SetUid(usingData); + bool allowed = *data % ENABLE; + Notification::NotificationHelper::IsAllowedNotify(bundleOption, allowed); + // test GetNotificationSlotsForBundle function and one parameter + sptr notification = nullptr; + std::vector> notifications; + notifications.emplace_back(notification); + Notification::NotificationHelper::GetAllActiveNotifications(notifications); + // test GetNotificationSlotsForBundle function and two parameter + std::vector keys; + keys.emplace_back(stringData); + return Notification::NotificationHelper::GetAllActiveNotifications(keys, notifications) == ERR_OK; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/getallactivenotifications_fuzzer/getallactivenotifications_fuzzer.h b/test/fuzztest/getallactivenotifications_fuzzer/getallactivenotifications_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..22b0ce78e227ce8259176b859437a0b69b5cab26 --- /dev/null +++ b/test/fuzztest/getallactivenotifications_fuzzer/getallactivenotifications_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 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_GETALLACTIVENOTIFICATIONS_FUZZER_GETALLACTIVENOTIFICATIONS_FUZZER_H +#define TEST_FUZZTEST_GETALLACTIVENOTIFICATIONS_FUZZER_GETALLACTIVENOTIFICATIONS_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "getallactivenotifications_fuzzer" + +#endif // TEST_FUZZTEST_GETALLACTIVENOTIFICATIONS_FUZZER_GETALLACTIVENOTIFICATIONS_FUZZER_H diff --git a/test/fuzztest/getallactivenotifications_fuzzer/project.xml b/test/fuzztest/getallactivenotifications_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/getallactivenotifications_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/getnotificationslotsforbundle_fuzzer/BUILD.gn b/test/fuzztest/getnotificationslotsforbundle_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..550181ea6e0254dfa85208447e9cced46d75e32f --- /dev/null +++ b/test/fuzztest/getnotificationslotsforbundle_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# Copyright (c) 2022 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") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("GetNotificationSlotsForBundleFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/getnotificationslotsforbundle_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "getnotificationslotsforbundle_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", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":GetNotificationSlotsForBundleFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/getnotificationslotsforbundle_fuzzer/corpus/init b/test/fuzztest/getnotificationslotsforbundle_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/getnotificationslotsforbundle_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 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/getnotificationslotsforbundle_fuzzer/getnotificationslotsforbundle_fuzzer.cpp b/test/fuzztest/getnotificationslotsforbundle_fuzzer/getnotificationslotsforbundle_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..94a46feb1cc710595a8d87893cb5b68f288337de --- /dev/null +++ b/test/fuzztest/getnotificationslotsforbundle_fuzzer/getnotificationslotsforbundle_fuzzer.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 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 "getnotificationslotsforbundle_fuzzer.h" + +#include "notification_helper.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + int32_t usingData = static_cast(GetU32Data(data)); + Notification::NotificationBundleOption bundleOption; + bundleOption.SetBundleName(stringData); + bundleOption.SetUid(usingData); + sptr slot = nullptr; + std::vector> slots; + slots.emplace_back(slot); + // test UpdateNotificationSlots function + Notification::NotificationHelper::UpdateNotificationSlots(bundleOption, slots); + // test GetNotificationSlotsForBundle function + Notification::NotificationHelper::GetNotificationSlotsForBundle(bundleOption, slots); + // test RemoveGroupByBundle function + return Notification::NotificationHelper::RemoveGroupByBundle(bundleOption, stringData); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/getnotificationslotsforbundle_fuzzer/getnotificationslotsforbundle_fuzzer.h b/test/fuzztest/getnotificationslotsforbundle_fuzzer/getnotificationslotsforbundle_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..12da69d29f59b63cc6f668b5f150b470b122d976 --- /dev/null +++ b/test/fuzztest/getnotificationslotsforbundle_fuzzer/getnotificationslotsforbundle_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 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_GETNOTIFICATIONSLOTSFORBUNDLE_FUZZER_GETNOTIFICATIONSLOTSFORBUNDLE_FUZZER_H +#define TEST_FUZZTEST_GETNOTIFICATIONSLOTSFORBUNDLE_FUZZER_GETNOTIFICATIONSLOTSFORBUNDLE_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "getnotificationslotsforbundle_fuzzer" + +#endif // TEST_FUZZTEST_GETNOTIFICATIONSLOTSFORBUNDLE_FUZZER_GETNOTIFICATIONSLOTSFORBUNDLE_FUZZER_H diff --git a/test/fuzztest/getnotificationslotsforbundle_fuzzer/project.xml b/test/fuzztest/getnotificationslotsforbundle_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/getnotificationslotsforbundle_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/BUILD.gn b/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9a8915f9375dad0c6b3bccc8175c65a35bb668a0 --- /dev/null +++ b/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2022 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") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("SetNotificationsEnabledForAllBundlesFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/setnotificationsenabledforallbundles_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "setnotificationsenabledforallbundles_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", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":SetNotificationsEnabledForAllBundlesFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/corpus/init b/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 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/setnotificationsenabledforallbundles_fuzzer/project.xml b/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/setnotificationsenabledforallbundles_fuzzer.cpp b/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/setnotificationsenabledforallbundles_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b02ccad339c6cbe906aac29992a1f6008411f233 --- /dev/null +++ b/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/setnotificationsenabledforallbundles_fuzzer.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022 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 "setnotificationsenabledforallbundles_fuzzer.h" + +#include "notification_helper.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + // test SetNotificationsEnabledForAllBundles function + std::string stringData(data); + bool enabled = *data % ENABLE; + Notification::NotificationHelper::SetNotificationsEnabledForAllBundles(stringData, enabled); + // test SetNotificationsEnabledForDefaultBundle function + Notification::NotificationHelper::SetNotificationsEnabledForDefaultBundle(stringData, enabled); + // test SetNotificationsEnabledForSpecifiedBundle function + int32_t usingData = static_cast(GetU32Data(data)); + Notification::NotificationBundleOption bundleOption; + bundleOption.SetBundleName(stringData); + bundleOption.SetUid(usingData); + Notification::NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(bundleOption, stringData, enabled); + // test SetShowBadgeEnabledForBundle function + Notification::NotificationHelper::SetShowBadgeEnabledForBundle(bundleOption, enabled); + // test GetShowBadgeEnabledForBundle function + return Notification::NotificationHelper::GetShowBadgeEnabledForBundle(bundleOption, enabled); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/setnotificationsenabledforallbundles_fuzzer.h b/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/setnotificationsenabledforallbundles_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..1b0351ffda6a15d43c7f75784becdbe4e6441834 --- /dev/null +++ b/test/fuzztest/setnotificationsenabledforallbundles_fuzzer/setnotificationsenabledforallbundles_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 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_SETNOTIFICATIONSENABLEDFORALLBUNDLES_FUZZER_SETNOTIFICATIONSENABLEDFORALLBUNDLES_FUZZER_H +#define TEST_FUZZTEST_SETNOTIFICATIONSENABLEDFORALLBUNDLES_FUZZER_SETNOTIFICATIONSENABLEDFORALLBUNDLES_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "setnotificationsenabledforallbundles_fuzzer" + +#endif // TEST_FUZZTEST_SETNOTIFICATIONSENABLEDFORALLBUNDLES_FUZZER_SETNOTIFICATIONSENABLEDFORALLBUNDLES_FUZZER_H